原文链接: https://leetcode-cn.com/problems/course-schedule-iv 英文原文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 t…
标签详情
广度优先搜索 分类
原文链接: https://leetcode-cn.com/problems/pseudo-palindromic-paths-in-a-binary-tree 英文原文Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node valu…
原文链接: https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero 英文原文There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a …
原文链接: https://leetcode-cn.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label 英文原文Given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of th…
原文链接: https://leetcode-cn.com/problems/detect-cycles-in-2d-grid 英文原文Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid. A cycle is a path of length 4 or more in the grid …
原文链接: https://leetcode-cn.com/problems/minimum-number-of-days-to-disconnect-island 英文原文Given a 2D grid consisting of 1s (land) and 0s (water). An island is a maximal 4-directionally (horizontal or vertical) connected group of 1s. The grid is said to …
原文链接: https://leetcode-cn.com/problems/even-odd-tree 英文原文A binary tree is named Even-Odd if it meets the following conditions: The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, et…
原文链接: https://leetcode-cn.com/problems/lexicographically-smallest-string-after-applying-operations 英文原文You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b. You can apply either of the following two opera…
原文链接: https://leetcode-cn.com/problems/path-with-minimum-effort 英文原文You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are si…
原文链接: https://leetcode-cn.com/problems/minimum-jumps-to-reach-home 英文原文A certain bug's home is on the x-axis at position x. Help them get there from position 0. The bug jumps according to the following rules: It can jump exactly a positions forward (…
原文链接: https://leetcode-cn.com/problems/nearest-exit-from-entrance-in-maze 英文原文You are given an m x n matrix maze (0-indexed) with empty cells (represented as '.') and walls (represented as '+'). You are also given the entrance of the maze, where entr…
原文链接: https://leetcode-cn.com/problems/last-day-where-you-can-still-cross 英文原文There is a 1-based binary matrix where 0 represents land and 1 represents water. You are given integers row and col representing the number of rows and columns in the matri…
原文链接: https://leetcode-cn.com/problems/operations-on-tree 英文原文You are given a tree with n nodes numbered from 0 to n - 1 in the form of a parent array parent where parent[i] is the parent of the ith node. The root of the tree is node 0, so parent[0] …
原文链接: https://leetcode-cn.com/problems/find-if-path-exists-in-graph 英文原文There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, whe…
原文链接: https://leetcode-cn.com/problems/the-time-when-the-network-becomes-idle 英文原文There is a network of n servers, labeled from 0 to n - 1. You are given a 2D integer array edges, where edges[i] = [ui, vi] indicates there is a message channel between…
原文链接: https://leetcode-cn.com/problems/second-minimum-time-to-reach-destination 英文原文A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented…
原文链接: https://leetcode-cn.com/problems/minimum-operations-to-convert-number 英文原文You are given a 0-indexed integer array nums containing distinct numbers, an integer start, and an integer goal. There is an integer x that is initially set to start, and…
原文链接: https://leetcode-cn.com/problems/find-all-people-with-secret 英文原文You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] ind…
原文链接: https://leetcode-cn.com/problems/route-between-nodes-lcci 英文原文Given a directed graph, design an algorithm to find out whether there is a route between two nodes. Example1: Input: n = 3, graph = [[0, 1], [0, 2], [1, 2], [1, 2]], start = 0, targe…
原文链接: https://leetcode-cn.com/problems/list-of-depth-lcci 英文原文Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked lists). Return a array cont…
原文链接: https://leetcode-cn.com/problems/color-fill-lcci 英文原文Implement the "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fi…
原文链接: https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof 中文题目请完成一个函数,输入一个二叉树,该函数输出它的镜像。 例如输入: 4 / \ 2 7 / \ / \ 1 3 6 9 镜像输出: 4 / \ 7 2 / \ / \ 9 6 3 1 示例 1: 输入:root = [4,2,7,1,3,6,9] 输出:[4,7,2,9,6,3,1] 限制: 0 <= 节点个数 <= 1000 注意:本题与主站 226 …
原文链接: https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof 中文题目请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 1 / \ 2 2 \ \ 3 3 示例 1: 输入:root = [1…
原文链接: https://leetcode-cn.com/problems/xu-lie-hua-er-cha-shu-lcof 中文题目请实现两个函数,分别用来序列化和反序列化二叉树。 你需要设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。 提示:输入输出格式与 LeetCode 目前使用的方式一致,详情请参阅 LeetCode 序列化二叉树的格式。你并非必须采取这…
原文链接: https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof 中文题目从上到下打印出二叉树的每个节点,同一层的节点按照从左到右的顺序打印。 例如: 给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回: [3,9,20,15,7] 提示: 节点总数 <= 1000 通过代码 高赞题解解题思路: 题目要求的二叉树的 从上至下 打印(即按层打印)…
原文链接: https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof 中文题目从上到下按层打印二叉树,同一层的节点按从左到右的顺序打印,每一层打印到一行。 例如: 给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回其层次遍历结果: [ [3], [9,20], [15,7] ] 提示: 节点总数 <= 1000 注意:本题与主站 102 题相…
原文链接: https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof 中文题目输入一棵二叉树的根节点,求该树的深度。从根节点到叶节点依次经过的节点(含根、叶节点)形成树的一条路径,最长路径的长度为树的深度。 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回它的最大深度 3 。 提示: 节点总数 <= 10000 注意:本题与主站 104 题相同:https://leet…
原文链接: https://leetcode-cn.com/problems/pond-sizes-lcci 英文原文You have an integer matrix representing a plot of land, where the value at that loca­tion represents the height above sea level. A value of zero indicates water. A pond is a region of wat…
原文链接: https://leetcode-cn.com/problems/word-transformer-lcci 英文原文Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step…
原文链接: https://leetcode-cn.com/problems/baby-names-lcci 英文原文Each year, the government releases a list of the 10000 most common baby names and their frequencies (the number of babies with that name). The only problem with this is that some names have m…