본문 바로가기

leet code41

[LEET CODE] 104. Maximum Depth of Binary Tree # Problem Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Constraints: The number of nodes in the tree is in the range [0, 104]. -100 int: if root is None: return 0 queue = collections.deque([root]) depth = 0 while queue: depth += 1 # 큐 연산 추출 노드의 자식 노드 삽입 for .. 2021. 4. 15.
[LEET CODE] 787. Cheapest Flights Within K Stops ( 다익스트라 알고리즘 ) # Problem There are n cities connected by m flights. Each flight starts from city u and arrives at v with a price w. Now given all the cities and flights, together with starting city src and the destination dst, your task is to find the cheapest price from src to dst with up to k stops. If there is no such route, output -1. Constraints: The number of nodes n will be in range [1, 100], with nodes.. 2021. 4. 14.
[LEET CODE] 743. Network Delay Time ( 다익스트라 알고리즘) # Problem You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal to travel from source to target. We will send a signal from a given node k. Return the time it takes for all the n nodes to receive the signal. If.. 2021. 4. 14.
❗️[LEET CODE] 207. Course Schedule # Problem There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai. For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1. Return true if you can finish all courses. Otherwise, .. 2021. 4. 10.
❗️[LEET CODE] 332. Reconstruct Itinerary # Problem You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it. All of the tickets belong to a man who departs from "JFK", thus, the itinerary must begin with "JFK". If there are multiple valid itineraries, you should return the itinerary that has the smallest lexic.. 2021. 4. 10.
[LEET CODE] 78. Subsets # Problem Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. Constraints: 1 2021. 4. 9.
반응형