1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public class Solution { public int RemoveDuplicates(int[] nums) { int uniqueCount = nums.Distinct().Count(); int[] uniqueNumbers = new int[uniqueCount]; Array.Copy( nums.Distinct().ToArray(), uniqueNumbers, uniqueCount); for (int i = 0; i < uniqueNumbers.Length; i++) { nums[i] = uniqueNumbers[i]; }
return uniqueCount; } }
|
因為題目說前面開頭k個數字跟他需要的數字一樣就可以所以不用多餘的數字