Skip to content

Commit

Permalink
프로그래머스/StackQueue: 올바른 괄호 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunnnn committed Dec 18, 2023
1 parent c7b36dd commit 3d43877
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/programmers/algorithmKit/stackQueue/PROB03.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package programmers.algorithmKit.stackQueue;

import java.util.*;

public class PROB03 {
boolean solution(String s) {
Stack<Character> stack = new Stack<>();

for (char c : s.toCharArray()) {
if (c == '(') {
stack.push(c);

} else { // ')' 인 경우
if (stack.isEmpty() || stack.peek() != '(') {
return false;
}
stack.pop();
}
}

if (stack.isEmpty()) {
return true;
}

return false;
}
}

0 comments on commit 3d43877

Please sign in to comment.