Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool IsStringValid(string str) {
- bool[] bracesData = new bool[str.length];
- int braces = 0;
- for(int i=0; i<str.length; i++) {
- switch(str[i]) {
- case '(':
- bracesData[braces] = false;
- braces++;
- break;
- case '[':
- bracesData[braces] = true;
- braces++;
- break;
- case ')':
- braces--;
- if(bracesData[braces] != false) return false;
- break;
- case ']':
- braces--;
- if(bracesData[braces] != true) return false;
- break;
- }
- if(braces < 0) return false;
- }
- return braces == 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement