문제 : https://leetcode.com/problems/word-search/ 난이도 : Medium 풀이 class Solution: def exist(self, board: List[List[str]], word: str) -> bool: if not word: return True m, n = len(board), len(board[0]) if len(word) > m * n: return False counter = Counter(word) for line in board: for c in line: if c in counter: counter[c] -= 1 for v in counter.values(): if v > 0: return False def DFS(r, c, w): if not..
문제 : https://school.programmers.co.kr/learn/courses/30/lessons/42862# 난이도 : Lv.1 풀이 def solution(n, lost, reserve): newReserve = [r for r in reserve if r not in lost] newLost = [l for l in lost if l not in reserve] for nr in newReserve: if nr - 1 in newLost: newLost.remove(nr - 1) elif nr + 1 in newLost: newLost.remove(nr + 1) answer = n - len(newLost) return answer 이미 카테고리에서 Greedy 알고리즘이라고 나와있다..
문제 : https://school.programmers.co.kr/learn/courses/30/lessons/92334 난이도 : Lv.1 풀이 from collections import defaultdict def solution(id_list, report, k): mailCnt = {} for id in id_list: mailCnt[id] = 0 reportedPerson = {} for rpt in report: s, t = rpt.split(" ") if t not in reportedPerson: reportedPerson[t] = [s] elif s not in reportedPerson[t]: reportedPerson[t].append(s) for rp in reportedPerso..
문제 : https://leetcode.com/problems/word-search/description/ 난이도 : Medium 풀이 class Solution: def exist(self, board: List[List[str]], word: str) -> bool: M, N = len(board), len(board[0]) def dfs(x, y, d): if x >= M or x = N or y < 0 or word[d] != board[x][y]: return False if d == len(word)-1: return True temp = board[x][y] board[x][y] = '0' # 방문여부 found = dfs(x,y-1,d+1) or dfs(x,y+1,d+1)..
문제 : https://school.programmers.co.kr/learn/courses/30/lessons/12943 난이도 : Lv.1 풀이 def solution(num): answer = 0 while True: if num == 1: return answer if answer == 500: return -1 if num % 2 == 0: num = num / 2 elif num % 2 == 1: num = num * 3 + 1 answer += 1 양심상... 설마 이렇게 단순한 풀이를 원했을까...하는 마음에 다른 풀이를 고민해봤다.. 다른 풀이 def solution(num): for i in range(501): if num == 1: return i num = num/2 if num%..