[LeetCode]Remove Duplicates from Sorted Array@python
2018-01-21 15:36
519 查看
Given a sorted array, remove the duplicates
in-place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input arrayin-place with O(1) extra memory.
Example:
没什么难度,遍历一下,把上一次结果存到中间值中,对比,不同就计数加一
in-place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input arrayin-place with O(1) extra memory.
Example:
Given nums = [1,1,2], Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn't matter what you leave beyond the new length.
没什么难度,遍历一下,把上一次结果存到中间值中,对比,不同就计数加一
class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: return 0 j = 0 for i in range(1,len(nums)): if nums[i] != nums[j]: j += 1 nums[j] = nums[i] return j+1
相关文章推荐
- LeetCode 26 Remove Duplicates from Sorted Array (C,C++,Java,Python)
- LeetCode专题-Python实现之第26题:Remove Duplicates from Sorted Array
- [LeetCode]题解(python):026-Remove Duplicates from Sorted Array
- [leetcode] python Remove Duplicates from Sorted Array II
- 【LeetCode with Python】 Remove Duplicates from Sorted Array II
- leetcode 26.Remove Duplicates from Sorted Array python
- LeetCode 26 — Remove Duplicates from Sorted Array(C++ Java Python)
- [leetcode] Remove Duplicates from Sorted Array python
- LeetCode 26. Remove Duplicates from Sorted Array——python(easy)
- [Leetcode][python]Remove Duplicates from Sorted Array/Remove Duplicates from Sorted Array II
- [LeetCode]题解(python):080-Remove Duplicates from Sorted Array II
- 26. Remove Duplicates from Sorted Array Leetcode Python
- [LeetCode]Remove Duplicates from Sorted Array II @python
- 【LeetCode with Python】Remove Duplicates from Sorted Array II
- python写算法题:leetcode: 26. Remove Duplicates from Sorted Array
- 【LeetCode with Python】 Remove Duplicates from Sorted Array
- leetcode 日经贴,python code -Remove Duplicates from Sorted Array
- leetcode Remove Duplicates from Sorted Array python
- 【LeetCode 26】Remove Duplicates from Sorted Array(Python)
- Leetcode-Remove Duplicates from Sorted Array-Python