您的位置:首页 > 其它

LeetCode 26. Remove Duplicates from Sorted Array

2016-11-20 18:27 435 查看
public class Solution {
public int removeDuplicates(int[] nums) {
if (nums.length == 0) return 0;
int length = 1;
int val = nums[0];
for (int i = 1; i < nums.length; i++) {
if (nums[i] != val) {
nums[length++] = nums[i];
val = nums[i];
}
}
return length;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: