题解 | #数组中只出现一次的数(其它数出现k次)#
数组中只出现一次的数(其它数出现k次)
https://www.nowcoder.com/practice/5d3d74c3bf7f4e368e03096bb8857871
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param arr int整型一维数组 * @param k int整型 * @return int整型 */ public int foundOnceNumber (List<int> arr, int k) { // write code here if (arr == null || arr.Count <= k) return 0; for (int nIndex = 0; nIndex < arr.Count; nIndex++) { if (arr.IndexOf(arr[nIndex]) == arr.LastIndexOf(arr[nIndex])) return arr[nIndex]; } return 0; } }