package leetcode_50; import java.util.Arrays; /*** * * @author pengfei_zheng * 移除数组中重复元素,返回剩余元素个数 */ public class Solution27 { public static int removeElement(int[] nums, int val) { Arrays.sort(nums); int i=0; for(int n:nums){ if(n!=val){ nums[i++]=n; } } return i; } public static void main(String[]args){ int []nums = {4,5,3,6,3,7}; System.out.println(removeElement(nums,3)); } }