Skip to content

Instantly share code, notes, and snippets.

@sbsatter
Created August 19, 2016 15:27
Show Gist options
  • Save sbsatter/c09e2f6ea5970d1fa64bf0a0bb1d98a7 to your computer and use it in GitHub Desktop.
Save sbsatter/c09e2f6ea5970d1fa64bf0a0bb1d98a7 to your computer and use it in GitHub Desktop.
Find nested parenthesis recursively
public boolean nestParen(String str) {
int i= str.indexOf('('), j=str.lastIndexOf(')');
if(i==-1 ^ j==-1){
return false;
}
if(i==-1 && j==-1)
return true;
return nestParen(str.substring(i+1,j));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment