题目
2.1.22 Candy
There are N children standing in a line. Each child is assigned a rating value.
You are giving candies to these children subjected to the following requirements:
• Each child must have at least one candy.
• Children with a higher rating get more candies than their neighbors.
What is the minimum candies you must give?
翻译
N个小朋友站成一排,每个小朋友最少分一个糖果,相邻的小朋友得分高的比得分低的糖果多。
求最少需要多少糖果
分析
1、从左到右扫描,左边得分高的比右边多
2、从右往左扫描,右边得分高的比左边多
3、计算糖果
代码
代码稍后给出