- int removeDuplicates(int* nums, int numsSize){
- int i = 0;
- int j = 1;
- int k = 1;
- int tmp = nums[i];
- while(j < numsSize) {
- if(nums[j] == tmp && k < 2) {
- nums[++i] = nums[j];
- k++;
- j++;
- } else if(nums[j] != tmp) {
- tmp = nums[j];
- nums[++i] = nums[j];
- k = 1;
- j++;
- } else {
- j++;
- }
- }
- return i + 1;
- }
- int removeDuplicates(int* nums, int numsSize){
- if(numsSize == 1 || numsSize == 2) {
- return numsSize;
- }
- int k = 2;
- int i = 0;
- for(i = 2; i < numsSize; i++) {
- if(!(nums[k - 2] == nums[k - 1] && nums[i] == nums[k - 1])) {
- nums[k] = nums[i];
- k++;
- }
- }
- return k;
- }
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!