diff options
Diffstat (limited to 'other/split_array_consec_subseq.cpp')
-rw-r--r-- | other/split_array_consec_subseq.cpp | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/other/split_array_consec_subseq.cpp b/other/split_array_consec_subseq.cpp deleted file mode 100644 index 622e296..0000000 --- a/other/split_array_consec_subseq.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "leetcode.h" - -class Solution { -public: - bool isPossible(vector<int> &nums) { - unordered_map<int, int> um; - for (auto &it : nums) - um[it]++; - for (auto &it : nums) { - if (um[it] == 0) - continue; - int freq = um[it], curr = it, count = 0; - while (um.count(curr) && um[curr] >= freq) { - freq = fmax(freq, um[curr]); - um[curr]--; - count++; - curr++; - } - if (count < 3) - return false; - } - return true; - } -}; - -int main() { - Solution obj; - vector<int> nums = {1, 2, 3, 4, 5}; - if (obj.isPossible(nums)) - cout << "true"; - else - cout << "false"; -} |