135. 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?
思路
先从左向右遍历一遍,右边的比左边的大,不大则设置为1
再从右向左遍历一遍,左边的比右边的大,已经大的不动
1 | public class Solution { |