Remove Duplicates from Sorted Array

来源:互联网 发布:林彪为什么要叛变 知乎 编辑:程序博客网 时间:2024/04/30 14:02

Remove Duplicates from Sorted Array


public class Solution {    public int removeDuplicates(int[] A) {         boolean isEqual = false;        int count = 0;        int tmp = 0;        if(A == null || A.length == 0){            return 0;        }        if(A.length == 1){            return 1;        }        for(int i = 1 ; i < A.length ; i++){            if(A[i] == A[i -1]){                count++;                tmp++;                isEqual = true;            }else if(tmp > 0){                A[i - tmp] = A[i];            }        }//        for(int i = 0 ; i < A.length ; i++){//            System.out.println(A[i]);//        }        return A.length - count;    }}
虽然是一道简单题目,但是可以做到1A也挺开心的,不过这道题记得之前做过,但是看MySubmisson里面却没有提交记录,用了看过的方法做的

0 0
原创粉丝点击