Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int longestWPI(vector<int>& hours) {
- int curr=0, ans=0;
- unordered_map<int, int> seen;
- for(int i=0; i<hours.size(); i++){
- curr += ((hours[i]>8) ? 1:-1);
- if(curr > 0)
- ans = i+1;
- if(seen.find(curr) == seen.end()){
- seen[curr] = i;
- }
- if(seen.find(curr-1) != seen.end()){
- ans = max(ans, i-seen[curr-1]);
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment