题目描述
题目链接: https://leetcode-cn.com/problems/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?
解题思路
贪心算法的运用,双向爬坡。从左到右爬一边,再从右到左爬一边。再累加所有值即可。
程序实现
public class Solution {
public int candy