/*
* @Author: sumBorn
* @Date: 2022-02-21 19:30:18
* @LastEditTime: 2022-02-22 14:27:19
* @Description: https://leetcode-cn.com/leetbook/read/all-about-array/x9p1iv/
*/
/**
* @description: 双指针
* @param {*}
* @return {*}
*/
public class Solution
{
public int RemoveElement(int[] nums, int val)
{
int arrLength = nums.Length;
int left = 0;
for (var right = 0; right < arrLength; right++)
{
if (nums[right] != val)
{
nums[left] = nums[right];
left++;
}
}
return left;
}
}
移除元素
最新推荐文章于 2025-12-06 07:43:37 发布
本文介绍了一个使用双指针解决数组元素移除问题的Java实现。`Solution`类中的`RemoveElement`方法通过左右指针遍历数组,有效移除指定值并返回新数组长度。这种方法优化了空间复杂度,仅修改原数组。
799

被折叠的 条评论
为什么被折叠?



