会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Agentgamer
“It only takes 10 seconds to crush a man's ambitions. I need to take care that I protect mine.”
博客园
首页
新随笔
联系
订阅
管理
1
2
3
4
5
···
13
下一页
2019年8月14日
206. Reverse Linked List
摘要: 花式反转单链表 1. 用反转数组的思路:反转[1:] 然后把head 怼在后面。与数组不同“怼在后面” 这个操作是O(n) 效率很差。 2. 改进上面的方法,优化掉后面那个O(n) 的添加操作。方法是:记住已反转好的tail,这样只用tail->next = head 就可以了,不需要遍历整个链表。
阅读全文
posted @ 2019-08-14 15:43 Agentgamer
阅读(137)
评论(0)
推荐(0)
2019年7月19日
529. Minesweeper
摘要: class Solution { unordered_set visited; inline string hash(int r, int c) { return to_string(r) + "#" + to_string(c); } void check(vector>& board, ...
阅读全文
posted @ 2019-07-19 20:39 Agentgamer
阅读(197)
评论(0)
推荐(0)
2019年3月26日
948. Bag of Tokens
摘要: https://leetcode.com/problems/bag-of-tokens/ 一开始觉得应该是个dp 题,把所有结果搜出来然后max 一下。实现以后发现组合太多了,非常慢,即使加上memorization 也是TLE 看了答案发现是用greedy,然而也没有证明为啥greedy 就是最优
阅读全文
posted @ 2019-03-26 22:53 Agentgamer
阅读(220)
评论(0)
推荐(0)
2019年3月10日
ugly-number-ii
摘要: https://www.lintcode.com/problem/ugly-number-ii/description 2 * (1,2,3,4,5....) 3 * (1,2,3,4,5....) 5 * (1,2,3,4,5....) 三个stream 的merge
阅读全文
posted @ 2019-03-10 22:47 Agentgamer
阅读(148)
评论(0)
推荐(0)
2018年10月15日
575. Distribute Candies
摘要: https://leetcode.com/problems/distribute-candies/description/ 题目比较长,总结起来很简单:有个整型数组,长度是偶数,把它分成两份,要求有一份里面数字的多样性最大。 思路:一个很简单的思路是,数出有多少不一样的数字n,然后一份有多少个m,取
阅读全文
posted @ 2018-10-15 11:04 Agentgamer
阅读(89)
评论(0)
推荐(0)
118. Pascal's Triangle
摘要: https://leetcode.com/problems/pascals-triangle/description/ 思路:先写好base case,也就是杨辉三角的前两行。然后从第2 行开始递推第3 行。往后的每一行都由前一行推出。 知道第n 行求n+1 行很简单,首先开头都是1,然后从0 开始
阅读全文
posted @ 2018-10-15 10:14 Agentgamer
阅读(119)
评论(0)
推荐(0)
2018年10月12日
572. Subtree of Another Tree
摘要: https://leetcode.com/problems/subtree-of-another-tree/description/ easy 题也不easy,坑还是多。主要观察两个例子:[1,1] [1] 和 [3,4,5,1,null,null,2] [3,1,2] 第一个例子主要考察当s, t
阅读全文
posted @ 2018-10-12 17:05 Agentgamer
阅读(112)
评论(0)
推荐(0)
32. Longest Valid Parentheses
摘要: https://leetcode.com/problems/longest-valid-parentheses/description/ 来回做了好几遍,虽然AC 了但是这个解发肯定不是最优的。思路是把问题分两步解决:1. 把字符串转换成一个匹配括号的id 序列,比如第0 个和第3 个匹配了,则把0
阅读全文
posted @ 2018-10-12 15:12 Agentgamer
阅读(133)
评论(0)
推荐(0)
2018年10月11日
566. Reshape the Matrix
摘要: https://leetcode.com/problems/reshape-the-matrix/description/ 简单有趣,也稍微窥探了一下matlab 和numpy 里面reshape 的算法。当然现实要比这个题要复杂,比如numpy 里面reshape 可以只接受一个参数,然后自动推导
阅读全文
posted @ 2018-10-11 12:36 Agentgamer
阅读(165)
评论(0)
推荐(0)
563. Binary Tree Tilt
摘要: https://leetcode.com/problems/binary-tree-tilt/description/ 挺好的一个题目,审题不清的话很容易做错。主要是tilt of whole tree 的定义是sum of all node's tilt 而不是想当然的tilt of root.
阅读全文
posted @ 2018-10-11 11:59 Agentgamer
阅读(141)
评论(0)
推荐(0)
1
2
3
4
5
···
13
下一页
公告