题解 | 草原牛群集合
草原牛群集合
https://www.nowcoder.com/practice/6fc74519ff9c44288dbcec5db7345ded
- 插入即可。
import java.util.*; public class Solution { public int remove_cows (int[] nums, int val) { final int n = nums.length; int next = 0; for (int i = 0; i < n; ++i) { if (nums[i] != val) { nums[next] = nums[i]; ++next; } } return next; } }