码迷,mamicode.com
首页 >  
搜索关键字:leetcode 19    ( 34993个结果
4Sum -- LeetCode
原题链接: http://oj.leetcode.com/problems/4sum/  这道题要求跟3Sum差不多,只是需求扩展到四个的数字的和了。我们还是可以按照3Sum中的解法,只是在外面套一层循环,相当于求n次3Sum。我们知道3Sum的时间复杂度是O(n^2),所以如果这样解的总时间复杂度是O(n^3)。代码如下:public ArrayList> fourSum(int[] num,...
分类:其他好文   时间:2014-07-22 23:01:34    阅读次数:328
LeetCode - Best Time to Buy and Sell 3
这道题在前两个的基础上做稍微改进就可以。下面是AC代码: 1 /** 2 * Design an algorithm to find the maximum profit. You may complete at most two transactions. 3 * @pa...
分类:其他好文   时间:2014-07-22 23:01:13    阅读次数:251
[leetcode]Valid Number @ Python
原题地址:http://oj.leetcode.com/problems/valid-number/题意:判断输入的字符串是否是合法的数。解题思路:这题只能用确定有穷状态自动机(DFA)来写会比较优雅。本文参考了http://blog.csdn.net/kenden23/article/detail...
分类:编程语言   时间:2014-05-02 00:04:57    阅读次数:483
leetcode__Add Two Numbers && Climbing Stairs
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link...
分类:其他好文   时间:2014-05-01 22:08:19    阅读次数:366
Leetcode | Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinki...
分类:其他好文   时间:2014-05-01 19:48:19    阅读次数:344
LeetCode - Best Time to Buy and Sell 2
这道题我一开始想到用递归方法,可以把规模大的问题变成规模小的问题,但是觉得递归的时间复杂度很高,因为它会把相同的问题进行重复计算,然后我想是不是有什么down-up的方法,先把所有的子问题的结果保存起来,但是发现问题的最优解并不能由子问题的最优解推导出来。最后就想到买股票的时候,我们在一个局部极小的...
分类:其他好文   时间:2014-05-01 19:24:02    阅读次数:250
leetcode__Merge k Sorted Lists
Merge k Sorted Lists  Total Accepted: 9746 Total Submissions: 41674My Submissions Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity....
分类:其他好文   时间:2014-05-01 17:11:32    阅读次数:234
leetcode day7 -- Word Break I II
1、 ?? Word Break...
分类:其他好文   时间:2014-04-30 22:26:38    阅读次数:285
Sort Colors
leetcode,三色排序...
分类:其他好文   时间:2014-04-30 22:14:39    阅读次数:225
Unique Binary Search Trees -- LeetCode
原题链接: http://oj.leetcode.com/problems/unique-binary-search-trees/  这道题要求可行的二叉查找树的数量,其实二叉查找树可以任意取根,只要满足中序遍历有序的要求就可以。从处理子问题的角度来看,选取一个结点为根,就把结点切成左右子树,以这个结点为根的可行二叉树数量就是左右子树可行二叉树数量的乘积,所以总的数量是将以所有结点为根的可行结果...
分类:其他好文   时间:2014-04-30 22:12:39    阅读次数:244
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!