1 /// <summary> 2 /// Solution 3 /// 通过率 100/50 4 /// </summary> 5 /// <param name="A"></param> 6 /// <returns></returns> 7 public static int[] solution(int[] A) 8 { 9 int sum = 0; 10 int[] arr = new int[A.Length]; 11 int[] result = new int[A.Length]; 12 Dictionary<int, int> dic = new Dictionary<int, int>(); 13 14 for (int i = 0; i < A.Length; i++) 15 arr[i] = A[i]; 16 17 Array.Sort(arr); 18 19 for (int i = 0; i < arr.Length; i++) 20 { 21 if (i < arr.Length - 1 && arr[i] == arr[i + 1]) 22 continue; 23 24 if (!dic.ContainsKey(arr[i])) 25 { 26 sum = 0; 27 for (int j = 0; j < i; j++) 28 { 29 if (arr[i] % arr[j] == 0) 30 sum++; 31 } 32 dic.Add(arr[i], A.Length - sum - 1); 33 } 34 } 35 36 for (int i = 0; i < A.Length; i++) 37 { 38 result[i] = dic[A[i]]; 39 } 40 41 return result; 42 }
时间: 2024-10-19 03:18:27