上一页 1 2 3 4 5 6 7 8 ··· 38 下一页
摘要: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), 阅读全文
posted @ 2020-05-06 11:29 Jinxiaobo0509 阅读(110) 评论(0) 推荐(0)
摘要: 1 void traverse(ListNode* head) 2 { 3 if(!head) return; 4 //cout << head->val << " "; // 正序访问链表 5 traverse(head->next); 6 //cout << head->val << " "; 阅读全文
posted @ 2020-05-06 10:16 Jinxiaobo0509 阅读(152) 评论(0) 推荐(0)
摘要: 1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices, int fee) 5 { 6 int n = prices.size(); 7 vector<vector<int>> dp(n,vector<int>(2,0)) 阅读全文
posted @ 2020-05-05 19:21 Jinxiaobo0509 阅读(146) 评论(0) 推荐(0)
摘要: 1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices) 5 { 6 if(prices.size() < 2) return 0; 7 int n = prices.size(); 8 vector<vector<int 阅读全文
posted @ 2020-05-05 19:13 Jinxiaobo0509 阅读(111) 评论(0) 推荐(0)
摘要: 1 // 一次交易由买入和卖出构成,至少需要两天。所以说有效的限制 k 应该不超过 n/2,如果超过,就没有约束作用了,相当于 k = +infinity。 2 class Solution 3 { 4 public: 5 int maxProfit(int K, vector<int>& pric 阅读全文
posted @ 2020-05-05 19:00 Jinxiaobo0509 阅读(160) 评论(0) 推荐(0)
摘要: 1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices) 5 { 6 if(prices.empty()) return 0; 7 int n = prices.size(); 8 vector<vector<vector 阅读全文
posted @ 2020-05-05 18:46 Jinxiaobo0509 阅读(133) 评论(0) 推荐(0)
摘要: 1 dp[i][k][0 or 1] 2 0 <= i <= n-1, 1 <= k <= K 3 n 为天数,大 K 为最多交易数 4 此问题共 n × K × 2 种状态,全部穷举就能搞定。 5 6 for 0 <= i < n: 7 for 1 <= k <= K: 8 for s in {0 阅读全文
posted @ 2020-05-05 18:09 Jinxiaobo0509 阅读(203) 评论(0) 推荐(0)
摘要: 1 class Trie 2 { 3 public: 4 bool is_end; //是否以该单词结尾 5 Trie* son[26]; //该节点儿子的个数 6 Trie() 7 { 8 is_end = false; 9 for(int i = 0;i < 26;i ++) son[i] = 阅读全文
posted @ 2020-05-03 23:15 Jinxiaobo0509 阅读(117) 评论(0) 推荐(0)
摘要: 1 class Solution 2 { 3 // 状态 dp[i][j] : 表示 s 的前 i 个字符和 p 的前 j 个字符是否匹配 (true 的话表示匹配) 4 // 状态转移方程: 5 // 1. 当 s[i] == p[j],或者 p[j] == ? 那么 dp[i][j] = dp[ 阅读全文
posted @ 2020-05-02 21:56 Jinxiaobo0509 阅读(155) 评论(0) 推荐(0)
摘要: 1 //f(n) 表示从左到右(forward)的最终结果 2 //b(n) 表示从右到左(backward)的最终结果 3 class Solution 4 { 5 public: 6 int leftToRight(int n) 7 { 8 if (n == 1) return 1; 9 els 阅读全文
posted @ 2020-04-30 14:52 Jinxiaobo0509 阅读(126) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 ··· 38 下一页