Five lines Solution


  • 0
    T
    public class Solution {
        public int removeDuplicates(int[] nums) {
            int num=0;
            for(int i=1; i<nums.length; ++ i){
                if(nums[i]!=nums[num]) nums[++num]=nums[i];
            }
            return nums.length==0 ? 0 : num+1;
        }
    }

Log in to reply
 

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