DEV Community

Debesh P.
Debesh P.

Posted on

80. Remove Duplicates from Sorted Array II | LeetCode | Top Interview 150 | Coding Questions

Problem Link

https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/


leetcode 80


Solution

class Solution {
    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        int j = 2;
        for(int i=2; i<n; i++) {
            if(nums[i] != nums[j-2]) {
                nums[j] = nums[i];
                j++;
            }
        }

        return j;
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)