Question
Please use Java for the following question Brackets Matches Given a string of parentheses, check if the parentheses is valid and display the complete parentheses.
Please use Java for the following question
Brackets Matches
Given a string of parentheses, check if the parentheses is valid and display the complete parentheses.
For example:
Given a string value of "(("", it's a invalid parentheses because it's not complete, the complete parentheses should be "()()" because each "(" character shoud be mathced with a ")" closing bracket.
Sample input: "(()(("
Sample output should be : "()()()()".
Because only one set of parentheses is complete at index 1 and 2, so the other three "(" should have a ")" for each one of them.
Sample input: ")(()("
Sample output should be: "()()()()"
Since the first index has ")" so we should add a open bracket for it and index 1 has only "(" so add a close bracket to it and index 2 and 3 are a set of bracket so it's all set, and the last index should have a close bracket.
Sample input : "))(("
Sample output "()()()()"
Since all four indexes are missing parts of brackets so add brackets for them all.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started