diff --git a/solutions/day08/solution_java.java b/solutions/day08/solution_java.java new file mode 100644 index 0000000..62e52f6 --- /dev/null +++ b/solutions/day08/solution_java.java @@ -0,0 +1,20 @@ +class Solution { + public int minSwaps(String s) { + Stack st = new Stack<>(); + int ans = 0; + for(int i = 0;i < s.length(); i++){ + Character temp = s.charAt(i); + if(temp == '['){ + st.push(temp); + }else{ + if(!st.isEmpty()){ + st.pop(); + }else{ + ans++; + } + } + } + + return (ans + 1) / 2; + } +}