Last active
January 5, 2021 14:30
-
-
Save mumunuu/d4b6e278fc1b68e74d425e086ff30d01 to your computer and use it in GitHub Desktop.
algorithm(leetcode) Remove Duplicates from Sorted Array
This file contains 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
func removeDuplicates(nums []int) int { | |
if len(nums) == 0 { | |
return 0 | |
} | |
i := 0 | |
j := 1 | |
for j < len(nums) { | |
if nums[j] != nums[i] { | |
i++ | |
nums[i] = nums[j] | |
j++ | |
} else { | |
j++ | |
} | |
} | |
return i + 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment