Home

[백준] 9012번 괄호 _ 문제 풀이

1. 문제 https://www.acmicpc.net/problem/9012 2. 풀이 2.1. 내 풀이 def solution(this): arr = [] for x in this: if x == '(': arr.append(x) else: if len(arr) == 0: return 'NO' else: arr.pop() return 'YES' if len(arr) == 0 else 'NO' total = int(input()) for...

Read more

[백준] 10773번 제로 _ 문제 풀이

1. 문제 https://www.acmicpc.net/problem/10773 3. 풀이 아래와 같이 배열을 사용하여 간단하게 해결할 수 있는 문제입니다. arr = [] total = int(input()) for _ in range(total): this = int(input()) if this == 0: arr.pop() else: arr.append(this) print(sum(arr))

Read more

[백준] 1003번 피보나치 함수 _ 문제 풀이

1. 문제 https://www.acmicpc.net/problem/1003 2. 풀이 2.1. 오답 풀이 처음에는 단순하게 재귀함수를 사용하여 문제를 해결하여 시간초과가 발생했다. d= [0, 0] def fibo(depth): if depth == 0 or depth == 1: d[depth] += 1 return fibo(depth-1) fibo(depth-2) test_n = int(input()) for i in range(test_n): d = [0, 0] fibo(int(input())) print('%d %d' % (d...

Read more

[프로그래머스] 이상한 문자 만들기 문제 풀이

1. 문제 https://programmers.co.kr/learn/courses/30/lessons/12930 2. 풀이 공백이 여러개 있는 것에 유의하여 문제를 해결하면 잘 해결됩니다. 공백을 하나로만 간주하여 시간이 꽤 소요되었습니다. def solution(s): answer = '' cnt = 0 for x in s: if x.isalpha(): answer += ( x.upper() if cnt % 2 == 0 else x.lower() ) cnt += 1 else: answ...

Read more