搜索
涛涛酱
北邮研究僧在读
展开
-
【LeetCode 994】 Rotting Oranges
题目描述In a given grid, each cell can have one of three values:the value 0 representing an empty cell;the value 1 representing a fresh orange;the value 2 representing a rotten orange.Every minute, any fresh orange that is adjacent (4-directionally) to a原创 2020-06-08 23:35:42 · 124 阅读 · 0 评论 -
【LeetCode 542】 01 Matrix
题目描述Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1:Input:[[0,0,0], [0,1,0], [0,0,0]]Output:[[0,0,0], [0,1,0], [0,0,0]]Example 2:Input:[[0,0,0], [0原创 2020-06-08 22:41:38 · 127 阅读 · 0 评论 -
【LeetCode 784】 Letter Case Permutation
题目描述Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create.Examples:Input: S = "a1b2"Output: ["a1b2", "a1B2", "A1b2", "A1B2"]Input: S原创 2020-06-04 23:16:10 · 121 阅读 · 0 评论 -
【LeetCode 114】 Flatten Binary Tree to Linked List
题目描述Given a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 4 6The flattened tree should look like:1 \ 2 \ 3 \ 4 \ 5 \原创 2020-05-22 22:08:51 · 126 阅读 · 0 评论 -
【LeetCode 236】 Lowest Common Ancestor of a Binary Tree
题目描述Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q原创 2020-05-21 23:41:24 · 109 阅读 · 0 评论 -
【LeetCode 51】 N-Queens
题目描述The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each solution contains a distinct board configuration of t原创 2020-05-20 16:45:25 · 103 阅读 · 0 评论 -
【LeetCode 40】 Combination Sum II
题目描述Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidates may only be used once in the combination.Note:All num原创 2020-05-20 13:40:30 · 81 阅读 · 0 评论 -
【LeetCode 473】 Matchsticks to Square
题目描述Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You should not break any stick, but you can link them up, an原创 2020-05-19 23:26:32 · 131 阅读 · 0 评论 -
【LeetCode 90】 Subsets II
题目描述Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: [1,2,2]Output:[ [2], [1], [1,2,2], [2,2], [1,2],原创 2020-05-19 20:38:33 · 77 阅读 · 0 评论 -
【LeetCode 78】 Subsets
题目描述Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]原创 2020-05-19 17:15:58 · 93 阅读 · 0 评论 -
【LeetCode 698】Partition to K Equal Sum Subsets
题目描述Given an array of integers nums and a positive integer k, find whether it’s possible to divide this array into k non-empty subsets whose sums are all equal.Example 1:Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4Output: TrueExplanation: It's possible原创 2020-05-11 23:27:38 · 96 阅读 · 0 评论 -
【LeetCode 329】Longest Increasing Path in a Matrix
题目描述Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outsi...原创 2020-05-06 22:34:23 · 102 阅读 · 0 评论 -
【面试题 & LeetCode 22】Generate Parentheses
题目描述Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(()...原创 2020-04-22 12:11:30 · 108 阅读 · 0 评论 -
【LeetCode 1298】 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 closed.candies[i]: an integer ...原创 2020-03-20 08:49:31 · 225 阅读 · 0 评论 -
【LeetCode 1263】 Minimum Moves to Move a Box to Their Target Location
题目描述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 a grid of size m x n, where each element is a wall,...原创 2020-03-19 23:35:49 · 394 阅读 · 0 评论 -
【LeetCode 1368】 Minimum Cost to Make at Least One Valid Path in a Grid
题目描述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 closed.candies[i]: an integer ...原创 2020-03-19 15:33:05 · 162 阅读 · 0 评论 -
【LeetCode 842】 Split Array into Fibonacci Sequence
题目描述Given a string S of digits, such as S = “123456579”, we can split it into a Fibonacci-like sequence [123, 456, 579].Formally, a Fibonacci-like sequence is a list F of non-negative integers such ...原创 2020-03-19 10:06:37 · 123 阅读 · 0 评论 -
【LeetCode 1240】 Tiling a Rectangle with the Fewest Squares
题目描述Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.Example 1:Input: n = 2, m = 3Output: 3Explanation: 3 squares are necessary to cover t...原创 2020-03-19 00:03:00 · 285 阅读 · 0 评论 -
【LeetCode 1239】 Maximum Length of a Concatenated String with Unique Characters
题目描述Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.Return the maximum possible length of s.Example 1:Input: arr = ["un","iq","ue"]...原创 2020-03-18 19:16:51 · 222 阅读 · 0 评论 -
【LeetCode 967】 Numbers With Same Consecutive Differences
题目描述Return all non-negative integers of length N such that the absolute difference between every two consecutive digits is K.Note that every number in the answer must not have leading zeros except f...原创 2020-03-18 14:19:00 · 129 阅读 · 0 评论 -
【LeetCode 212】 Word Search II
题目描述Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those h...原创 2020-03-18 13:36:55 · 77 阅读 · 0 评论 -
【LeetCode 96】Unique Binary Search Trees
题意:求某长度的二叉搜索树的结构数。思路:以 i 为顶点时,结构数等于左子树长度为 i-1,右子树长度为 n-i 分别得到的结构数乘积。代码:递归超时:class Solution {public: int dfs(int n) { if (n == 1 || n == 0) return 1; int ans = 0; for...原创 2019-06-03 10:01:13 · 74 阅读 · 0 评论 -
【LeetCode 803】Bricks Falling When Hit
题目描述We have a grid of 1s and 0s; the 1s in a cell represent bricks. A brick will not drop if and only if it is directly connected to the top of the grid, or at least one of its (4-way) adjacent bric...原创 2020-03-16 22:48:46 · 99 阅读 · 0 评论 -
【LeetCode 815】 Bus Routes
题目描述We have a list of bus routes. Each routes[i] is a bus route that the i-th bus repeats forever. For example if routes[0] = [1, 5, 7], this means that the first bus (0-th indexed) travels in the se...原创 2020-03-16 11:01:16 · 143 阅读 · 0 评论 -
【LeetCode 773】 Sliding Puzzle
题目描述On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square represented by 0.A move consists of choosing 0 and a 4-directionally adjacent number and swapping i...原创 2020-03-15 21:54:40 · 92 阅读 · 0 评论 -
【LeetCode752】 Open the Lock
题目描述You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’. The wheels can rotate freely and wrap around: for example we can...原创 2020-03-14 16:11:21 · 121 阅读 · 0 评论 -
【LeetCode 301】Remove Invalid Parentheses
题目描述Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses ( and ...原创 2020-03-14 10:44:06 · 136 阅读 · 0 评论 -
【LeetCode 733】 Flood Fill
题目描述An 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 ...原创 2020-03-13 19:54:19 · 81 阅读 · 0 评论 -
【LeetCode 216】 Combination Sum III
题目描述Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Note:All numbers wi...原创 2020-03-13 18:57:16 · 81 阅读 · 0 评论 -
【LeetCode 37】 Sudoku Solver
题目描述Write a program to solve a Sudoku puzzle by filling the empty cells.A sudoku solution must satisfy all of the following rules:Each of the digits 1-9 must occur exactly once in each row.Each of...原创 2020-03-13 14:49:43 · 111 阅读 · 0 评论 -
【LeetCode 40】 Combination Sum II
题目描述Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidates...原创 2020-03-12 22:56:00 · 62 阅读 · 0 评论 -
【LeetCode 488】 Zuma Game
题目描述Think about Zuma Game. You have a row of balls on the table, colored red®, yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand.Each time, you may choose a ball i...原创 2020-03-12 21:07:54 · 124 阅读 · 0 评论 -
【LeetCode 126】 Word Ladder II
题目描述Given two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a time...原创 2020-03-11 22:35:58 · 106 阅读 · 0 评论 -
【LeetCode 547】Friend Circles
题目描述There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, ...原创 2020-03-10 20:34:07 · 95 阅读 · 0 评论 -
【LeetCode 675】 Cut Off Trees for Golf Event
题目描述You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-negative 2D map, in this map:0 represents the obstacle can’t be reached.1 represents the ground c...原创 2020-03-10 20:02:18 · 234 阅读 · 0 评论 -
【LeetCode 51】 N-Queens
题目描述The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.E...原创 2020-03-10 14:59:06 · 72 阅读 · 0 评论 -
【LeetCode 1140】 Stone Game II
题目描述Alex and Lee continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game ...原创 2020-03-07 23:13:05 · 98 阅读 · 0 评论 -
【LeetCode 417】 Pacific Atlantic Water Flow
题目描述Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the “Pacific ocean” touches the left and top edges of the matrix and the “Atlantic ocean” ...原创 2020-03-06 13:18:05 · 117 阅读 · 1 评论 -
【LeetCode 980】 Unique Paths III
题目描述On a 2-dimensional grid, there are 4 types of squares:1 represents the starting square. There is exactly one starting square.2 represents the ending square. There is exactly one ending square...原创 2020-03-05 01:59:27 · 127 阅读 · 0 评论 -
【LeetCode 964】 Least Operators to Express Number
题目描述Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x … where each operator op1, op2, etc. is either addition, subtraction, multiplication, or divis...原创 2020-03-05 00:23:26 · 255 阅读 · 0 评论