전체 글92 [python] 섬 연결하기 문제 출처 섬 연결하기 풀이 def solution(n, costs): answer = 0 costs.sort(key=lambda x: x[2]) visited = [0] * n visited[0] = 1 while sum(visited) != n: for cost in costs: s, e, c = cost if visited[s] or visited[e]: if visited[s] and visited[e]: continue else: visited[s] = 1 visited[e] = 1 answer += c break return answer 2019. 10. 14. [python] 단속카메라 문제 출처 단속카메라 풀이 def solution(routes): answer = [] routes.sort(key=lambda x: (x[0], x[1])) _, move_out = routes[0] for i in range(1, len(routes)): if routes[i][0] > move_out: answer.append(i) _, move_out = routes[i] else: move_out = min(routes[i][1], move_out) if answer[-1] != len(routes): return len(answer)+1 return len(answer) 2019. 10. 14. [python] 등굣길 문제 출처 등굣길 풀이 def solution(m, n, puddles): arr = [[0]*(m) for _ in range(n)] arr[0][0] = 1 for x, y in puddles: arr[y-1][x-1] = -1 for y in range(n): for x in range(m): if arr[y][x] == -1: continue else: if y > 0 and arr[y-1][x] != -1: arr[y][x] += arr[y-1][x] if x > 0 and arr[y][x-1] != -1: arr[y][x] += arr[y][x-1] return arr[n-1][m-1] % 1000000007 2019. 10. 14. [python] 이중우선순위큐 문제 출처 이중우선순위큐 풀이 def solution(operations): answer = [] for op in operations: cmd, num = op.split() if cmd == 'I': answer.append(int(num)) else: if not answer: continue if num == '1': answer.pop(answer.index(max(answer))) else: answer.pop(answer.index(min(answer))) if answer: return [max(answer), min(answer)] else: return [0, 0] 2019. 10. 14. 이전 1 2 3 4 5 6 7 ··· 23 다음