标签:leetcode
题意:从有序数组中删除重复数据,但是与题目一有一点区别:可以允许重复一次public int removeDuplicates(int[] A) { if(A == null || A.length == 0)return 0; int len = A.length; int i = 0, j = i + 1; while (j < A.length){ if(j - i > 1){ A[i + 1] = A[j]; } if(A[j] == A[i]){//找到第二个该元素 i ++; j ++; while (j < A.length){//删除第三个以上的相同元素 if(A[j] == A[i]){ j ++; }else { A[i + 1] = A[j]; i = i + 1; j = j + 1; break; } } }else { i ++; j ++; } } len = i + 1; return len; }
[LeetCode]Remove Duplicates from Sorted Array2
标签:leetcode
原文地址:http://blog.csdn.net/youmengjiuzhuiba/article/details/45110449