Java code. easy to read.


  • 0
    Z
    public class Solution {
        public int removeDuplicates(int[] nums) {
            if(nums==null || nums.length ==0)
                return 0;
                
            Integer cur = null; // special value, means uninitialized.
            int len = 0;
            
            for(int n : nums){
                if(cur == null || cur < n){
                    cur = n;
                    nums[len ++ ] = n;
                }
            }
            
            return len;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.