코딩테스트


https://www.acmicpc.net/problem/1929 import mathdef solution(M, N): is_prime = [True] * (N+1) is_prime[0] = is_prime[1] = False for i in range(2, int(math.sqrt(N))+1): if is_prime[i]: for j in range(i*i, N+1, i): is_prime[i] = False for k in range(M, N+1): if (is_prime[k]==True): print(k) M, N = map(int, input().split())solution(..

https://leetcode.com/problems/first-unique-character-in-a-string?source=submission-ac SolutionStep 1. 주어진 String에서 하나씩 돌면서 char 확인하기Step 2. i번재 char이 이전에 나왔는지, 이후에 또 나오는지를 체크함Step 3. 반복되지 않을 경우, 바로 break하고 answer return Step 4. 다 확인했는데도 해당하는 경우 없으면 -1 반환 Codeclass Solution(object): def firstUniqChar(self, s): char_list = [] for i in range(len(s)): char = s[i] ..


https://www.acmicpc.net/problem/10798 def solution(arrays): anw_list = [] for i in range(15): for j in range(5): if i >= len(array[i]) continue ans_list.append(array[j][i]) answer = "".join(ans_list) print(answer) return answer # 입력 처리arrays = []for _ in range(5): arr = input() arrays.append(arr) solution(arrays)


# BFS 탐색def min_time_to_make_emoticons(S): # 현재 이모티콘 수, 클립보드의 이모티콘 수, 소요 시간을 저장 visited = set() queue = [(1, 0, 0)] visited.add((1, 0)) while queue: screen, clipboard, time = queue.pop(0) if screen == S: return time # 현재 화면의 이모티콘을 클립보드에 복사 if (screen, screen) not in visited: visited.add((screen, screen)) queue.append((screen, screen, time+1)) # 클립보드의 이모티콘을 화면에 붙이기 if clipboa..


from collections import Counterdef solution(X, Y): count_x = Counter(X) count_y = Counter(Y) common_digit = set(X) & set(Y) result = [] for digit in common_digit: min_count = min(count_x[digit], count_y[digit]) result.extend([digit] * min_count) result.sort(reverse=True) if len(result) == 0: return '-1' if result[0] == '0': return '..


def solution(n): answer = 0 num_list = [] for i in range(len(str(n))): num_list.append(n%10) n //= 10 sorted_num_list = sorted(num_list) for i in range(len(sorted_num_list)): answer += sorted_num_list[i] * (10**i) return answer