You are viewing a single comment's thread. Return to all comments →
C#
char last = ' '; for (int i = 0;i<s.Length;i++) { char c = s[i]; switch (c) { case '{': break; case '[': break; case '(': break; case ')': if (last=='(') { s = s.Remove(i - 1, 2); i -= 2; } else { return "NO"; } break; case ']': if (last == '[') { s = s.Remove(i - 1, 2); i -= 2; } else { return "NO"; } break; case '}': if (last == '{') { s = s.Remove(i - 1, 2); i -= 2; } else { return "NO"; } break; } if (i>-1) { last = s[i]; } else { last = ' '; } } if (s.Length==0) { return "YES"; } else { return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
C#