Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool checkValidString(string s) {
- int len = s.size(), lo = 0, hi = 0;//range of # of open left bracket
- for(int i = 0; i < len; ++i)
- {
- lo = s[i] == '('? lo + 1: lo - 1;
- hi = s[i] == ')'? hi - 1: hi + 1;
- if(hi < 0)return false;
- lo = max(lo, 0);
- }
- return lo == 0;
- }
- };
Add Comment
Please, Sign In to add comment