Java Quick Short Solution

  • 1

    Inspired by @StefanPochmann in the previous problem.

    public class Solution {
        public int removeElement(int[] nums, int val) {
            int i = 0;
            for (int n : nums) {
                if (n != val)
                    nums[i++] = n;
            return i;

Log in to reply

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