
Stack/Queuw > 올바른 괄호
using System;
using System.Collections.Generic;
public class Solution
{
public bool solution(string s)
{
Stack<char> stack = new Stack<char>();
foreach(char c in s)
{
if(c == '(')
{
stack.Push(c);
}
else
{
// 추가되지도 않았는데 들어옴 ㅇㅇ
if(stack.Count == 0)
return false;
else
{
stack.Pop();
}
}
}
return stack.Count == 0;
}
}
처음엔 Queue로 풀었다가 작동도 안되고 이상해서 Stack으로 다시 풀었습니다.. Stack,Queue 없이 Count로도 가능은한데 Stack,Queue 문제라..ㅠ 공부의 필요성을 느낍니다.