C++ | 10ms | 99.62% | Beginner Friendly | Fast
C++ | 10ms | 99.62% | Beginner Friendly | Fast\n\nclass Solution {\npublic:\n    int candy(vector<int> &ratings)\n {\n\t int size=ratings.size();\n\t if(size<=1
# C++ | 10ms | 99.62% | Beginner Friendly | Fast\n```\nclass Solution {\npublic:\n    int candy(vector<int> &ratings)\n {\n\t int size=ratings.size();\n\t if(size<=1)\n\t\t return size;\n\t vector<int> num(size,1);\n\t for (int i = 1; i < size; i++)\n\t {\n\t\t if(ratings[i]>ratings[i-1])\n\t\t\t num[i]=num[i-1]+1;\n\t }\n\t for (int i= size-1; i>0 ; i--)\n\t {\n\t\t if(ratings[i-1]>ratings[i])\n\t\t\t num[i-1]=max(num[i]+1,num[i-1]);\n\t }\n\t int result=0;\n\t for (int i = 0; i < size; i++)\n\t {\n\t\t result+=num[i];\n\t\t// cout<<num[i]<<" ";\n\t }\n\t return result;\n }\n};\n```
['C', 'C++']