摘要:
I will first give the solution then show you the magic template. The code of solving this problem is below. It might be the shortest among all solutio 阅读全文
摘要:
one pass solution.要求一次遍历即完成排序。 思路:设置两个指针(zeros和twos)指向数组的头部(-1)和尾部(nums.length)。用索引i遍历整个数组,找到0即放到数组左边,指针zeros向右移动1位;找到2即放在数组右边,twos向左移动1位。 注意点: 1、i从0遍 阅读全文
摘要:
到目前为止做了200道leetcode,大多是按照从易到难的顺序,已经三次遇到完全不同的情景,但是采取floyd cycle detection 算法能够有效解决的问题的了。 floyd cycle detection 都是采用一快一慢两个指针,快的一次向前移动两步,慢的一次向前移动一步,这样快的每 阅读全文
摘要:
题目描述: Implement int sqrt(int x). Compute and return the square root of x. x is guaranteed to be a non-negative integer. 思路:二分查找,时间复杂度O(logn)。 if(mid的平 阅读全文
摘要:
题目描述:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted 阅读全文
摘要:
题目描述:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 出错: 阅读全文