美文网首页
26. Remove Duplicates from Sorte

26. Remove Duplicates from Sorte

作者: becauseyou_90cd | 来源:发表于2018-08-01 07:48 被阅读0次

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 Sorte

      本文链接:https://www.haomeiwen.com/subject/dgflvftx.html