LeetCode 82 Remove Duplicates from Sorted List

来源:互联网 发布:apache启动和开始命令 编辑:程序博客网 时间:2024/06/07 03:32

Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.

public class Solution {    public int removeDuplicates(int[] A) {        if(A==null || A.length<1) return 0;        int i=1;        int elem=A[0];        for(int j=1; j<A.length; j++) {            if(A[j]!=elem) {                elem=A[j];                A[i++] = A[j];             }        }        return i;            }}


0 0