码迷,mamicode.com
首页 > 其他好文 > 详细

Peaks【遗留问题】

时间:2015-07-26 05:55:06      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

 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         }

 

Peaks【遗留问题】

标签:

原文地址:http://www.cnblogs.com/HuoAA/p/4676943.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!