Guest User

Untitled

a guest
Oct 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. class Solution {
  2. public:
  3. bool checkValidString(string s) {
  4. int len = s.size(), lo = 0, hi = 0;//range of # of open left bracket
  5. for(int i = 0; i < len; ++i)
  6. {
  7. lo = s[i] == '('? lo + 1: lo - 1;
  8. hi = s[i] == ')'? hi - 1: hi + 1;
  9. if(hi < 0)return false;
  10. lo = max(lo, 0);
  11. }
  12. return lo == 0;
  13. }
  14. };
Add Comment
Please, Sign In to add comment