leetcode 26[easy]--- Remove Duplicates from Sorted Array
2017-12-15 14:03
399 查看
难度:easy
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 array in-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.
思路:原位操作,删除给定list中的重复element,用while循环,碰到重复就删除该element,若不重复就继续往前走,直到遍历整个list。
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 array in-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.
思路:原位操作,删除给定list中的重复element,用while循环,碰到重复就删除该element,若不重复就继续往前走,直到遍历整个list。
相关文章推荐
- LeetCode_Easy心得:26. Remove Duplicates from Sorted Array(C语言)
- LeetCode 26. Remove Duplicates from Sorted Array——python(easy)
- leetcode_26_ Remove Duplicates from Sorted Array (easy)
- [Leetcode 26, easy] Remove Duplicates from Sorted Array
- LeetCode-26-Remove Duplicates from Sorted Array(排序/内部排序)-Easy
- Leetcode 26. Remove Duplicates from Sorted Array (Easy) (cpp)
- 【LeetCode】26.Remove Duplicates from Sorted Array(Easy)解题报告
- [array] leetCode-26. Remove Duplicates from Sorted Array - Easy
- Leetcode 26. Remove Duplicates from Sorted Array (Easy) (java)
- [LeetCode]26 Remove Duplicates from Sorted Array
- 【Easy】26. Remove Duplicates from Sorted Array
- leetcode 26. Remove Duplicates from Sorted Array
- leetcode-26 Remove Duplicates from Sorted Array
- LeetCode-26. Remove Duplicates from Sorted Array
- [leetcode 26] Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- leetcode26 Remove Duplicates from Sorted Array 去重已排序列表
- LeetCode - 26. Remove Duplicates from Sorted Array
- LeetCode---(26) Remove Duplicates from Sorted Array
- LeetCode26/27/80/75 Remove Duplicates from Sorted Array I and II/Remove Element/Set Colors**