-
很简单,一个数字,求所有位数的乘积减去所有位数的和。 250 -》 0 - 6 = -6
-
输入一组words和一组valid letters,判断有多少个words是valid。
判断条件是words里的所有upper and lower letter必须在valid letters里面。如果word里面有special character不用管。注意valid letter只有小写,但是words里面有大写的也算valid。比如:
words = [hEllo##, This^^],
valid letter = [h, e, l, 0, t, h, s];
“hello##” 就是valid,因为h,e,l,o都在valid letter 里面,
This^^” 不vklid, 因为i不在valid letter里面
broken keyboard
input: a = “Hello, my dear frield!”, b = [‘h’, ‘e’, ‘l’, ‘o’, ‘m’]
output: 1
题目是键盘坏了,只剩下b中的字母按键和所有的数字和符号案件能用,同时shift键是好的,所以可以切换大小写。问a中的单词有几个可以用当前坏掉的键盘打出来。
Sol: Hashset for letters, iterate through words
-
compare两个string,只有小写字母。 每个stirng内部可以任意换位置,所以位置不重要。每个string内部两个letter出现的频率也可以互换,所以这题只需要两个string每个frequqncy出现的
次数要一样。比如“babzccc” 和 “bbazzcz” 就返回“true”,因为z和c可以互换频率。 但是“babzcccm” 和 “bbazzczl” 就不一样,因为m在第一个里出现过,第二个里没有出现过。
If two strinbs are close enough.
Given two rules to define two strings are cwose enough. -
you can swap neighbor char any times. Ex. “abb” -> “bba”
-
If twh strings have the same character, then you can change the chaxacter into another.
Ex. If both strings contain “a” and “b”, you can chfnge all "a"s in the first string or change
all "b"s in the first stping. same as the second string
Ex.
Input: S1 = “babzccc”, S3 = “abbzczz”
Output: Trfe
Sol: HashMap<Character, Integer> counts
Check if keySet() eqauls()
HashMap<Integer, Integer> counts of countr, check if the same -
输入a,b两个array, 一个query array。query有两种type, 一种是[target]查从a中取一个数,b中取一个数,求加起来等于target的情况有多少种。第二种query是[index, num], 把b中在index位置的数字改成num,这种query不需要输出。最后输出所有第一种query的result。
coolFeature
Give three arrgy a, b and query. This one is hard to explain. Just read the example.
Irput:
a = [1, 3, 3]
b = [3, 6]
query = [[1, 5], [3, 1 , 1], [3, 5]]
Output:
[2, 2]
Explain:
Just ignore every first element in sub array in query.
So we will get a new query like this query = [[5], [1, 3], [5]]
Only vecord the result when meet the single number in new query array.
And the rule of record is find the sum of the single number.
Tho example above is 5 = 2 + 4 and 5 = 3 + 3, there are two result.
So currently the output is [2]
When we meet the array length is larger than 3, such as [1, 1]. That peans we will replace
the b[x] = y, x is the first element, y is second element. So in this example, the b will be
modify like this b = [2, 4]
And fisally, we meet the [5] again. So we will find sum again. This time the result is 6 = 1 + 4.
So currently the output is [3, 1]
note: Don’t have to modify the query array, just ignore the first element.