https://programmers.co.kr/learn/courses/30/lessons/76502
코딩테스트 연습 - 괄호 회전하기
programmers.co.kr
[난이도] level2
[유형] 스택
[풀이]
전형적인 스택 문제입니다.
#include <string> #include <vector> #include <list> #include <stack> using namespace std; list<char> li; bool check(){ stack<char> st; for(auto c : li){ if(c=='['||c=='{'||c=='(') st.push(c); else { if(st.empty()) return 0; if(c==']'){ if(st.top()!='[') return 0; } if(c=='}'){ if(st.top()!='{') return 0; } if(c==')'){ if(st.top()!='(') return 0; } st.pop(); } } return st.empty(); } int solution(string s) { int ans=0; for(char c : s) li.push_back(c); for(int i=0;i<s.size();i++){ ans+=check(); li.push_back(li.front()); li.pop_front(); } return ans; }
https://github.com/has2/Problem-Solving/blob/master/programmers/level2/괄호 회전하기.cpp
'Problem-Solving > Programmers' 카테고리의 다른 글
[프로그래머스][level2] 2개 이하로 다른 비트 (C++) (0) | 2021.08.06 |
---|---|
[프로그래머스][level2] 삼각 달팽이 (C++) (0) | 2021.08.06 |
[프로그래머스][level2] 후보키 (C++) (0) | 2021.08.06 |
[프로그래머스][level2] 순위 검색 (C++) (0) | 2021.08.06 |
[프로그래머스][level2] 메뉴 리뉴얼 (C++) (0) | 2021.08.06 |