Algorithm/Programmers

[C#]프로그래머스 76502 괄호 회전하기 - Hide

zz0zz9 2024. 12. 13. 23:39
반응형
반응형

https://school.programmers.co.kr/learn/courses/30/lessons/76502

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

문제 요약

s가 올바른 괄호 문자열이 되게 하는 x의 개수를 반환하는 함수 만들기

 

 

 

풀이
using System;

public class Solution {
    public int solution(string s) {
        int answer = 0;
        
        for (int i = 0; i < s.Length; i++)
        {
            s = s.Substring(1) + s[0];
            string temp = s;
            while(temp.Contains("{}") || temp.Contains("[]") || temp.Contains("()"))
            {
                temp = temp.Replace("{}", string.Empty);
                temp = temp.Replace("[]", string.Empty);
                temp = temp.Replace("()", string.Empty);

            }
            if (temp.Length == 0) answer++;
        }
        
        return answer;
    }
}

하루종일 돌아다녔는데 붕어빵 못 구해서 약간 슬픈 하루...

반응형