Advertisement
exmkg

2-2

Jan 14th, 2025
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. class Solution {
  2.     public int removeElement(int[] nums, int val) {
  3.         int index = 0;
  4.         for (int i = 0; i < nums.length; i++) {
  5.             if (nums[i] != val) {
  6.                 // Gather values that are not equal to 'val'
  7.                 // at the beginning of the array, one-by-one.
  8.                 nums[index] = nums[i];
  9.                 index++;
  10.             }
  11.         }
  12.         return index;
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement