Created
August 19, 2016 15:27
-
-
Save sbsatter/c09e2f6ea5970d1fa64bf0a0bb1d98a7 to your computer and use it in GitHub Desktop.
Find nested parenthesis recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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