문제: app.codility.com/programmers/lessons/7-stacks_and_queues/nesting/
List<char> listS = new List<char>(S);
Stack<char> stackS = new Stack<char>();
for (int i = 0; i < listS.Count; i++)
{
if (listS[i].Equals('('))
stackS.Push(listS[i]);
else
{
if (stackS.Count > 0)
{
if (stackS.Peek().Equals('('))
stackS.Pop();
}
else
return 0;
}
}
return stackS.Count == 0 ? 1 : 0;
'공부하자 > Codility' 카테고리의 다른 글
[Codility] Lesson8. Dominator (C#) (0) | 2020.11.20 |
---|---|
[Codility] Lesson7. StoneWall (C#) (0) | 2020.11.20 |
[Codility] Lesson7. Fish (C#) (0) | 2020.11.20 |
[Codility] Lesson7. Brackets (C#) (0) | 2020.11.20 |
[Codility] Lesson6. Triangle (C#) (0) | 2020.11.20 |