My simple java solution


  • 0
    P
    public class Solution {
        public int removeElement(int[] nums, int val) {
            int tail = nums.length - 1;
            int i = 0;
            for (; i <= tail; i++) {
                if (nums[i] == val) nums[i--] = nums[tail--];
            }
            return i;
        }
    }

Log in to reply
 

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