[Python] 카카오 2019 채용 - 후보키
https://programmers.co.kr/learn/courses/30/lessons/42890?language=python3 코딩테스트 연습 - 후보키 [["100","ryan","music","2"],["200","apeach","math","2"],["300","tube","computer","3"],["400","con","computer","4"],["500","muzi","music","3"],["600","apeach","music","2"]] 2 programmers.co.kr 풀이 노가다로 풀었다... from itertools import combinations def make_key(relation, colList): alist = [] for i in range(len(rela..
2020. 8. 18.
[Python] 카카오 2019 인턴쉽 - 인형 뽑기 게임
1. 내 풀이 def solution(board, moves): answer = 0 basket = [] for x in moves: x = x-1 for y in range(len(board)) : if(board[y][x] == 0): continue else: if(len(basket) > 0 and basket[-1] == board[y][x]): del basket[-1] answer += 2 else: basket.append(board[y][x]) board[y][x] = 0 break return answer if __name__ == "__main__": board = [[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] moves..
2020. 8. 16.
[Python] 카카오 2020 인턴쉽 - 경주로 건설 (BFS)
from collections import deque def solution(board): ans = float('inf') n = len(board) dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] # (nx, ny, d) : cost visit = {(0,0,0):0, (0,0,1):0, (0,0,2) : 0, (0,0,3):0} que = deque() #초기값. x, y, dir = -1 , cost que.append((0,0,-1,0)) #BFS while que: x, y, dir, cost = que.popleft() for d in range(4): nx = x + dx[d] ny = y + dy[d] #이동 가능하면 (범위내이고 board[nx][ny]가 0이면) i..
2020. 8. 16.