Title Description:
Given a sorted array, remove the duplicates in place such, all element appear only once and return the new L Ength.
Do the allocate extra space for another array, and you must does this on place with constant memory.
Problem Solving Analysis:
Scan through the linked list, using a variable to mark the length of the found non-repeating element Len, and whenever a non-repeating element is found, let the element that is scanned by the element and the variable len be swapped for the position
Specific code:
1 Public classSolution {2 Public Static intRemoveDuplicates (int[] nums) {3 if(nums.length<=1)4 returnnums.length;5 intNum =nums[0];6 intLen =1;7 for(inti=1;i<nums.length;i++){8 if(num!=Nums[i]) {9num=Nums[i];Tennums[len]=Nums[i]; Onelen++; A } - } - returnLen; the } - -}
"Leetcode" 26. Remove Duplicates from Sorted Array