Last active
February 7, 2017 02:16
-
-
Save khomutoff/50d6d2c13bea8b73e3a0c42120844a00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| # Given a sorted array, remove the duplicates in place such that each element can appear atmost twice and return the new length. | |
| # @param A : list of integers | |
| # @return an integer | |
| def removeDuplicates(self, A): | |
| if len(A) < 2: | |
| return len(A) | |
| index = 0 | |
| while index < (len(A)): | |
| if A[index] == A[index - 2]: | |
| A.pop(index) | |
| else: | |
| index += 1 | |
| return len(A) | |
| class Solution: | |
| # @param A : list of integers | |
| # @return an integer | |
| def removeDuplicates(self, A): | |
| if len(A) < 4: | |
| return len(A) | |
| index = 1 | |
| match = False | |
| while index < (len(A)): | |
| if A[index] == A[index - 1]: | |
| if match is True: | |
| A.pop(index) | |
| else: | |
| match = True | |
| index += 1 | |
| else: | |
| match = False | |
| index += 1 | |
| return len(A) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment