- 博客(10)
- 收藏
- 关注
原创 Leetcode P283 Move Zeroes @python Lang (LL)
Link: https://leetcode.com/problems/move-zeroes/Content:Method: two pointers (slow and fast pointers)Very similar to P27 (remove element)Algorithm:i - slow pointer (to record current position)...
2020-01-04 08:56:37 113
原创 Leetcode P80 Remove Duplicates from Sorted Array II @python Lang (LL)
Link: https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/Content:Method: two pointers (slow and fast pointers)Algorithm: same with P26单独讨论长度为0,1,2的情况slow pointer从i = 1开始,fast ...
2020-01-04 07:51:43 204
原创 Leetcode P35 Search Insert Position @python Lang (LL)
Link: https://leetcode.com/problems/search-insert-position/Content:Method 1: linearAlgorithm: It has four situationsno elements ---- return 0nums[0] > target ---- return 0nums[-1] < targ...
2019-12-28 05:53:27 112
原创 Leetcode P33 Search in Rotated Sorted Array @python Lang (LL)
Link: https://leetcode.com/problems/search-in-rotated-sorted-array/Content:Method:Algorithm:一个ascending array rotated 后可以分为两端,mid 的位置有两种可能,根据mid 的位置,target 有四种可能。Code:def search(nums, target):...
2019-12-17 11:00:22 99
原创 Leetcode P31 Next Permutation @python Lang (LL)
Link: https://leetcode.com/problems/next-permutation/Content:Analysis:next permutation means 仅仅比这个数大的下一个数如果是一个降序的数,比如9876,则如何排列都没有比之更大的数,此时将数列逆序排列,即 sorted it in ascending order从上也可知,我们可以先从后向前看,...
2019-12-17 06:42:23 165
原创 Leetcode P27 Remove Element @python Lang (LL)
Link: https://leetcode.com/problems/remove-element/Content:Attention:return lengthfirst n elements, no matter what leave beyond elementsthe order can be arbitraryMethod 1: Two pointersAlgori...
2019-12-17 02:54:31 107 1
原创 Leetcode P26 Remove Duplicates from Sorted Array @python Lang (LL)
Link: https://leetcode.com/problems/remove-duplicates-from-sorted-array/Content:第一次分析题目的时候出现的错误:本题要求return 去掉重复key后的array长度但是特别注意的是**** first length elements modified ! and doesn’t matter what va...
2019-12-16 06:06:32 81
原创 Leetcode P16 three sum closest @python Lang (LL)
**Leetcode P16 three sum closest @python Lang (LL)**Link: https://leetcode.com/problems/3sum-closest/Content:Method: two pointers (similar to 3 sum problem)Algorithm:sort numskeeper: ans (st...
2019-12-11 05:46:53 158
原创 Leetcode P15 three sum @python Lang (LL)
Leetcode P15 three sum @python Lang (LL)Link: https://leetcode.com/problems/3sum/Content:Method 1 - Brute ForceAlgorithm:nums sortreturn is a list, build an empty array - res = []traverse i f...
2019-12-11 05:20:51 135
原创 Leetcode P1 two sum @python Lang (LL)
Leetcode P1 two sum @python Lang (LL)Link: https://leetcode.com/problems/two-sum/Content:Method 1 - Brute ForceAlgorithm:traverse i, first loop from 0 to len(nums-1).traverse j, fixed i, secon...
2019-12-11 04:51:43 122
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人