原题
前后两遍遍历
class Solution
{
public:int candy(vector<int> &ratings){
int len = ratings.size();vector<int> candys(len, 1);for (int i = 1, base = 2; i < len; i++){
if (ratings[i] > ratings[i - 1])candys[i] = max(base++, candys[i]);elsebase = 2;}for (int i = len - 2, base = 2; i >= 0; i--){
if (ratings[i] > ratings[i + 1])candys[i] = max(base++, candys[i]);elsebase = 2;}for (auto c : candys){
cout << c << endl;}return accumulate(candys.begin(), candys.end(), 0);}
};