#include<string>
#include <iostream>
using namespace std;
bool solution(string s)
{
bool answer = true;
int openCnt = 0;
int closeCnt = 0;
// 예외 처리
if(s[0] == ')')
{
cout << "예외 1" << endl;
return false;
}
for(int i=0; i<s.size(); i++)
{
if(s[s.size()-1] == '(')
{
cout << "예외 2" << endl;
return false;
}
// ) 로 시작
if(s[i] == ')')
{
closeCnt++;
}
// ( 로 시작
else if(s[i] == '(')
{
openCnt++;
}
if(closeCnt > openCnt)
{
cout << "예외 3" << endl;
return false;
}
}
cout << "closeCnt = " << closeCnt << endl;
cout << "openCnt = " << openCnt << endl;
if(closeCnt == openCnt)
return true;
else
return false;
}
'코딩 테스트 > 프로그래머스 코딩테스트' 카테고리의 다른 글
JadenCase 문자열 만들기 (0) | 2022.10.04 |
---|---|
최솟값 만들기 (0) | 2022.10.03 |
신규 아이디 추천 - 미해결... (0) | 2022.10.03 |
행렬의 곱셈 (0) | 2022.09.29 |
성격 유형 검사하기 (0) | 2022.09.25 |