forked from mayankchaudhary26/HacktoberFest-Practice-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicate_Brackets.java
More file actions
33 lines (26 loc) Β· 880 Bytes
/
Duplicate_Brackets.java
File metadata and controls
33 lines (26 loc) Β· 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
public class Duplicate_brackets {
public static boolean Brackets(String str) {
LinkedList<Character> st = new LinkedList<>();
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
boolean IsLoopRun = false;
while(st.size() != 0 && ch == ')' && st.getFirst() != '('){
IsLoopRun = true;
st.removeFirst();
}
if(!IsLoopRun && ch == ')')
return true;
else if(IsLoopRun)
st.removeFirst();
else
st.addFirst(ch);
}
return false;
}
public static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
String str = sc.nextLine();
System.out.println(Brackets(str));
}
}