DEV Community

Debesh P.
Debesh P.

Posted on

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

Problem Link

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


leetcode 26


Solution

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

        return j+1;
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)