Skip to content

Instantly share code, notes, and snippets.

@mchernyavskaya
Created February 19, 2017 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchernyavskaya/e64108cdf339e0c46e9145d91ce53a62 to your computer and use it in GitHub Desktop.
Save mchernyavskaya/e64108cdf339e0c46e9145d91ce53a62 to your computer and use it in GitHub Desktop.
Check matching brackets - solution without a stack
public class Groups{
public static boolean groupCheck(String s) {
int len;
do {
len = s.length();
s = s.replace("()", "");
s = s.replace("{}", "");
s = s.replace("[]", "");
} while (len != s.length());
return s.length() == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment