반응형
봤던 문제라 금방 풀었다!
using System;
using System.Collections.Generic;
public class Solution {
public bool solution(string s) {
bool answer = true;
int right = 0;
int left = 0;
foreach(char c in s)
{
if(c=='(') left++;
else
right++;
if(left < right)
{
answer = false;
return answer;
}
}
if(left != right)
{
answer = false;
return answer;
}
return answer;
}
}
백준에 비슷한 문제가 있었다.
백준 C# - 9012
백준 C# - 9012
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { int num = int.Parse(Console.ReadLine()); for (int i = 0; i < num; i++) { string answer = "YES"; string
code-piggy.tistory.com
반응형
'코딩테스트 준비 > 프로그래머스' 카테고리의 다른 글
프로그래머스 C# - 피보나치 수 (0) | 2024.02.19 |
---|---|
프로그래머스 C# - 다음 큰 숫자 (1) | 2023.12.15 |
프로그래머스 C# - 이진 변환 반복하기 (0) | 2023.09.12 |
프로그래머스 C# - 최솟값 만들기 (0) | 2023.09.06 |
프로그래머스 C# - JadenCase 문자열 만들기 (0) | 2023.09.05 |
댓글