-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathanswer.py
33 lines (28 loc) · 862 Bytes
/
answer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
#-------------------------------------------------------------------------------
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
# If array is empty
if len(nums) == 0:
return 0
# Two Pointer Solution
# j is slow runner, i is fast runner
j = 0;
for i in range(1, len(nums)):
# If they are unique, change the array and increment both
if nums [i] != nums[j]:
j += 1
nums[j] = nums[i]
# Return the slow runner + 1 for length
return j + 1
#-------------------------------------------------------------------------------
# Testing
def main():
x = Solution()
y = x.removeDuplicates([1,1,1,1,2,3,3])
print y
main()