PassingCars

 1         /// <summary>
 2         /// Solution
 3         /// 100/100
 4         /// </summary>
 5         /// <param name="A"></param>
 6         /// <returns></returns>
 7         public static int solution(int[] A)
 8         {
 9             int result = 0;
10             int temp = 0;
11             for (int i = A.Length - 1; i >= 0; i--)
12             {
13                 if (A[i] == 1)
14                     temp++;
15                 else
16                     result += temp;
17             }
18             if (Math.Abs(result) > 1000000000)
19                 result = -1;
20             return result;
21         }

 

posted @ 2015-07-25 01:48  叫我霍啊啊啊  阅读(226)  评论(0编辑  收藏  举报