240
笔下虽有千言,胸中实无一策
摘要: 题解 Hard Sliding Window 事实证明,掌握套路还是很有用的。用 sliding window 模板套路解决这道题还是比较顺利的,虽然是一道 Hard 级别的题。当然,有一点冗余,可以精简一下。 class Solution { public: int lengthOfLongest 阅读全文
posted @ 2020-10-09 14:22 CasperWin 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 题解 Hard 动态规划 这道题还确实挺难的,尤其是状态转移方程,不容易想到。 dp[i][j]: i位到j位的子数组能得到的最大值(或最多硬币值)。 这个问题可以继续分解乘子问题: | i | ... | k | ... | j | (k = i ... j) 考虑如果第k位是[i, j]中最后戳 阅读全文
posted @ 2020-10-09 13:52 CasperWin 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium BFS Tree 是一种特殊的 Graph,节点之间只有一个方向。而这里有从 Target 节点向各个方向,包括父节点方向,遍历的需求。所以利用 Hashmap 先转化成一个无向图。 /** * Definition for a binary tree node. * struc 阅读全文
posted @ 2020-10-09 07:30 CasperWin 阅读(129) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int minKnightMoves(int x, int y) { int steps = 0; unordered_set<string> s; queue<pair<int, int>> q; q.push({0, 0}); s.insert( 阅读全文
posted @ 2020-10-09 07:03 CasperWin 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium 动态规划 class Solution { public: bool wordBreak(string s, vector<string>& wordDict) { // a + b = s // as long as a true and b true, then s true 阅读全文
posted @ 2020-10-09 02:00 CasperWin 阅读(78) 评论(0) 推荐(0) 编辑