Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 1.22 KB

_27. Remove Element.md

File metadata and controls

55 lines (43 loc) · 1.22 KB

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

Back to top


First completed : June 02, 2024

Last updated : July 10, 2024


Related Topics : Array, Two Pointers

Acceptance Rate : 58.93 %


Solutions

Java

class Solution {
    public int removeElement(int[] nums, int val) {
        int pointer = 0;

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                nums[pointer] = nums[i];
                pointer += 1;
            }
        }
        return pointer;
    }
}

Python

class Solution:
    def removeElement(self, nums: List[int], val: int) -> int:
        currentPointer = 0
        for i in range(len(nums)) :
            if not nums[i] == val :
                nums[currentPointer] = nums[i]
                currentPointer += 1
        return currentPointer