26. 刪除排序數組中的重複項 java

class Solution {
    public int removeDuplicates(int[] nums) {
        if(nums == null || nums.length == 0) return 0;
        int pos = 1;
        for(int i=1; i<nums.length; i++) {
            if(nums[i] != nums[i-1]) nums[pos++] = nums[i];
        }
        return pos;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章