随笔分类 -  dp - matrix

361. Bomb Enemy
摘要:Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number zero), return the maximum enemies you can kill using one bomb.
The bomb kills all the enemies in the same row an... 阅读全文

posted @ 2018-11-29 06:04 猪猪🐷

118. Pascal's Triangle
摘要:DescriptionHintsSubmissionsDiscussSolution Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers dir... 阅读全文

posted @ 2018-11-09 10:48 猪猪🐷

750. Number Of Corner Rectangles
摘要:Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner rectangle is 4 distinct 1s on the grid that form an axis-aligned rectangle. Note that only the corners nee... 阅读全文

posted @ 2018-11-09 10:37 猪猪🐷

119. Pascal's Triangle II
摘要:Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0.  In Pascal's tri 阅读全文

posted @ 2018-11-09 10:21 猪猪🐷

562. Longest Line of Consecutive One in Matrix
摘要:https://leetcode.com/problems/longest-line-of-consecutive-one-in-matrix/solution/ Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horizontal, vertical... 阅读全文

posted @ 2018-11-08 16:34 猪猪🐷

304. Range Sum Query 2D - Immutable
摘要:Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2 阅读全文

posted @ 2018-11-08 02:25 猪猪🐷

85. Maximal Rectangle
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example: Input: [ ["1","0","1","0","0"], ["1","0","1","1","1"], [" 阅读全文

posted @ 2018-11-06 11:52 猪猪🐷

797. All Paths From Source to Target
摘要:Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N-1, and return them in any order. The graph is given as follows: the nodes are 0, 1, ..., graph.length - 1. ... 阅读全文

posted @ 2018-11-06 09:28 猪猪🐷

363. Max Sum of Rectangle No Larger Than K
摘要:Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k. Example: Input: matrix = [[1,0,1],[0,-2,3]], k = 2 Output: 2 ... 阅读全文

posted @ 2018-11-06 08:06 猪猪🐷

63. Unique Paths II
摘要:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bo... 阅读全文

posted @ 2018-11-06 08:06 猪猪🐷

174. Dungeon Game
摘要:The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially po... 阅读全文

posted @ 2018-11-06 08:05 猪猪🐷

741. Cherry Pickup
摘要:In a N x N grid representing a field of cherries, each cell is one of three possible integers. 0 means the cell is empty, so you can pass through; 1 means the cell contains a cherry, that you can pi... 阅读全文

posted @ 2018-11-06 08:04 猪猪🐷

Given a matrix, get the number of path from the top left cell to the top right cell.
摘要:Given a matrix, get the number of path from the top left cell to the top right cell. Note that: you can only go right, up right, down right. (0,0) (0, 阅读全文

posted @ 2018-10-03 23:55 猪猪🐷

568. Maximum Vacation Days
摘要:LeetCode wants to give one of its best employees the option to travel among N cities to collect algorithm problems. But all work and no play makes Jack a dull boy, you could take vacations in some pa... 阅读全文

posted @ 2018-09-25 04:21 猪猪🐷

62. Unique Paths
摘要:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the b... 阅读全文

posted @ 2018-09-20 18:21 猪猪🐷

64. Minimum Path Sum
摘要:https://leetcode.com/problems/minimum-path-sum/solution/ Approach 3: Dynamic Programming 1D Approach 4: Dynamic Programming (Without Extra Space) 阅读全文

posted @ 2018-09-20 18:17 猪猪🐷

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 outside o... 阅读全文

posted @ 2018-09-20 18:15 猪猪🐷

longest consecutive path
摘要:Given a 2D matrix containing all positive and distinct integers in the range [1, N^2], compute the longest path containing consecutive integers in thi 阅读全文

posted @ 2018-09-11 14:47 猪猪🐷

120. Triangle
摘要:120. Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], ... 阅读全文

posted @ 2018-08-11 03:41 猪猪🐷

221. Maximal Square
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. Example: Input: 1 0 1 0 0 1 0 1 1 1 阅读全文

posted @ 2018-08-11 03:32 猪猪🐷

导航