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个)第一次,从左往右扫,右边的rating大于左边的,则右边的个数=左边个数+1
第二次,从右往左扫,左边的rating大于右边的,