原文链接: https://leetcode-cn.com/problems/minimum-height-trees 英文原文A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. Given a tree of n nodes la…
标签详情
深度优先搜索 分类
原文链接: https://leetcode-cn.com/problems/longest-increasing-path-in-a-matrix 英文原文Given an m x n integers matrix, return the length of the longest increasing path in matrix. From each cell, you can either move in four directions: left, right, up, or dow…
原文链接: https://leetcode-cn.com/problems/reconstruct-itinerary 英文原文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.…
原文链接: https://leetcode-cn.com/problems/house-robber-iii 英文原文The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root. Besides the root, each house has one and only one parent house. After a …
原文链接: https://leetcode-cn.com/problems/flatten-nested-list-iterator 英文原文You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatt…
原文链接: https://leetcode-cn.com/problems/water-and-jug-problem 英文原文You are given two jugs with capacities jug1Capacity and jug2Capacity liters. There is an infinite amount of water supply available. Determine whether it is possible to measure exactly t…
原文链接: https://leetcode-cn.com/problems/mini-parser 英文原文Given a string s represents the serialization of a nested list, implement a parser to deserialize it and return the deserialized NestedInteger. Each element is either an integer or a list whose e…
原文链接: https://leetcode-cn.com/problems/lexicographical-numbers 英文原文Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order. You must write an algorithm that runs in O(n) time and uses O(1) extra space. Example 1…
原文链接: https://leetcode-cn.com/problems/longest-absolute-file-path 英文原文Suppose we have a file system that stores both files and directories. An example of one system is represented in the following picture: Here, we have dir as the only directory in t…
原文链接: https://leetcode-cn.com/problems/evaluate-division 英文原文You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi…
原文链接: https://leetcode-cn.com/problems/sum-of-left-leaves 英文原文Given the root of a binary tree, return the sum of all left leaves. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 24 Explanation: There are two left leaves in the binary tree, w…
原文链接: https://leetcode-cn.com/problems/pacific-atlantic-water-flow 英文原文There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touc…
原文链接: https://leetcode-cn.com/problems/battleships-in-a-board 英文原文Given an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board. Battleships can only be placed horizontally or vertically o…
原文链接: https://leetcode-cn.com/problems/path-sum-iii 英文原文Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum. The path does not need to start or end at the ro…
原文链接: https://leetcode-cn.com/problems/serialize-and-deserialize-bst 英文原文Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection li…
原文链接: https://leetcode-cn.com/problems/concatenated-words 英文原文Given an array of strings words (without duplicates), return all the concatenated words in the given list of words. A concatenated word is defined as a string that is comprised entirely of…
原文链接: https://leetcode-cn.com/problems/find-mode-in-binary-search-tree 英文原文Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it. If the tree has more than one mode, re…
原文链接: https://leetcode-cn.com/problems/most-frequent-subtree-sum 英文原文Given the root of a binary tree, return the most frequent subtree sum. If there is a tie, return all the values with the highest frequency in any order. The subtree sum of a node is…
原文链接: https://leetcode-cn.com/problems/find-bottom-left-tree-value 英文原文Given the root of a binary tree, return the leftmost value in the last row of the tree. Example 1: Input: root = [2,1,3] Output: 1 Example 2: Input: root = [1,2,3,4,null,5,6,null,…
原文链接: https://leetcode-cn.com/problems/freedom-trail 英文原文In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring" and use the dial to spell a specific keyword to open the door. Gi…
原文链接: https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row 英文原文Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed). Example 1: Input: root = [1,3,2,5,3,null,9] Output: [1,3,9] Exam…
原文链接: https://leetcode-cn.com/problems/minesweeper 英文原文Let's play the minesweeper game (Wikipedia, online game)! You are given an m x n char matrix board representing the game board where: 'M' represents an unrevealed mine, 'E' represents an unreveal…
原文链接: https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst 英文原文Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree. Example 1: Input: root = [4,…
原文链接: https://leetcode-cn.com/problems/convert-bst-to-greater-tree 英文原文Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater …
原文链接: https://leetcode-cn.com/problems/diameter-of-binary-tree 英文原文Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This p…
原文链接: https://leetcode-cn.com/problems/number-of-provinces 英文原文There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected ind…
原文链接: https://leetcode-cn.com/problems/binary-tree-tilt 英文原文Given the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right su…
原文链接: https://leetcode-cn.com/problems/array-nesting 英文原文You are given an integer array nums of length n where nums is a permutation of the numbers in the range [0, n - 1]. You should build a set s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], .…
原文链接: https://leetcode-cn.com/problems/subtree-of-another-tree 英文原文Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise. A subtree of a …
原文链接: https://leetcode-cn.com/problems/construct-string-from-binary-tree 英文原文Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it. Omit all the em…