package com.zmz.algorithm.array;

/**
 * @author 张明泽
 * Create by 2022/5/23 0:48
 * 移除元素
 * LeetCode-27
 */
public class RemoveElement {
    public static void main(String[] args) {
        int[] nums = {3,2,2,3};
        int number = remove(nums,3);
        System.out.println(number);
    }
    public static int remove(int[] nums, int target) {
        int temp = 0;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] != target) {
                nums[temp++] = nums[i];
            }
        }
        return temp;
    }
}
最后修改:2022 年 05 月 25 日 12 : 15 PM
赏杯咖啡喝 谢谢您~