jinhuang1102

26 Remove Duplicates from Sorted Array

Oct 21st, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. class Solution:
  2.     def removeDuplicates(self, nums):
  3.         """
  4.        :type nums: List[int]
  5.        :rtype: int
  6.        """
  7.         if not nums:
  8.             return 0
  9.        
  10.         pre = 1
  11.         i = 1
  12.         while i < len(nums):
  13.             if nums[i-1] == nums[i]:
  14.                 i = i + 1
  15.             else:
  16.                 nums[pre] = nums[i]
  17.                 pre = pre + 1
  18.                 i = i + 1
  19.  
  20.         return pre
Advertisement
Add Comment
Please, Sign In to add comment