Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions week2/2. 올바른 괄호/Solution.java

This file was deleted.

51 changes: 51 additions & 0 deletions week2/2. 올바른 괄호/Solution2_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java.util.Map;

/*
2. 올바른 괄호
https://programmers.co.kr/learn/courses/30/lessons/12909
*/
public class Solution2_2 {
public static void main(String[] args) {

String s = "(()(";

System.out.println(solution(s));

}

public static boolean solution(String s) {

int stack = 0;

if (s.charAt(0) == ')') {
return false;
}

for (char c : s.toCharArray()) {

switch (c) {
case '(':

stack += 1;

break;

case ')':

stack -= 1;

if (stack < 0) {
return false;
}

break;

default:
break;
}

}

return stack == 0 ? true : false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3항 연산자의 결과가 boolean 타입이면 그냥 조건식을 return 해도 됩니다.
return stack == 0;

}
}