leetcod 2 Remove Duplicates from Sorted Array

    技术2025-10-29  10

    Remove Duplicates from Sorted Array class Solution { public int removeDuplicates(int[] nums) { if(nums.length==1){ return 1; } if(nums.length==2){ if(nums[0]==nums[1]){ return 1;} else return 2; } int i=0; int j=1; int r=0; while(j<nums.length){ if(nums[i]==nums[i+1]){ r++; }else{ i++; } if(++j==nums.length){ break; } nums[i+1]=nums[j]; }; return nums.length-r; }}
    Processed: 0.008, SQL: 10