![](https://img-blog.csdnimg.cn/0a3823ccb3904b77a66a4506d3b178a8.jpeg?x-oss-process=image/resize,m_fixed,h_224,w_224)
LeetCode Learning
文章平均质量分 84
Algorithm topic learning and sharing
NP_hard
ShenZhen University-CSSE-CS
️ Github: Np_hard (David-deng-yeah)
Interest: Database-Kernel & Distributed-System & Machine-Learning
展开
-
每日一题 day59 (Dp topic)
文章目录problemapproach 1 `recursive TLE`approach 2 `dp`problem377. Combination Sum IVGiven an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.The test cases are generated so tha原创 2022-03-30 23:30:06 · 429 阅读 · 1 评论 -
每日一题 day 58(DP topic)
文章目录problemwrong approachapproach `memorize dp`problem518. Coin Change 2You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.Return the number of combinations that原创 2022-03-25 00:04:09 · 354 阅读 · 0 评论 -
每日一题 day 57 (DP topic)
文章目录problem `classical bag problem`wrong approach `59/188, Greedy`wrong approach 2 `TLE, recursive`appraoch 3 `memorize dp`approach `bag problem , dp`problem classical bag problem322. Coin ChangeYou are given an integer array coins representing coins of原创 2022-03-24 00:15:48 · 534 阅读 · 2 评论 -
每日一题 day 56(DP topic)
文章目录problemapproach `DP`approach `shorter code`wrong approachproblem1143. Longest Common SubsequenceGiven two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.A subsequence of a原创 2022-03-20 21:22:03 · 257 阅读 · 0 评论 -
每日一题 day 55(DP topic)
文章目录problemapproach 1approach 2 `shorter code`problem392. Is SubsequenceGiven two strings s and t, return true if s is a subsequence of t, or false otherwise.A subsequence of a string is a new string that is formed from the original string by deleting原创 2022-03-18 23:55:22 · 234 阅读 · 0 评论 -
每日一题 day 54 (DP topic)
文章目录problemapproach 1 `Brute force`approach 3 `Greedy`problem376. Wiggle SubsequenceA wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) m原创 2022-03-17 15:15:19 · 313 阅读 · 0 评论 -
每日一题 day 53 (DP topic)
文章目录problemapproach 1 `DP`approach 2 `Greedy with Binary search`approach 3 ` Binary Indexed Tree` `others approach`problem300. Longest Increasing SubsequenceGiven an integer array nums, return the length of the longest strictly increasing subsequence.A原创 2022-03-16 11:46:26 · 664 阅读 · 0 评论 -
字符串DP问题
文章目录前言例题1例题2前言对于一些字符串问题,比如求一串字符中最长的回文串,或者是一些回文串的变种问题,我们一般可以使用一个二维的DP数组来保存计算的结果,从而减少计算量,下面我用两个例题来解释例题1例题的链接例题2516. Longest Palindromic Subsequence给定一个字符串s,找出s中最长的回文子序列的长度。子序列是一个序列,可以通过删除部分或不删除元素而从另一个序列派生,而不改变其余元素的顺序。我们可以将一个字符串的任意字串用一个二维DP数组来表示,比如s[原创 2022-03-15 10:57:13 · 260 阅读 · 0 评论 -
每日一题 day 52 (DP topic)
文章目录problemapproach 1problem516. Longest Palindromic SubsequenceGiven a string s, find the longest palindromic subsequence’s length in s.A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without chang原创 2022-03-15 10:13:25 · 184 阅读 · 0 评论 -
每日一题 day 51 (DP topic)
文章目录problemapproach 1problem221. Maximal SquareGiven an m x n binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.Example 1:Input: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","原创 2022-03-14 22:19:50 · 526 阅读 · 0 评论 -
每日一题 day 50(DP topic)
文章目录problemapproach 1`DP`approach 2 `DP less space`problem64. Minimum Path SumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.Note: You can only move原创 2022-03-13 11:58:30 · 135 阅读 · 0 评论 -
每日一题 day 49 (DP topic)
文章目录problemapproach 1 `DP`approach 2 `DP merge two loop`approach 3 `others dp`approach 4 `others dp, less space`problem63. Unique Paths IIA robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only原创 2022-03-12 16:21:50 · 149 阅读 · 0 评论 -
每日一题 day48 (DP topic)
文章目录problemapproach `permutation`approach 1 `DP`approach 2 `DP improve`problem62. Unique PathsThere is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner原创 2022-03-11 17:09:27 · 285 阅读 · 0 评论 -
每日一题 day 47 (DP topic)
文章目录problemapproachproblem304. Range Sum Query 2D - ImmutableGiven a 2D matrix matrix, handle multiple queries of the following type:Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and low原创 2022-03-10 12:42:19 · 119 阅读 · 0 评论 -
每日一题 day 46 (DP topic)
文章目录problemwrong approach 1 `TLE`approach 2 `DP`approach 3 `wonderful DP`problem1314. Matrix Block SumGiven a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for:i - k <= r <原创 2022-03-09 14:41:29 · 170 阅读 · 0 评论 -
每日一题 day45 (DP topic)
文章目录problemapproach 1approach 2 `with some trick`problem931. Minimum Falling Path SumGiven an n x n array of integers matrix, return the minimum sum of any falling path through matrix.A falling path starts at any element in the first row and chooses th原创 2022-03-08 10:21:37 · 110 阅读 · 0 评论 -
每日一题 day 44 (DP topic)
文章目录problemmy approachproblem118. Pascal’s TriangleGiven an integer numRows, return the first numRows of Pascal’s triangle.In Pascal’s triangle, each number is the sum of the two numbers directly above it as shown:Example 1:Input: numRows = 5Output原创 2022-03-07 13:39:53 · 79 阅读 · 0 评论 -
每日一题 day 43 (DP topic)
文章目录problemwrong approachapproach 1problemwrong approachclass Solution {public: int numTrees(int n) { vector<int> dp(23, 0); dp[0] = 1, dp[1] = 1, dp[2] = 2; for(int i=3; i<=n; i++){ if(i%2){原创 2022-03-06 15:44:28 · 96 阅读 · 0 评论 -
每日一题 day 42 (DP topic)
文章目录problemapproachproblem264. Ugly Number IIAn ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.Given an integer n, return the nth ugly number.Example 1:Input: n = 10Output: 12Explanation: [1, 2, 3, 4, 5, 6, 8, 9, 1原创 2022-03-05 15:21:38 · 200 阅读 · 0 评论 -
每日一题 day 41 (DP topic)
文章目录problemwrong approachwrong approach `tle`dfs + memorizationproblem91. Decode WaysA message containing letters from A-Z can be encoded into numbers using the following mapping:'A' -> "1"'B' -> "2"...'Z' -> "26"To decode an encoded mess原创 2022-03-04 17:27:00 · 303 阅读 · 0 评论 -
每日一题 day 40 (DP topic)
文章目录problemapproach 1 `brute force`approach 2 `without extra space`approach 3 `shortest code, but not best`problem413. Arithmetic SlicesAn integer array is called arithmetic if it consists of at least three elements and if the difference between any tw原创 2022-03-03 13:03:23 · 153 阅读 · 0 评论 -
每日一题 day 39 (dp topic)
文章目录problemapproach 1 `TLE`approach 2 `DP`approach 3 `two point`wrong approachproblem42. Trapping Rain WaterGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.E原创 2022-03-02 17:23:49 · 163 阅读 · 0 评论 -
每日一题 day 38 (DP topic)
文章目录problemwrong solution 1 `Brute force recursive`solution 2 `dp`solution 3 `DFS + prune`problem139. Word BreakGiven a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dicti原创 2022-03-01 12:16:15 · 306 阅读 · 0 评论 -
每日一题 day 37 (DP topic)
文章目录solutionNOTE714. Best Time to Buy and Sell Stock with Transaction FeeYou are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee.Find the maximum profit you can achiev原创 2022-02-28 12:36:43 · 317 阅读 · 0 评论 -
每日一题 day 36 (DP topic)
文章目录solution 1solution 2solution 3NOTE309. Best Time to Buy and Sell Stock with CooldownYou are given an array prices where prices[i] is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete as many transact原创 2022-02-27 12:40:57 · 314 阅读 · 0 评论 -
每日一题 day 35 (DP topic)
文章目录my solutionsolution 2 `good solution`solution 3 `best and fastest solution`NOTE122. Best Time to Buy and Sell Stock IIYou are given an integer array prices where prices[i] is the price of a given stock on the ith day.On each day, you may decide to b原创 2022-02-26 15:14:19 · 90 阅读 · 0 评论 -
力扣第三十四天(DP topic)
文章目录problem Ⅰsolution 1problem Ⅱwrong solutioncorrect solutionproblem Ⅰ1014. Best Sightseeing PairYou are given an integer array values where values[i] represents the value of the ith sightseeing spot. Two sightseeing spots i and j have a distance j - i原创 2022-02-26 01:21:46 · 77 阅读 · 0 评论 -
力扣第三十三天(DP topic)
文章目录problem Ⅰsolutionproblem Ⅱsolutionproblem Ⅰ152. Maximum Product SubarrayGiven an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product.The test cases are generated so that the原创 2022-02-25 00:23:48 · 521 阅读 · 0 评论 -
力扣第三十二天(DP topic)
文章目录problem Ⅰsolution 1solution 2 `without dp array`problem Ⅱsolutionproblem Ⅰ53. Maximum SubarrayGiven an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.A subarray is a co原创 2022-02-18 00:07:46 · 355 阅读 · 0 评论 -
力扣第三十一天(DP topic)
文章目录problem Ⅰsolution 1solution 2problem Ⅱsolutionproblem Ⅰ55. Jump GameYou are given an integer array nums. You are initially positioned at the array’s first index, and each element in the array represents your maximum jump length at that position.Ret原创 2022-02-17 01:17:04 · 8231 阅读 · 0 评论 -
力扣第三十天(DP topic)
文章目录problem Ⅰsolution 1problem Ⅱsolution 1problem Ⅰ213. House Robber IIYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means t原创 2022-02-16 02:06:00 · 290 阅读 · 0 评论 -
力扣第二十九天(DP topic)
文章目录problem Ⅰsolution `DP`problem Ⅱsolution 1 `DP`solution 2 `short code`problem Ⅲsolutionproblem Ⅰ509. Fibonacci NumberThe Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the原创 2022-02-14 23:35:03 · 187 阅读 · 0 评论 -
力扣第二十八天(heap(priority queue) topic)
文章目录problem Ⅰsolution 1 `hashmap and priority queue`solution 2 `bucket`problem Ⅱmy solution 1 `max priority queue`solution 2 `sort`great solution 1 `binary search`great solution 2 `quick select`problem Ⅰ451. Sort Characters By FrequencyGiven a string s,原创 2022-02-13 16:32:35 · 438 阅读 · 0 评论 -
力扣第二十七天(heap(priority queue) topic)
文章目录problem Ⅰsolution 1problem Ⅱsolutionproblem Ⅰ215. Kth Largest Element in an ArrayGiven an integer array nums and an integer k, return the kth largest element in the array.Note that it is the kth largest element in the sorted order, not the kth dist原创 2022-02-12 15:50:40 · 7552 阅读 · 0 评论 -
力扣第二十六天(Graph topic)
文章目录problem Ⅰsolution 1 `matrix`solution 2 `only use a vector of size n`problem Ⅱsolution 1problem Ⅲsolutionproblem Ⅰ997. Find the Town JudgeIn a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the tow原创 2022-02-11 16:20:24 · 466 阅读 · 0 评论 -
力扣第二十五天(Tree topic)
文章目录problem Ⅰmy solution 1 `DFS`my solution 2 `use parent pointer`problem Ⅱsolution 1 `TLE`solution 2problem Ⅰ236. Lowest Common Ancestor of a Binary TreeGiven a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.Accordin原创 2022-02-10 15:33:42 · 272 阅读 · 0 评论 -
力扣第二十四天(Tree topic)
文章目录problem Ⅰsolution 1 `recursive` `inorder-traversal`solution 2 `iterative (use stack)` `inorder-traversal`problem 2solutionproblem Ⅰ230. Kth Smallest Element in a BSTGiven the root of a binary search tree, and an integer k, return the kth smallest v原创 2022-02-09 13:52:18 · 96 阅读 · 0 评论 -
力扣第二十三天(Tree Topic)
文章目录problem Ⅰsolution 1 `BFS`solution 2 `DFS`problem 2solution `DFS`problem 3solution 1solution 2 `recursive [a little bit slow]`problem Ⅰ199. Binary Tree Right Side ViewGiven the root of a binary tree, imagine yourself standing on the right side of it,原创 2022-02-08 18:27:16 · 536 阅读 · 0 评论 -
力扣第二十二天 (Tree topic)
文章目录problem Ⅰmy solutionproblem Ⅱmy solution 1 `brute force`my solution 2 `hashmap`problem Ⅲmy solution 1 `use stack to reverse`my solution 2 `use reverse() instead of using stack`problem Ⅰ108. Convert Sorted Array to Binary Search TreeGiven an integer原创 2022-02-07 16:55:35 · 6377 阅读 · 0 评论 -
力扣第二十一天(stack, queue)
文章目录problem Ⅰmy solution 1 `stack`my solution 2 `cnt`problem Ⅱmy solution `wrong`my solution `queue`problem Ⅲsolutionproblem Ⅰ1249. Minimum Remove to Make Valid ParenthesesGiven a string s of ‘(’ , ‘)’ and lowercase English characters.Your task is to r原创 2022-02-06 15:08:37 · 187 阅读 · 0 评论