787. Cheapest Flights Within K Stops

787. Cheapest Flights Within K Stops 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. 1 2 3 4 5 6 7 Example 1: Input: n = 3, edges = [[0,1,100],[1,2,100],[0,2,500]] src = 0, dst = 2, k = 1 Output: 200 Explanation: The graph looks like this: ...

March 24, 2021 · 3 min · volyx

105. Construct Binary Tree from Preorder and Inorder Traversal

105. Construct Binary Tree from Preorder and Inorder Traversal Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree. 1 2 3 4 Example 1: Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] Output: [3,9,20,null,null,15,7] ...

March 23, 2021 · 3 min · volyx

145. Binary Tree Postorder Traversal

145. Binary Tree Postorder Traversal Given the root of a binary tree, return the postorder traversal of its nodes’ values. 1 2 3 4 Example 1: Input: root = [1,null,2,3] Output: [3,2,1] 1 2 3 4 Example 2: Input: root = [] Output: [] 1 2 3 4 Example 3: Input: root = [1] Output: [1] 1 2 3 4 Example 4: Input: root = [1,2] Output: [2,1] ...

March 22, 2021 · 2 min · volyx

94. Binary Tree Inorder Traversal

94. Binary Tree Inorder Traversal Given the root of a binary tree, return the inorder traversal of its nodes’ values. 1 2 3 4 Example 1: Input: root = [1,null,2,3] Output: [1,3,2] 1 2 3 4 Example 2: Input: root = [] Output: [] 1 2 3 4 Example 3: Input: root = [1] Output: [1] 1 2 3 4 Example 4: Input: root = [1,2] Output: [2,1] ...

March 22, 2021 · 2 min · volyx

144. Binary Tree Preorder Traversal

144. Binary Tree Preorder Traversal Given the root of a binary tree, return the preorder traversal of its nodes’ values. 1 2 3 4 Example 1: Input: root = [1,null,2,3] Output: [1,2,3] 1 2 3 4 Example 2: Input: root = [] Output: [] ...

March 16, 2021 · 2 min · volyx

149. Max Points on a Line

149. Max Points on a Line Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line. 1 2 3 4 Example 1: Input: points = [[1,1],[2,2],[3,3]] Output: 3 1 2 3 4 Example 2: Input: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]] Output: 4 ...

March 16, 2021 · 2 min · volyx

108. Convert Sorted Array to Binary Search Tree

108. Convert Sorted Array to Binary Search Tree Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one. 1 2 3 4 5 Example 1: Input: nums = [-10,-3,0,5,9] Output: [0,-3,9,-10,null,5] Explanation: [0,-10,5,null,-3,null,9] is also accepted: ...

March 13, 2021 · 2 min · volyx

110. Balanced Binary Tree

110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the left and right subtrees of every node differ in height by no more than 1. 1 2 3 4 Example 1: Input: root = [3,9,20,null,null,15,7] Output: true ...

March 13, 2021 · 3 min · volyx

111. Minimum Depth of Binary Tree

111. Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. 1 2 3 4 Example 1: Input: root = [3,9,20,null,null,15,7] Output: 2 1 2 3 4 Example 2: Input: root = [2,null,3,null,4,null,5,null,6] Output: 5 Constraints: ...

March 12, 2021 · 3 min · volyx

100. Same Tree

![https://leetcode.com/problems/same-tree/] Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. 1 2 3 4 Example 1: Input: p = [1,2,3], q = [1,2,3] Output: true ...

March 11, 2021 · 2 min · volyx