leetcode每日一题202008
Bryan要加油
这个作者很懒,什么都没留下…
展开
-
841. Keys and Rooms(Leetcode每日一题-2020.08.31)
ProblemThere are N rooms and you start in room 0. Each room has a distinct number in 0, 1, 2, …, N-1, and each room may have some keys to access the next room.Formally, each room i has a list of keys rooms[i], and each key rooms[i][j] is an integer in [原创 2020-08-31 22:45:49 · 119 阅读 · 0 评论 -
557. Reverse Words in a String III(Leetcode每日一题-2020.08.30)
ProblemGiven a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Note: In the string, each word is separated by single space and there will not be any extra space i原创 2020-08-30 08:07:16 · 324 阅读 · 0 评论 -
214. Shortest Palindrome(Leetcode每日一题-2020.08.29)
ProblemGiven a string s, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.Example1Input: “aacecaaa”Output: “aaacecaaa”Example2原创 2020-08-29 21:00:24 · 201 阅读 · 0 评论 -
657. Robot Return to Origin(Leetcode每日一题-2020.08.28)
ProblemThere is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.The move sequence is represented by a string, and the character moves[i] rep原创 2020-08-28 20:36:29 · 139 阅读 · 0 评论 -
332. Reconstruct Itinerary(Leetcode每日一题-2020.08.27)
ProblemGiven a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.Note:If there原创 2020-08-27 22:31:27 · 159 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number(Leetcode每日一题-2020.08.26)
ProblemGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters原创 2020-08-27 22:29:06 · 136 阅读 · 0 评论 -
491. Increasing Subsequences(Leetcode每日一题-2020.08.25)
ProblemGiven an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2.Constraints:The length of the given array will not exceed 15.Th原创 2020-08-25 21:51:17 · 106 阅读 · 0 评论 -
459. Repeated Substring Pattern(Leetcode每日一题-2020.08.24)
ProblemGiven a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 1原创 2020-08-24 21:58:47 · 186 阅读 · 0 评论 -
201. Bitwise AND of Numbers Range(Leetcode每日一题-2020.08.23)
ProblemGiven a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.Example1Input: [5,7]Output: 4Example2Input: [0,1]Output: 0Solutionclass Solution {public: int rangeBitwi原创 2020-08-23 20:47:57 · 176 阅读 · 0 评论 -
679. 24 Game (Leetcode每日一题-2020.08.22)
ProblemYou have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, ) to get the value of 24.Note:The division operator / represents real division, not integer division. For example, 4 / (1原创 2020-08-22 22:40:54 · 232 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree(Leetcode每日一题-2020.08.21)
ProblemGiven 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.ExampleSolution/** * Definition for a binar原创 2020-08-21 20:51:04 · 131 阅读 · 0 评论 -
529. Minesweeper(Leetcode每日一题-2020.08.20)
ProblemYou are given a 2D char matrix representing the game board. ‘M’ represents an unrevealed mine, ‘E’ represents an unrevealed empty square, ‘B’ represents a revealed blank square that has no adjacent (above, below, left, right, and all 4 diagonals) m原创 2020-08-20 21:56:07 · 261 阅读 · 0 评论 -
647. Palindromic Substrings(Leetcode每日一题-2020.08.19)
ProblemGiven a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters.Note:The input string lengt原创 2020-08-19 21:58:55 · 183 阅读 · 0 评论 -
109. Convert Sorted List to Binary Search Tree(Leetcode每日一题-2020.08.18)
ProblemGiven the head of a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every no原创 2020-08-18 21:44:47 · 196 阅读 · 0 评论 -
110. Balanced Binary Tree(Leetcode每日一题-2020.08.17)
ProblemGiven 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.Example1Example2Solutio原创 2020-08-17 22:11:32 · 158 阅读 · 0 评论 -
733. Flood Fill(Leetcode每日一题-2020.08.16)
ProblemAn image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor原创 2020-08-16 15:42:31 · 222 阅读 · 0 评论 -
546. Remove Boxes(Leetcode每日一题-2020.08.15)--抄答案
ProblemGiven several boxes with different colors represented by different positive numbers.You may experience several rounds to remove boxes until there is no box left. Each time you can choose some continuous boxes with the same color (composed of k box原创 2020-08-15 14:18:47 · 162 阅读 · 0 评论 -
20. Valid Parentheses(Leetcode每日一题-2020.08.14)
ProblemGiven a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brackets.Open brackets must be closed in the corr原创 2020-08-15 14:15:43 · 95 阅读 · 0 评论 -
43. Multiply Strings(Leetcode每日一题-2020.08.13)
ProblemGiven two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.Note:The length of both num1 and num2 is < 110.Both num1 and num2 contain only digits 0-9.Both num1 and原创 2020-08-13 21:53:23 · 146 阅读 · 0 评论 -
133. Clone Graph(Leetcode每日一题-2020.08.12)
ProblemGiven a reference of a node in a connected undirected graph.Return a deep copy (clone) of the graph.Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors.Test case format:For simplicity sake, each node’s value is原创 2020-08-12 20:56:50 · 185 阅读 · 0 评论 -
130. Surrounded Regions(Leetcode每日一题-2020.08.11)
ProblemGiven a 2D board containing ‘X’ and ‘O’ (the letter O), capture all regions surrounded by ‘X’.A region is captured by flipping all 'O’s into 'X’s in that surrounded region.ExampleSolution从边缘的O开始,进行DFS,找到所有相连的O。然后将所有没有跟边缘的O相连的O标记成X。class Solut原创 2020-08-11 21:34:56 · 181 阅读 · 1 评论 -
696. Count Binary Substrings(Leetcode每日一题-2020.08.10)--抄答案
ProblemGive a string s, count the number of non-empty (contiguous) substrings that have the same number of 0’s and 1’s, and all the 0’s and all the 1’s in these substrings are grouped consecutively.Substrings that occur multiple times are counted the num原创 2020-08-10 21:23:57 · 185 阅读 · 0 评论 -
93. Restore IP Addresses(Leetcode每日一题-2020.08.09)
ProblemGiven a string containing only digits, restore it by returning all possible valid IP address combinations.A valid IP address consists of exactly four integers (each integer is between 0 and 255) separated by single points.ExampleInput: “2552551原创 2020-08-09 09:52:16 · 274 阅读 · 0 评论 -
99. Recover Binary Search Tree(Leetcode每日一题-2020.08.08)--Morris遍历
ProblemTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Example1Example2SolutionMorris遍历从根节点开始遍历,直至当前节点为空为止:如果当前节点没有左儿子,则打印当前节点的值,然后进入右子树;如果当前节点有左儿子,则找当前节点的前驱。(1) 如果前驱节点的右儿子为空,说明原创 2020-08-08 12:27:18 · 175 阅读 · 0 评论 -
100. Same Tree(Leetcode每日一题-2020.08.07)
ProblemGiven two binary trees, 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.Example1Example2Example3Solution/** * Definition f原创 2020-08-08 12:23:43 · 126 阅读 · 0 评论 -
336. Palindrome Pairs(Leetcode每日一题-2020.08.06)--抄答案
ProblemGiven a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.Example1Input: [“abcd”,“dcba”,“lls”,“s”,“sssll”]Output: [[0,1],[1,0]原创 2020-08-06 21:28:49 · 249 阅读 · 0 评论 -
207. Course Schedule(Leetcode每日一题-2020.08.04)
ProblemThere are a total of numCourses courses you have to take, labeled from 0 to numCourses-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]Given the total number原创 2020-08-04 22:44:03 · 195 阅读 · 0 评论 -
415. Add Strings(Leetcode每日一题-2020.08.03)
ProblemGiven two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is < 5100.Both num1 and num2 contains only digits 0-9.Both num1 and num2 does not contain any leading原创 2020-08-04 22:32:35 · 200 阅读 · 0 评论 -
114. Flatten Binary Tree to Linked List(Leetcode每日一题-2020.08.02)
ProblemGiven a binary tree, flatten it to a linked list in-place.ExampleGiven the following tree:The flattened tree should look like:Solution/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; *原创 2020-08-02 09:36:45 · 158 阅读 · 0 评论 -
632. Smallest Range Covering Elements from K Lists(Leetcode每日一题-2020.08.01)-新的一个月,从抄答案开始
ProblemYou have k lists of sorted integers in ascending order. Find the smallest range that includes at least one number from each of the k lists.We define the range [a,b] is smaller than range [c,d] if b-a < d-c or a < c if b-a == d-c.Note:The原创 2020-08-02 09:11:48 · 306 阅读 · 0 评论