删除数组重复项

 1 class Solution {
 2     public int removeDuplicates(int[] nums) {
 3      int length = nums.length - 1;
 4         for (int i = 0; i <= length; i++) {
 5             for (int j = i + 1; j <= length; j++) {
 6                 if (nums[i] == nums[j]) {
 7                     for (int k = i; k <length ; k++) {
 8                         nums[k] = nums[k + 1];
 9                     }
10                     nums[length] = 0;
11                     length--;
12                     j--;
13                 }
14             }
15         }
16         length++;
17         return length;
18             
19 }
20 }

猜你喜欢

转载自www.cnblogs.com/Baronboy/p/10743092.html