#include <string>
#include <iostream>
#include <stack>
using namespace std;
bool solution(string str)
{
stack<char> s;
for (auto e : str) {
if (e == '(')
s.push(e);
else {
if (s.empty() || s.top() == ')')
return false;
s.pop();
}
}
return s.empty();
}
import java.util.*;
class Solution {
boolean solution(String str) {
boolean answer = true;
Stack<Character> s = new Stack<>();
for (var e : str.toCharArray()) {
if (e == '(') {
s.push(e);
continue;
}
if (s.isEmpty() || s.peek() == ')')
return false;
s.pop();
}
return s.isEmpty();
}
}
태그 - algorithm, hash(사용한 자료구조), boj(플랫폼)