1 /// <summary> 2 /// Solution 3 /// 通过率 83/60 4 /// </summary> 5 /// <param name="A"></param> 6 /// <returns></returns> 7 public int solution(int[] A) 8 { 9 int length = A.Length; 10 bool[] flagArr = new bool[length]; 11 int peakNum = 0; 12 13 for (int i = 1; i < length - 1; i++) 14 { 15 if (A[i] > A[i - 1] && A[i] > A[i + 1]) 16 { 17 flagArr[i] = true; 18 peakNum++; 19 } 20 } 21 22 int div = 0; 23 int divLength = 0; 24 25 for (int bloks = peakNum; bloks > 1; bloks--) 26 { 27 if (length % bloks == 0) 28 { 29 div = length / bloks; 30 divLength = div; 31 for (int i = 0; i < divLength; i++) 32 { 33 if (flagArr[i] == true && divLength < length) 34 { 35 i = divLength; 36 divLength += div; 37 } 38 } 39 if (divLength == length) 40 return bloks; 41 } 42 } 43 44 if (peakNum > 0) 45 return 1; 46 else 47 return 0; 48 }
时间: 2024-12-28 16:26:41