摘要:https://leetcode.cn/problems/ZL6zAn/ class Solution { public: void DFS(vector<vector<int>>& grid, int i, int j, int M, int N, int& sum) { if (grid[i][
        
阅读全文
 
        
     
    
        
        
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig
        
阅读全文
 
        
     
    
        
        
摘要:class Solution { public: bool isSubsequence(string s, string t) { // 公共子序列是不是s 长度相同 // dp[i][j] 表示以下标i-1为结尾的字符串s,和以下标j-1为结尾的字符串t,相同子序列的长度为dp[i][j]。 //
        
阅读全文
 
        
     
    
        
        
摘要:https://leetcode.cn/problems/unique-paths-ii/ class Solution { public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int m = obsta
        
阅读全文
 
        
     
    
        
        
摘要:class Solution { public: int uniquePaths(int m, int n) { // 二维dp数组 vector<vector<int> >dp(m, vector<int>(n, 0)); //初始化 for (int j = 0; j<n; j++) { dp[
        
阅读全文
 
        
     
    
        
        
摘要:class Solution { public: int minCostClimbingStairs(vector<int>& cost) { // dp[i] 为选择下标为i的台阶向上爬,所需要的最低花费 // dp[i] = min(dp[i-2] + cost[i-2], dp[i-1] + 
        
阅读全文
 
        
     
    
        
        
摘要:class Solution { public: int climbStairs(int n) { // dp[i] 为到达第i个台阶所用的方法 // dp[i] = dp[i-1]+dp[i-2] 两种方法之和 // dp[0] = 0 // dp[1] = 1 // dp[2] = 2 // d
        
阅读全文
 
        
     
    
        
        
摘要:https://leetcode.cn/problems/fibonacci-number/ // 递归的写法 // class Solution { // public: // int fib(int n) { // if (n==0) { // return 0; // } // if (n==
        
阅读全文