๋ฌธ์ ๋ฆฟ์ฝ๋ 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(..
๋ฌธ์ ๋ฐฑ์ค ๊ทธ๋ฆผ https://www.acmicpc.net/problem/1926 ์ฝ๋from collections import dequen, m = map(int, input().split()) # ์ธ๋ก, ๊ฐ๋กpaper = [list(map(int, input().split())) for _ in range(n)]visit = [[False for _ in range(m)] for _ in range(n)] # ๋ฐฉ๋ฌธ ๊ธฐ๋ก์ฉmaxi = 0picture_count = 0for i in range(n): # ์ธ๋ก์ขํ for j in range(m): # ๊ฐ๋ก์ขํ if paper[i][j] == 1 and visit[i][j] == False: # ๊ทธ๋ฆผ์ด๊ณ , ๋ฐฉ๋ฌธํ์ ์๋ค๋ฉด ..
๋ฌธ์ ๋ฐฑ์ค ์ํธ ๋ง๋ค๊ธฐ https://www.acmicpc.net/problem/1759 ์ฝ๋l, c = map(int, input().split()) # ์ํธ๊ธธ์ด, ํ๋ณด ๋ฌธ์ ๊ฐ์letters = sorted(list(map(str, input().split()))) # ํ๋ณด ๋ฌธ์arr = []# ๋ชจ์ ์ธ๋ ํจ์def count_vowel(lst): return lst.count('a') + lst.count('e') + lst.count('i') + lst.count('o') + lst.count('u')def recur(idx): if len(arr) == l: # ๋ชจ์ ํ๊ฐ์ด์, ์์ ๋๊ฐ ์ด์์ด๋ฉด if count_vowel(arr) >= 1 and l - c..
๋ฌธ์ ๋ฐฑ์ค ๋ฆฌ๋ชจ์ปจ https://www.acmicpc.net/problem/1107 ์ฝ๋target = int(input())m = int(input())if m != 0: broken = list(map(int, input().split()))else: broken = []count = abs(100 - target)for num in range(1000000 + 1): for n in str(num): if int(n) in broken: break else: count = min(count, len(str(num)) + abs(num - target))print(count) ํ์ดtarget = int(input())m = int(inp..
๋ฌธ์ ๋ฐฑ์ค ๊ฐ์ํ๋ ์ https://www.acmicpc.net/problem/1038 ์ฝ๋n = int(input())if n > 1022: print(-1)else: num = [] ans = [] def check(i): global num if len(num) == 1: return True if num[-2] > i: return True def dfs(depth): global num for i in range(10): num.append(i) if check(i): dfs(depth + 1) ..
๋ฌธ์ ๋ฐฑ์ค ์ซ์์นด๋ 2https://www.acmicpc.net/problem/10816 ์ฝ๋N = int(input())cards = sorted(list(map(int, input().split())))M = int(input())want_card = (list(map(int, input().split())))count = {}for card in cards: if card in count: count[card] += 1 else: count[card] = 1def binarySearch(arr, target, start, end): if start > end: return 0 mid = (start + end) // 2 if arr[m..