Environment: Python 3.8

Key technique: set, list

Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays.

Example 1:

Input: words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"]
Output: 2
Explanation:
- "leetcode" appears exactly once in each of the two arrays. We…

Environment: Python 3.8

Key technique: set, list

Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all the values that are present in at least two out of the three arrays. You may return the values in any order.

Example 1:

Input: nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]
Output: [3,2]
Explanation: The values that are present in at least two arrays are:
- 3, in all three arrays.
- 2, in nums1 and nums2.

Analysis:

  1. get nums1, nums2, nums3 all possible set.
  2. set three sets and output it.

Solution:

class Solution:
def twoOutOfThree(self, nums1, nums2, nums3):

seta=set(nums1) & set(nums2)
setb=set(nums2) & set(nums3)
setc=set(nums1) & set(nums3)
return set(list(seta) + list(setb) + list(setc))

Submissions:

Environment: Python 3.8

Key technique: sort, for

You are given a 0-indexed integer array nums and a target element target.

A target index is an index i such that nums[i] == target.

Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasing order.

Example 1:

Input: nums = [1,2,5,2,3], target = 2
Output: [1,2]
Explanation: After sorting, nums is [1,2,2,3,5].
The indices where nums[i] == 2 are 1 and 2.

Analysis:

  1. Sort it.
  2. find the target in sorted nums.
  3. return its index.

Solution:

class Solution:
def targetIndices(self, nums, target):
nums.sort()
ans=[]
for i in range(len(nums)):
if nums[i]==target:
ans.append(i)
return ans

Submissions:

Environment: Python 3.8

Key technique: for, in

Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring in word.

A substring is a contiguous sequence of characters within a string.

Example 1:

Input: patterns = ["a","abc","bc","d"], word = "abc"
Output: 3
Explanation:
- "a" appears as a substring in "abc".
- "abc" appears as a substring in "abc".
- "bc" appears as a substring in "abc".
- "d" does not appear as a substring in "abc".
3 of the strings in patterns appear as a substring in word.

Analysis:

  1. Check patterns is in word.
  2. If yes, ans=ans+1
  3. return ans

Solution:

class Solution:
def numOfStrings(self, patterns, word):
ans=0
for i in patterns:
if i in word:
ans+=1
return ans

Submissions:

Environment: Python 3.8

Key technique: platform, subprocess, datetime

Task: Test wifi card connect stability

Step:

1. ping to AP/other system/ google.com.

2. Check every hour packet lost rate.

Passe criteria:

1. packet loss rate is less than 1%.

Note

  • Losses between 5% and 10% of the total packet stream will…

Environment: Python 3.8

Key technique: find, string

Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing.

  • For…

Fatboy Slim

Interesting in any computer science.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store