移除元素

2022-02-25  本文已影响0人  叫我颜先生
/*
 * @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;
    }
}
上一篇下一篇

猜你喜欢

热点阅读