Skip to content

Instantly share code, notes, and snippets.

@bangarharshit
Created July 18, 2020 12:15
Show Gist options
  • Save bangarharshit/7827ebaed4a1fa6dabfd08c3b5fd0089 to your computer and use it in GitHub Desktop.
Save bangarharshit/7827ebaed4a1fa6dabfd08c3b5fd0089 to your computer and use it in GitHub Desktop.
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