Created
July 1, 2019 13:11
-
-
Save Desolve/17ad6dbe70bef408aa2c3c40cb00acaf to your computer and use it in GitHub Desktop.
0026 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
class Solution { | |
public int removeDuplicates(int[] nums) { | |
if (nums.length <= 1) return nums.length; | |
int i = 0; | |
for (int j = 1; j < nums.length; j++) { | |
if (nums[j] != nums[i]) { | |
i++; | |
nums[i] = nums[j]; | |
} | |
} | |
return i + 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment