码迷,mamicode.com
首页 >  
搜索关键字:leetcode 19    ( 34993个结果
LeetCode OJ - Binary Tree Maximum Path
这道题需要注意的地方有以下一些:1. 求从子树中的某节点到当前节点的最大路径不能采用递归方法,因为这个部分会被反复的调用,如果用递归,会使得之前已经计算过的节点被重复计算,使得时间复杂度特别高;2. 树中有节点的值是负数的。下面是AC代码。(我发现AC并不代表代码真的完全正确!!) 1 /** 2 ...
分类:其他好文   时间:2014-05-01 12:10:52    阅读次数:274
[leetcode]LRU Cache @ Python
原题地址:http://oj.leetcode.com/problems/lru-cache/题意:设计LRU Cache参考文献:http://blog.csdn.net/hexinuaa/article/details/6630384 这篇博文总结的很到位。 https://github...
分类:编程语言   时间:2014-05-01 10:47:16    阅读次数:501
[leetcode]Linked List Cycle @ Python
原题地址:http://oj.leetcode.com/problems/linked-list-cycle/题意:判断链表中是否存在环路。解题思路:快慢指针技巧,slow指针和fast指针开始同时指向头结点head,fast每次走两步,slow每次走一步。如果链表不存在环,那么fast或者fast...
分类:编程语言   时间:2014-05-01 10:33:38    阅读次数:426
[leetcode]Linked List Cycle II @ Python
原题地址:http://oj.leetcode.com/problems/linked-list-cycle-ii/题意:如果链表中存在环路,找到环路的起点节点。解题思路:这道题有点意思。首先使用快慢指针技巧,如果fast指针和slow指针相遇,则说明链表存在环路。具体技巧参见上一篇http://w...
分类:编程语言   时间:2014-05-01 08:19:31    阅读次数:340
[leetcode] Minimum Path Sum
思路很简单,就是存储之前运算的结果,然后递归class Solution {public: int** dp; int get_min_sum(vector > &grid, int m, int n) { if (dp[m][n] != -1) ...
分类:其他好文   时间:2014-05-01 07:54:47    阅读次数:330
[leetcode]Swap Nodes in Pairs @ Python
原题地址:http://oj.leetcode.com/problems/swap-nodes-in-pairs/题意:将链表中的节点两两交换。Given1->2->3->4, you should return the list as2->1->4->3.解题思路:这题主要涉及到链表的操作,没什么...
分类:编程语言   时间:2014-05-01 06:44:21    阅读次数:339
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3....
分类:其他好文   时间:2014-04-29 13:47:20    阅读次数:251
Interleaving String -- LeetCode
原题链接: http://oj.leetcode.com/problems/interleaving-string/  这是一道关于字符串操作的题目,要求是判断一个字符串能不能由两个字符串按照他们自己的顺序,每次挑取两个串中的一个字符来构造出来。 像这种判断能否按照某种规则来完成求是否或者某个量的题目,很容易会想到用动态规划来实现。 先说说维护量,res[i][j]表示用s1的前i个字符和s...
分类:其他好文   时间:2014-04-29 13:46:22    阅读次数:336
leetCode解题报告5道题(六)
5道题目分别是:【Longest Substring Without Repeating Characters】、【Rotate Image】、【Restore IP Addresses】、【ZigZag Conversion】、【Set Matrix Zeroes】,由于有一些题目不需要发一整篇博文来记录,所以就将这些题目以一篇博文5道来记录...
分类:其他好文   时间:2014-04-29 13:43:23    阅读次数:348
Restore IP Addresses -- LeetCode
原题链接: http://oj.leetcode.com/problems/restore-ip-addresses/  这道题的解法非常接近于NP问题,也是采用递归的解法。基本思路就是取出一个合法的数字,作为IP地址的一项,然后递归处理剩下的项。可以想象出一颗树,每个结点有三个可能的分支(因为范围是0-255,所以可以由一位两位或者三位组成)。并且这里树的层数不会超过四层,因为IP地址由四段组...
分类:其他好文   时间:2014-04-29 13:16:22    阅读次数:313
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!