very easy C# solution (beats 88.52%)


  • 0
    K
    public class Solution {
        public int RemoveDuplicates(int[] nums) {
            int k = 0;
            int len = nums.Length;
            int max = Int32.MaxValue;
            
            if (len<=2) return len;
            
            for (int i=1; i< nums.Length; i++) {
                if (nums[i]==nums[i-1]) {
                    k++;
                    if (k > 1) {
                        nums[i-1] = max;
                        len--;
                    }
                }
                else
                    k = 0;
            }
            Array.Sort(nums);
            return len;
        }
    }
    

Log in to reply
 

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