标签:div i+1 log length turn solution += die return
class Solution { public int candy(int[] ratings) { int[] candies=new int[ratings.length]; for(int i=0;i<ratings.length;i++) candies[i]=(i!=0&&ratings[i-1]<ratings[i])?candies[i-1]+1:1; for(int i=ratings.length-2;i>=0;i--) if(ratings[i]>ratings[i+1]) candies[i]=Math.max(candies[i],candies[i+1]+1); int res=0; for(int candy:candies) res+=candy; return res; } }
标签:div i+1 log length turn solution += die return
原文地址:http://www.cnblogs.com/asuran/p/7636996.html