Java clean code


  • -1
    public class Solution {
        public int removeDuplicates(int[] nums) {
            if (nums == null || nums.length == 0)
                return 0;
            int i = 0; // last processed item
            for (int j = 1; j < nums.length; j++) {
                if (nums[j] != nums[i]) {
                    nums[++i] = nums[j];
                }
            }
            return i + 1;
        }
    }

Log in to reply
 

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