Friday, November 20, 2015

[leetcode] Remove Duplicate From Sorted Array

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
public class Solution {
    public int removeDuplicates(int[] nums) {
        if (nums == null || nums.length == 0) return 0;
        int available = 1;
        for (int i = 1; i < nums.length; i++){
            if (nums[i] != nums[i-1]){
                nums[available++] = nums[i];
            }
        }
        return available;
    }
}

No comments:

Post a Comment