会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
frankM
天下武功,唯快不破。
博客园
|
首页
|
新随笔
|
新文章
|
联系
|
订阅
|
管理
上一页
1
2
3
4
5
6
7
8
9
10
···
18
下一页
2014年12月12日
LeetCode 3sum
摘要: 链接: https://oj.leetcode.com/problems/3sum/2sum:尺取法 通过a+b与target比较,.根据大于或小于不断缩小范围3sum:即对0~n个数分别做2sum...去重: if(i!=0&&num[i]==num[i-1]) continue;只有当i=...
阅读全文
posted @ 2014-12-12 17:13 frankM
阅读(121)
评论(0)
推荐(0)
编辑
2014年12月10日
LeetCode Best Time to Buy and Sell Stock II
摘要: 链接: https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/class Solution{ public: int maxProfit(vector &prices) { if(prices.size()==...
阅读全文
posted @ 2014-12-10 14:07 frankM
阅读(90)
评论(0)
推荐(0)
编辑
2014年12月8日
LeetCode Permutations
摘要: 链接: https://oj.leetcode.com/problems/permutations/每次从num中选择一个数添加到结果中,并用used标记用过的数.public class Solution { private boolean used[]; private List > ans;...
阅读全文
posted @ 2014-12-08 22:08 frankM
阅读(114)
评论(0)
推荐(0)
编辑
2014年12月5日
LeetCode Rotate List
摘要: 链接: https://oj.leetcode.com/problems/rotate-list//** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next...
阅读全文
posted @ 2014-12-05 21:39 frankM
阅读(105)
评论(0)
推荐(0)
编辑
2014年12月4日
LeetCode Reorder List
摘要: 链接: https://oj.leetcode.com/problems/reorder-list/空间复杂度为O(n),时间复杂度为 O(n)的代码:/** * Definition for singly-linked list. * struct ListNode { * int val...
阅读全文
posted @ 2014-12-04 13:55 frankM
阅读(132)
评论(0)
推荐(0)
编辑
2014年12月2日
LeetCode Sum Root to Leaf Numbers
摘要: 链接: https://oj.leetcode.com/problems/sum-root-to-leaf-numbers/dfs..sum保存中间结果.每计算完一条路径,就更新ans/** * Definition for binary tree * struct TreeNode { * ...
阅读全文
posted @ 2014-12-02 19:37 frankM
阅读(163)
评论(0)
推荐(0)
编辑
2014年11月30日
LeetCode Unique Binary Search Trees
摘要: 链接: https://oj.leetcode.com/problems/unique-binary-search-trees/dp[i]表示当n为i时的BST数量..递推关系如下图这样,就把n=4分割为n=3,n=1,n=2.用dp数组记录结果代码:class Solution{ public: ...
阅读全文
posted @ 2014-11-30 13:14 frankM
阅读(116)
评论(0)
推荐(0)
编辑
2014年11月29日
LeetCode Best Time to Buy and Sell Stock
摘要: 链接: https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock/开始理解错题意了..只能买一次&&卖一次.找出最大利润看了网上的思路...O(n)的复杂度..ACclass Solution{ public: int max...
阅读全文
posted @ 2014-11-29 12:20 frankM
阅读(139)
评论(0)
推荐(0)
编辑
2014年11月27日
LeetCode Partition List
摘要: 链接: https://oj.leetcode.com/problems/partition-list/双重指针....../** * Definition for singly-linked list. * struct ListNode { * int val; * ListNo...
阅读全文
posted @ 2014-11-27 17:26 frankM
阅读(127)
评论(0)
推荐(0)
编辑
2014年11月24日
LeetCode Path Sum
摘要: 链接: https://oj.leetcode.com/problems/path-sum/深度优先搜索,.求出个从根到叶子节点的和..注意树中有负树/** * Definition for binary tree * struct TreeNode { * int val; * T...
阅读全文
posted @ 2014-11-24 22:25 frankM
阅读(154)
评论(0)
推荐(0)
编辑
上一页
1
2
3
4
5
6
7
8
9
10
···
18
下一页
公告