240
笔下虽有千言,胸中实无一策

随笔分类 -  刷题

Leetcode, Lintcode
摘要:题解 逆序链表,基本功之一。 用递归写起来很简单,但需要消耗大量栈空间,更推荐使用迭代的方法。通过画图找到变换关系。 // Original Linked List: ? --> p --> q --> r --> ? // Assume the elements before p have bee 阅读全文
posted @ 2020-07-04 06:57 CasperWin 阅读(91) 评论(0) 推荐(0)
摘要:题解 这道题是Easy级别,算是BFS的典型题,适合用来找手感。 非常典型的套路是,用一个队列结构(queue)保存一层的信息,那么下一次迭代的时候,就可以通过队列先进先出的顺序,根据上一层的信息去操作。 class Solution { public: vector<vector<int>> le 阅读全文
posted @ 2020-07-03 04:44 CasperWin 阅读(76) 评论(0) 推荐(0)
摘要:题述 原题见链接。 题解 根据题意,很容易想到蛮力解法如下: Brute Force Method // Complete the arrayManipulation function below. long arrayManipulation(int n, vector<vector<int>> 阅读全文
posted @ 2020-07-03 04:10 CasperWin 阅读(267) 评论(0) 推荐(0)
摘要:这道题是被认为属于 Stack 范畴的题,但我一开始解题的时候,并没有察觉到 pop 操作的需要。我理解这里需要一个维护历史记录的数据结构,那么 vector 也就足够了。 下面是我的被 Accept 的解答: 讨论版上,主流的解答是用一个 stack 来进行维护历史记录,其中有些记录在操作过程中会 阅读全文
posted @ 2020-05-20 03:06 CasperWin 阅读(163) 评论(0) 推荐(0)
摘要:蛮力算法不难想出,穷举即可,但明显会超时。需要考虑如何避免多余计算。 可以用一个移动窗口,也就是用下标 i 和 j 框出一个子字符串,能包含所有 s1 中的字符,这个字符串通常是包含了其他字母的,如果没有,那么它的长度是和 s1 字符串一样的。 移动窗口方法,可以说在字符串匹配和查找问题中屡试不爽。 阅读全文
posted @ 2020-05-19 03:29 CasperWin 阅读(138) 评论(0) 推荐(0)
摘要:Description: There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each 阅读全文
posted @ 2017-11-29 05:54 CasperWin 阅读(996) 评论(0) 推荐(0)
摘要:[Problem] Given a 2D grid, each cell is either a wall 2, an house 1 or empty 0 (the number zero, one, two), find a place to build a post office so tha 阅读全文
posted @ 2017-09-13 23:21 CasperWin 阅读(1017) 评论(0) 推荐(0)
摘要:[Probelm] (link) Given a 2D grid, each cell is either a wall 2, a zombie 1 or people 0 (the number zero, one, two).Zombies can turn the nearest people 阅读全文
posted @ 2017-08-31 02:08 CasperWin 阅读(386) 评论(0) 推荐(0)
摘要:[Problem] Given a knight in a chessboard (a binary matrix with 0 as empty and 1 as barrier) with a source position, find the shortest path to a destin 阅读全文
posted @ 2017-08-30 22:59 CasperWin 阅读(988) 评论(0) 推荐(0)
摘要:[Problem] Given a undirected graph, a node and a target, return the nearest node to given node which value of it is target, return NULL if you can't f 阅读全文
posted @ 2017-08-30 04:42 CasperWin 阅读(584) 评论(0) 推荐(0)