上一页 1 ··· 4 5 6 7 8 9 10 11 12 13 下一页
摘要: problem:https://leetcode.com/problems/shortest-path-in-binary-matrix/ 非常基础的单源无权最短路径,没有任何变化。 阅读全文
posted @ 2019-08-06 22:03 fish1996 阅读(258) 评论(0) 推荐(0)
摘要: problem:https://leetcode.com/problems/shortest-path-with-alternating-colors/ 周赛题,这道题是带约束的最短路径,我的做法是对不同颜色节点维护两个容器,分别计算从红色结点开始和从蓝色结点开始,取其中最小的。(这道题没有必要用优 阅读全文
posted @ 2019-08-06 20:08 fish1996 阅读(306) 评论(0) 推荐(0)
摘要: problem:https://leetcode.com/problems/sliding-puzzle/ 一看到求最短次数就是宽搜了。用字符串来记录所有状态量即可,找到目标状态量后就退出,我们总能保证找到时用到的步数是最少的。 阅读全文
posted @ 2019-08-06 15:58 fish1996 阅读(125) 评论(0) 推荐(0)
摘要: problem:https://leetcode.com/problems/snakes-and-ladders/ 这道题需要换算位置和数字之间的关系,虽然并不难但是很繁琐。 因为遇到了梯子/蛇一定要滑过去,所以我们可以当作把这一位置作为跳板直接到达了梯子末端,就好像没有来过这一位置一样。 阅读全文
posted @ 2019-08-06 14:39 fish1996 阅读(197) 评论(0) 推荐(0)
摘要: problem:https://leetcode.com/problems/longest-consecutive-sequence/ 使用并查集,时间不是严格的O(n) 阅读全文
posted @ 2019-08-06 12:44 fish1996 阅读(225) 评论(0) 推荐(0)
摘要: problem:https://leetcode.com/problems/word-ladder-ii/ 这道题做的好艰难,感觉还是经验不足导致的。 一个比较麻烦的地方是,我们需要使用一个path容器来记录访问过的路径,对于每个字符串而言,它可以由多个字符串转换而来,所以路径的上一个位置需要记录成 阅读全文
posted @ 2019-08-05 22:58 fish1996 阅读(172) 评论(0) 推荐(0)
摘要: problem: https://leetcode.com/problems/longest-valid-parentheses/ 在动态规划中,我们希望尽可能利用已经求解好的子问题结果。 对于这道问题,我们可以假设我们已经知道了以第i个字符为结尾的最长有效括号个数为 x, 那么如果它的下一个字符( 阅读全文
posted @ 2019-08-05 16:05 fish1996 阅读(133) 评论(0) 推荐(0)
摘要: problem:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 二刷此题了,发现第二次刷的时候几乎不需要思考就写出来了。之前虽然也做出了O(N)的解法,但是写起来很痛苦,因为之前是靠着人类天生 阅读全文
posted @ 2019-08-05 14:16 fish1996 阅读(120) 评论(0) 推荐(0)
摘要: 问题:https://leetcode.com/problems/last-stone-weight-ii/ 01背包问题,记录不同容量的背包能否被恰好装满即可。 阅读全文
posted @ 2019-08-05 13:58 fish1996 阅读(323) 评论(0) 推荐(0)
摘要: problem:https://leetcode.com/problems/random-pick-with-weight/ 首先计算一个累积的频数,根据总频数来进行随机,之后通过二分查找得到当前随机数对应的下标。 阅读全文
posted @ 2019-08-05 10:57 fish1996 阅读(114) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 13 下一页