aboutsummaryrefslogtreecommitdiff
path: root/other/candy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/candy.cpp')
-rw-r--r--other/candy.cpp37
1 files changed, 0 insertions, 37 deletions
diff --git a/other/candy.cpp b/other/candy.cpp
deleted file mode 100644
index 83915b0..0000000
--- a/other/candy.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "leetcode.h"
-
-class Solution {
-public:
- int candy(vector<int> &ratings) {
- if (ratings.size() <= 1)
- return ratings.size();
- int ans = 0, up = 0, down = 0, oldSign = 0;
- for (int i = 1; i < ratings.size(); i++) {
- int newSign = ratings[i] > ratings[i - 1] ? 1
- : ratings[i] < ratings[i - 1] ? -1
- : 0;
- if ((oldSign > 0 && newSign == 0) || (oldSign < 0 && newSign >= 0)) {
- ans += helper(up) + helper(down) + max(up, down);
- up = 0;
- down = 0;
- }
- if (newSign > 0)
- up++;
- if (newSign < 0)
- down++;
- if (newSign == 0)
- ans++;
- oldSign = newSign;
- }
- ans += ramp(up) + ramp(down) + max(up, down) + 1;
- }
-
-private:
- int helper(int n) { return (n * (n + 1)) / 2; }
-};
-
-int main() {
- Solution obj;
- vector<int> ratings = {};
- cout << obj.candy(ratings);
-}