Created
July 18, 2020 12:15
-
-
Save bangarharshit/7827ebaed4a1fa6dabfd08c3b5fd0089 to your computer and use it in GitHub Desktop.
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 class BalancedParanthesis2 { | |
public static void main(String[] args) { | |
} | |
// ((())) | |
private static boolean validExpression(String expression, int numOfRetriesAvailable) { | |
if (expression == null) { | |
return true; | |
} | |
char[] chars = expression.toCharArray(); | |
int count = 0; | |
for (char aChar : chars) { | |
if (aChar == '(') { | |
count++; | |
} else { | |
count--; | |
} | |
if (count < 0) { | |
return false; | |
} | |
} | |
if (count == 0) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment