Skip to content

Commit

Permalink
akshitagit#46 - BalanceParentheses setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nowele committed Sep 26, 2020
1 parent 55d03a6 commit a148bd2
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Interview_Questions/BalanceParentheses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
https://github.com/akshitagit/JAVA/issues/46
You are given a string of brackets i.e. '{', '}' , '(' , ')', '[' , ']' .
You have to check whether the sequence of parenthesis is balanced or not.
For example, "(())", "(())()" are balanced and "())(", "(()))" are not.
Input Format
A string of '(' , ')' , '{' , '}' and '[' , ']' .
Constraints
1<=|S|<=10^5
Output Format
Print "Yes" if the brackets are balanced and "No" if not balanced.
Sample Input
(())
Sample Output
Yes
*/

public class BalanceParentheses {

public static void balanceParentheses(String brackets) {

//Characters
String curlyOpen = "{";
String curlyClose = "}";
String bracketOpen = "[";
String bracketClose = "]";
String parenthesesOpen = "(";
String parentheseClose = ")";

String result = "";

//@TODO - determine if brackets is balanced

System.out.println("result: " + result);
}

public static void main(String[] args) {
balanceParentheses("(())"); //balanced
balanceParentheses("(())()"); //balanced
balanceParentheses("())("); // not balanced
balanceParentheses("(()))"); //not balanced

}

}

0 comments on commit a148bd2

Please sign in to comment.