原文链接: https://leetcode-cn.com/problems/as-far-from-land-as-possible 英文原文Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized…
标签详情
广度优先搜索 分类
原文链接: https://leetcode-cn.com/problems/flower-planting-with-no-adjacent 英文原文You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want …
原文链接: https://leetcode-cn.com/problems/brace-expansion-ii 中文题目如果你熟悉 Shell 编程,那么一定了解过花括号展开,它可以用来生成任意字符串。 花括号展开的表达式可以看作一个由 花括号、逗号 和 小写英文字母 组成的字符串,定义下面几条语法规则: 如果只给出单一的元素 x,那么表达式表示的字符串就只有 "x"。R(x) = {x} <ul> <li>例如,表达式 <code>"a"</code> 表示字符串 <c…
原文链接: https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves 英文原文Given the root of a binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only if it has no ch…
原文链接: https://leetcode-cn.com/problems/shortest-path-with-alternating-colors 英文原文Consider a directed graph, with nodes labelled 0, 1, ..., n-1. In this graph, each edge is either red or blue, and there could be self-edges or parallel edges. Each [i, …
原文链接: https://leetcode-cn.com/problems/sum-of-nodes-with-even-valued-grandparent 英文原文Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0. …
原文链接: https://leetcode-cn.com/problems/deepest-leaves-sum 英文原文Given the root of a binary tree, return the sum of values of its deepest leaves. Example 1: Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8] Output: 15 Example 2: Input: root = [6,…
原文链接: https://leetcode-cn.com/problems/validate-binary-tree-nodes 英文原文You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one …
原文链接: https://leetcode-cn.com/problems/kth-ancestor-of-a-tree-node 英文原文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 ith node. The root of the tree is node 0. Find the…
原文链接: https://leetcode-cn.com/problems/smallest-string-with-swaps 英文原文You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. You can swap the characters at …
原文链接: https://leetcode-cn.com/problems/sort-items-by-groups-respecting-dependencies 英文原文There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belong…
原文链接: https://leetcode-cn.com/problems/minimum-moves-to-reach-target-with-rotations 英文原文In an n*n grid, there is a snake that spans 2 cells and starts moving from the top left corner at (0, 0) and (0, 1). The grid has empty cells represented by zeros…
原文链接: https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree 英文原文Given a binary tree with the following rules: root.val == 0 If treeNode.val == x and treeNode.left != null, then treeNode.left.val == 2 * x + 1 If treeNode.val == …
原文链接: https://leetcode-cn.com/problems/minimum-moves-to-move-a-box-to-their-target-location 英文原文A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations. The game is represented by an m x n…
原文链接: https://leetcode-cn.com/problems/count-servers-that-communicate 英文原文You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two serv…
原文链接: https://leetcode-cn.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix 英文原文Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is chang…
原文链接: https://leetcode-cn.com/problems/shortest-path-in-a-grid-with-obstacles-elimination 英文原文You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty c…
原文链接: https://leetcode-cn.com/problems/maximum-candies-you-can-get-from-boxes 英文原文Given n boxes, each box is given in the format [status, candies, keys, containedBoxes] where: status[i]: an integer which is 1 if box[i] is open and 0 if box[i] is clos…
原文链接: https://leetcode-cn.com/problems/jump-game-iii 英文原文Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you can reach …
原文链接: https://leetcode-cn.com/problems/get-watched-videos-by-your-friends 英文原文There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of wat…
原文链接: https://leetcode-cn.com/problems/number-of-operations-to-make-network-connected 英文原文There are n computers numbered from 0 to n-1 connected by ethernet cables connections forming a network where connections[i] = [a, b] represents a connection be…
原文链接: https://leetcode-cn.com/problems/jump-game-iv 英文原文Given an array of integers arr, you are initially positioned at the first index of the array. In one step you can jump from index i to index: i + 1 where: i + 1 < arr.length. i - 1 where: i - 1 …
原文链接: https://leetcode-cn.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid 英文原文Given a m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j…
原文链接: https://leetcode-cn.com/problems/linked-list-in-binary-tree 英文原文Given a binary tree root and a linked list with head as the first node. Return True if all the elements in the linked list starting from the head correspond to some downward path c…
原文链接: https://leetcode-cn.com/problems/time-needed-to-inform-all-employees 英文原文A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID. Each employee has one direct manager given in…
原文链接: https://leetcode-cn.com/problems/frog-position-after-t-seconds 英文原文Given an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its current vertex to another unv…
原文链接: https://leetcode-cn.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree 英文原文Given two binary trees original and cloned and given a reference to a node target in the original tree. The cloned tree is a copy of the ori…
原文链接: https://leetcode-cn.com/problems/check-if-there-is-a-valid-path-in-a-grid 英文原文Given a m x n grid. Each cell of the grid represents a street. The street of grid[i][j] can be: 1 which means a street connecting the left cell and the right cell. 2 …
原文链接: https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree 英文原文Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of good nodes in t…
原文链接: https://leetcode-cn.com/problems/minimum-time-to-collect-all-apples-in-a-tree 英文原文Given an undirected tree consisting of n vertices numbered from 0 to n-1, which has some apples in their vertices. You spend 1 second to walk over one edge of the…