26. Remove Duplicates from Sorted Array

https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/

解题思路:
nums[res++] = nums[i]; res代表无重复的index

代码:
class Solution {
public int removeDuplicates(int[] nums) {
if(nums == null || nums.length == 0) return 0;
int res = 1;
for(int i = 1; i < nums.length; i++){
if(nums[i - 1] == nums[i]){
continue;
} else {
nums[res++] = nums[i];
}
}
return res;
}
}

你可能感兴趣的:(26. Remove Duplicates from Sorted Array)