---
# System prepended metadata

title: L7-Nesting
tags: [Codility_lessons]

---

# L7-Nesting
###### tags: `Codility_lessons`
## Question
https://app.codility.com/programmers/lessons/7-stacks_and_queues/nesting/
## Key
類似前面Brackets那題，只是改成只有一種括號，一樣用queue/stack來檢查對稱
## Reference
## Solution
```cpp=
#include <stack>
int solution(string &S) {
    stack<char> front_bracket;
    for(int i=0; i<S.length(); i++)
    {
        if(S[i] == '(')
        {
            front_bracket.push(S[i]);
        }
       
        if(S[i]==')')
        {
            if(front_bracket.top() == '(')
                front_bracket.pop();
            else
                return 0;
        }
    }
    /* Check whether stack remain some brakets */
    if(front_bracket.size() == 0)
        return 1;
    else
        return 0;
}
```