美文网首页
移除元素

移除元素

作者: 叫我颜先生 | 来源:发表于2022-02-25 11:02 被阅读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;
        }
    }
    

    相关文章

      网友评论

          本文标题:移除元素

          本文链接:https://www.haomeiwen.com/subject/clvolrtx.html