forked from akshitagit/JAVA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
akshitagit#46 - BalanceParentheses setup
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
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
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 | ||
|
||
} | ||
|
||
} |