码迷,mamicode.com
首页 >  
搜索关键字:leetcode 19    ( 34993个结果
LeetCode--Best Time to Buy and Sell Stock (贪心策略 or 动态规划)
LeetCode Problem -- Best Time to Buy and Sell Stock Greedy Algorithms 贪心算法...
分类:其他好文   时间:2014-06-05 04:36:58    阅读次数:239
Leetcode - Reverse Words
比起POJ弱爆了一题,从后往前扫描一遍,O(n)时间,只要注意各种极端情况即可,不明白通过率为什么只有13%。 #include #include using namespace std; class Solution { public: void reverseWords(string &s) { char* cstr = new char[s.size()+1]; ...
分类:其他好文   时间:2014-06-05 03:45:47    阅读次数:221
LeetCode Decode Ways
有点意思的题目。用动态规划可以O(n)求解出来:a[i]代表子字符串string(0,i)的可能解码方式,a[i] = {a[i-1] or a[i-1]+a[i-2]}.   意思是如果string(i)不为0,至少a[i] == a[i-1],即一种解码方法是string{0,.....(i-1)}+string(i);    然后如果string{i-1,i}是合法的(注意合法概念,比如...
分类:其他好文   时间:2014-06-05 03:36:48    阅读次数:231
[LeetCode]Next Permutation
Next Permutation字典顺序的下一个排列...
分类:其他好文   时间:2014-06-05 00:08:22    阅读次数:255
leetcode:String to Integer (atoi)
问题 输入:一个表示数字的字符串,需要考虑不同的输入形式。 输出:对应的整数 特殊输入形式: 1.输入开始几个字符为空格 2.考虑正负号 3.数字字符不属于[0,9]时,输出当前结果 4.字符串代表的数字大于INT_MAX或者小于INT_MIN时输出INT_MAX或者INT_MIN。 class Solution { // out of range...
分类:其他好文   时间:2014-06-03 06:30:14    阅读次数:314
LeetCode: Remove Duplicates from Sorted List [082]
【题目】 Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 【题意】 给定一个已排序的链表,删除其中的重复元素 【思路】 维护两个指针prev和cur, cur指针负责扫描链表,prev指向cur的前一...
分类:其他好文   时间:2014-06-03 04:05:39    阅读次数:231
LeetCode: Search in Rotated Sorted Array II [081]
【题目】 Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a function to determine if a given target is in the array. 【题意】 在“Search in Rotated Sorted Array”的基...
分类:其他好文   时间:2014-06-03 01:55:38    阅读次数:173
LeetCode: Remove Duplicates from Sorted List II [083]
【题目】 Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1->1->2->3, return 2->3. 【题意】 给定一个有序链表,删出其中重复出现的值...
分类:其他好文   时间:2014-05-31 21:14:11    阅读次数:333
【leetcode】Longest Palindromic Substring
题目:给定个字符串,返回chuan...
分类:其他好文   时间:2014-05-31 21:13:29    阅读次数:325
leetCode解题报告5道题(九)
题目一:CombinationsGiven two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4],....
分类:其他好文   时间:2014-05-31 20:01:02    阅读次数:455
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!