My 1ms Java Solution


  • 0
    public class Solution {
        public int removeDuplicates(int[] nums) {
            int count = 0;
            int pos = 0;
            for (int i = 0; i < nums.length; ++i) {
                if (i != 0 && nums[i] != nums[i - 1]) {
                    count = 0;
                }
                count++;
                if (count < 3) {
                    nums[pos++] = nums[i];
                }
            }
            return pos;
        }
    }
    

Log in to reply
 

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