LeetCode26删除排序数组中的重复项
未经博主同意,禁止瞎JB转载。
LeetCode26删除排序数组中的重复项
https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/description/
参考答案做的。
答案:
https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/solution/
我的代码:
1 class Solution(object): 2 def removeDuplicates(self, nums): 3 """ 4 :type nums: List[int] 5 :rtype: int 6 """ 7 if len(nums) == 0: 8 return 0 9 i = 0 10 for j in range(len(nums)): 11 if nums[j] != nums[i]: 12 nums[i+1] = nums[j] 13 i += 1 14 return i+1