摘要: 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 阅读全文
posted @ 2018-11-12 15:17 起点菜鸟 阅读(165) 评论(0) 推荐(0) 编辑
摘要: one pass solution.要求一次遍历即完成排序。 思路:设置两个指针(zeros和twos)指向数组的头部(-1)和尾部(nums.length)。用索引i遍历整个数组,找到0即放到数组左边,指针zeros向右移动1位;找到2即放在数组右边,twos向左移动1位。 注意点: 1、i从0遍 阅读全文
posted @ 2018-10-16 21:10 起点菜鸟 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 到目前为止做了200道leetcode,大多是按照从易到难的顺序,已经三次遇到完全不同的情景,但是采取floyd cycle detection 算法能够有效解决的问题的了。 floyd cycle detection 都是采用一快一慢两个指针,快的一次向前移动两步,慢的一次向前移动一步,这样快的每 阅读全文
posted @ 2018-05-28 20:47 起点菜鸟 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 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的平 阅读全文
posted @ 2018-04-01 10:33 起点菜鸟 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 题目描述: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 阅读全文
posted @ 2017-05-21 15:37 起点菜鸟 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 题目描述: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. 出错: 阅读全文
posted @ 2017-05-14 21:08 起点菜鸟 阅读(1940) 评论(0) 推荐(0) 编辑