1. 给一个字符串,返回true如果是个number,如果不是返回false. 这个有多少情况需要考虑?
正负号;小数点;小于一的小数;科学计数法;三位一个逗号的形式
2. 给一个整数串,给一个整数,测试是否两个和是这个整数,这个是老题目了,但是他专门问了如果要测试非常快的话,怎么搞?
3. An array with n elements which is K most sorted. 就是每个element的初始位置和它最终的排序后的位置的距离不超过常数K,设计一个排序算法。
should be faster than O(n*lgn).
Solution:Use a min heap. First insert number a0, a1… ak into the heap. We know
that the min number (the root of the heap) must be placed in position b0. So
we remove it from the heap and place it at b0. Next, we insert number ak+1
into the heap. Again, we can see that the current min number must be placed
in position b1.
So, the time complexity is O(n lgk).
4. Paint 一块画板上的区域。从一个点出发,直到所有相邻的和出发点一样颜色的点都 paint 上需要的颜色
5. 1..n 这些数有两个missing,find out which two are missing.
6. shifted sorted array找最大元素.
23451 return 5
12345 return 5
7. 3个string a, b, c.判断c是否是a和b的interleave,也就是c中应该有a,b中所有字符,并且c中字符顺序和a,b中一样。
a = "ef" b = "gh" c = "egfh" return true
a = "ef" b = "gh" c = "ehgf" return false
正负号;小数点;小于一的小数;科学计数法;三位一个逗号的形式
2. 给一个整数串,给一个整数,测试是否两个和是这个整数,这个是老题目了,但是他专门问了如果要测试非常快的话,怎么搞?
3. An array with n elements which is K most sorted. 就是每个element的初始位置和它最终的排序后的位置的距离不超过常数K,设计一个排序算法。
should be faster than O(n*lgn).
Solution:Use a min heap. First insert number a0, a1… ak into the heap. We know
that the min number (the root of the heap) must be placed in position b0. So
we remove it from the heap and place it at b0. Next, we insert number ak+1
into the heap. Again, we can see that the current min number must be placed
in position b1.
So, the time complexity is O(n lgk).
4. Paint 一块画板上的区域。从一个点出发,直到所有相邻的和出发点一样颜色的点都 paint 上需要的颜色
5. 1..n 这些数有两个missing,find out which two are missing.
6. shifted sorted array找最大元素.
23451 return 5
12345 return 5
7. 3个string a, b, c.判断c是否是a和b的interleave,也就是c中应该有a,b中所有字符,并且c中字符顺序和a,b中一样。
a = "ef" b = "gh" c = "egfh" return true
a = "ef" b = "gh" c = "ehgf" return false