Skip to content

Commit

Permalink
Merge pull request #52 from arya2004/arya2004-day08-java
Browse files Browse the repository at this point in the history
Create solution_java.java
  • Loading branch information
arya2004 authored Oct 8, 2024
2 parents d530ab1 + ea8c848 commit a5942fa
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions solutions/day08/solution_java.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {
public int minSwaps(String s) {
Stack<Character> 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;
}
}

0 comments on commit a5942fa

Please sign in to comment.