algorithm
湾区待时飞
这个作者很懒,什么都没留下…
展开
-
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 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 阅读 · 0 评论