๋ฌธ์ ํ๋ก๊ทธ๋๋จธ์ค ์์์ฐพ๊ธฐhttps://school.programmers.co.kr/learn/courses/30/lessons/42839 ํ๋ก๊ทธ๋๋จธ์ค์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์
๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์
๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.programmers.co.kr ์ฝ๋import itertoolsdef sosu(num): if num == 0 or num == 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return Truedef solution(n): answe..
ํญํด99
๋ฌธ์ ๋ฐฑ์ค ๋ด์ค ์ ํ๊ธฐ https://www.acmicpc.net/problem/1135 ์ฝ๋n = int(input())parent_list = list(map(int, input().split()))child_list = [list() for _ in range(n)]for child in range(1, n) : parent = parent_list[child] child_list[parent].append(child)def dfs(node) : if not child_list[node] : return 0 result = list() for child in child_list[node] : result.append(dfs(child)) result.sort( reverse =..
๋ฌธ์ ๋ฐฑ์ค 1927 ์ต์ ํ https://www.acmicpc.net/problem/1927๋ฐฑ์ค 11279 ์ต๋ ํ https://www.acmicpc.net/problem/11279 ์ต์ ํ ์ฒ์ ์ฝ๋ (์๊ฐ์ด๊ณผ)๋ฐฐ์ด์์ min()์ ์ด์ฉํ์ฌ ์ต์๊ฐ์ ์ฐพ์๋ค.n = int(input())x = []for _ in range(n): num = int(input()) if num == 0: if x: print(min(x)) x.remove(min(x)) else: print(0) else: x.append(num) ์ต์ ํ ์ฝ๋import sysimport heapqn = int(input()..
99ํด๋ฝ์ด๋?์ฝ๋ฉํ
์คํธ ํฉ๊ฒฉ๋ฅ ์ ๋์ด๊ธฐ ์ํด ํจ๊ป ์ฝ๋ฉํ
์คํธ ๋ฌธ์ ๋ฅผ ํธ๋ ํญํด99 ์ฃผ์ต ์คํฐ๋ ์ด๋ค. 99ํด๋ฝ ์งํ ๊ณผ์ ์์ ์ ์์ค์ ๋ฐ๋ผ ๋น๊ธฐ๋, ๋ฏธ๋ค๋ฌ, ์ฑ๋ฆฐ์ ๋ ๋ฒจ๋ก ๋๋๋ค. ๋๋ ํ์ด์ฌ ๋ฏธ๋ค๋ฌ๋ก ์ฐธ๊ฐํ์๋ค.๋น๊ธฐ๋๋ ๋ฐฑ์ค ๋ธ๋ก ์ฆ ๋๋ ํ๋ก๊ทธ๋๋จธ์ค 1๋ ๋ฒจ ์์ค์ด๋ค.๋ฏธ๋ค๋ฌ๋ ๋ฐฑ์ค ์ค๋ฒ ๋๋ ํ๋ก๊ทธ๋๋จธ์ค 2๋ ๋ฒจ ์์ค์ด๋ค.์ฑ๋ฆฐ์ ๋ ๋ฐฑ์ค ๊ณจ๋ ๋๋ ํ๋ก๊ทธ๋๋จธ์ค 3๋ ๋ฒจ ์์ค์ด๋ค.๋งค์ผ ์ค์ 11์์ ๋จํก๋ฐฉ ๋๋ ํ์ต๊ณต๊ฐ ์ฌ์ดํธ์ ์์ ์ด ์ ํ
ํ ๋ ๋ฒจ์ ๋ง๋ ๋ฌธ์ ๋ฅผ ํ๋์ฉ ๋ด์ฃผ์๋ค.๋ฌธ์ ๋ฅผ ํ๊ฑฐ๋ ๋ชปํ์ด๋ ํผ ์๋๊ฐ ์๋ ํ๋ฉด์ ์บก์ณํด์ ์ธ์ฆํ๋ฉด ๊ทธ๋ ์ ์ถ์์ฒดํฌ๋ ์๋ฃ๋ค.TIL์ ์ฌ๋ ค์ ๋งํฌ๋ฅผ ์ฌ๋ ค์ ์ธ์ฆํ๋ค.TIL์ ์ ํ์ด์ง๋ง ๋งค์ผ ๊พธ์คํ ์ฐ์์ผ๋ก ์ธ์ฆํ๋ฉด ๋ณด์์ด ์ฃผ์ด์ง๋ค.์/๋ชฉ์ ์ ๊ธฐ์คํฐ๋ ๋ ๋ก, ๊ฒ๋ํ์ด์ด๋ผ๋..
๋ฌธ์ ๋ฆฟ์ฝ๋ 1338. Reduce Array Size To The Halfhttps://leetcode.com/problems/reduce-array-size-to-the-half/description/ ์ฝ๋class Solution(object): def minSetSize(self, arr): answer = 0 count_num = {} for num in arr: if num not in count_num.keys(): count_num[num] = 1 else: count_num[num] += 1 values = sorted(list(..
๋ฌธ์ ๋ฆฟ์ฝ๋ 1845. Seat Reservation Managerhttps://leetcode.com/problems/seat-reservation-manager/ ์ฝ๋import heapqclass SeatManager: def __init__(self, n): self.can_reserve = list(range(1, n + 1)) heapq.heapify(self.can_reserve) def reserve(self): return heapq.heappop(self.can_reserve) def unreserve(self, seatNumber): heapq.heappush(self.can_reserve, seatNumber)..
๋ฌธ์ ๋ฆฟ์ฝ๋ 921. Minimum Add to Make Parentheses Valishttps://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ ์ฝ๋class Solution(object): def minAddToMakeValid(self, s): s = deque(s) stack = [] item = s.popleft() stack.append(item) while s: item = s.popleft() if not stack: stack.append(item) else: ..
๋ฌธ์ 2390. Removing Stars From a String https://leetcode.com/problems/removing-stars-from-a-string/ ์ฝ๋class Solution(object): def removeStars(self, s): s = list(s) while '*' in s: for i in range(len(s)-1): if s[i + 1] == '*': s.pop(i+1) s.pop(i) break return ''.join(s) ํ์ดs = list(s)๋งค๊ฐ๋ณ์๋ก ๋ฐ์ ๋ฌธ์..
๋ฌธ์ ๋ฆฟ์ฝ๋ 1823. Find the Winner of the Circular Gamehttps://leetcode.com/problems/find-the-winner-of-the-circular-game/solutions/ ์ฝ๋class Solution: def findTheWinner(self, n: int, k: int) -> int: circle = [i for i in range(1, n+1)] count = 1 turn = 0 while len(circle) != 1: if count == k: circle.pop(turn) count = 1 ..
๋ฌธ์ ๋ฐฑ์ค ๊ฑธ๊ทธ๋ฃน ๋ง์คํฐ ์ค์์ด https://www.acmicpc.net/problem/16165 ์ฝ๋n, m = map(int, input().split()) # ๊ฑธ๊ทธ๋ฃน์ ์, ๋งํ์ผ ํ ๋ฌธ์ ์ ์idol_dic = {}for _ in range(n): team_name = input() team_member_num = int(input()) team_member = [] for _ in range(team_member_num): team_member.append(input()) idol_dic[team_name] = team_memberfor _ in range(m): quiz = input() quiz_type = int(input()) ..
๋ฌธ์ ๋ฐฑ์ค ์์ด๋ฒ๋ฆฐ ๊ดํธ https://www.acmicpc.net/problem/1541 ์ฝ๋formular = list(input())formular.append('-')have_to_sum = []have_to_sub = []operand = ''for letter in formular: if letter != '+' and letter != '-': operand += letter elif letter == '+': have_to_sum.append(int(operand)) operand = '' elif letter == '-': have_to_sum.append(int(operand)) have_to_sub.appen..
๋ฌธ์ ๋ฐฑ์ค ์ ์ฐพ๊ธฐ https://www.acmicpc.net/problem/1920 ์ฝ๋n = int(input())arr = sorted(list(map(int, input().split())))m = int(input())targets = list(map(int, input().split()))for target in targets: answer = 0 # ์ด๋ถํ์ s = 0 e = n - 1 while s target: # ๋ค์ด? e = mid - 1 else: # ์
? s = mid + 1 print(answer) ํ์ดn = int(input())arr = sorted(list(map(int, input(..