Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 963 Bytes

_26. Remove Duplicates from Sorted Array.md

File metadata and controls

45 lines (33 loc) · 963 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : May 22, 2024

Last updated : July 01, 2024


Related Topics : Array, Two Pointers

Acceptance Rate : 58.83 %


Solutions

Java

class Solution {
    public int removeDuplicates(int[] nums) {
        int counter = 1;
        int shift = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[i - 1]) {
                shift++;
            } else {
                counter++;
            }

            nums[i - shift] = nums[i];
        }

        return counter;
    }
}