코-딩

코-딩/프로그래머스

프로그래머스::모의고사

문제 : https://school.programmers.co.kr/learn/courses/30/lessons/42840?language=python3 난이도 : Lv.1 풀이 def solution(answers): answer = [] a = [1, 2, 3, 4, 5] b = [2, 1, 2, 3, 2, 4, 2, 5] c = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] cnt = {1: 0, 2: 0, 3: 0} for i in range(len(answers)): if a[i%5] == answers[i]: cnt[1] += 1 if b[i%8] == answers[i]: cnt[2] += 1 if c[i%10] == answers[i]: cnt[3] += 1 win = max(cn..

코-딩/Leetcode

[leetcode] 79. Word Search

문제 : 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..

코-딩/Leetcode

[leetcode] 79. Word Search

문제 : 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%..

힞뚜루마뚜루
'코-딩' 카테고리의 글 목록 (3 Page)