码迷,mamicode.com
首页 >  
搜索关键字:leetcode 19    ( 34993个结果
LeetCode --- Climbing Stairs
题目链接简单递推附上代码: 1 class Solution { 2 public: 3 int climbStairs(int n) { 4 int f0 = 1, f1 = 1, f2 = 1; 5 for (int i = 2; i <= n; i++)...
分类:其他好文   时间:2014-05-29 01:48:48    阅读次数:175
LeetCode --- Reverse Integer
题目链接从代码的健壮性考虑, 应该顾及到把数字翻转后发生溢出的情况,但是此题中并没有这种测试数据。附上代码: 1 class Solution { 2 public: 3 int reverse(int x) { 4 int tmp = abs(x); 5 i...
分类:其他好文   时间:2014-05-29 00:26:22    阅读次数:243
LeetCode --- Add Two Numbers
题目链接说来算是个基础题目,可是还是各种CE,各种WA,基础还是不扎实。附上代码: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *ne...
分类:其他好文   时间:2014-05-28 23:56:38    阅读次数:382
[leetcode]_Path Sum I && II
都是考查DFS。经典回溯算法,问题在于我对该类型的代码不熟悉,目前以参考别人的代码,然后加上自己的实现为主,通过类似的题目加强理解。一、给定一棵二叉树,判断是否存在从root到leaf的路径和等于给定值sum,存在返回true,否则返回false。思路:DFS。代码: 1 private b...
分类:其他好文   时间:2014-05-28 23:51:25    阅读次数:389
leetcode -- 3sum
Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen...
分类:其他好文   时间:2014-05-28 16:47:30    阅读次数:308
LeetCode Spiral Matrix
class Solution { public: vector spiralOrder(vector > &matrix) { vector ret; int cols = 0; ...
分类:其他好文   时间:2014-05-28 14:38:02    阅读次数:236
[Java]_函数传参的疑惑与思考
问题来源于leetcode上的两道题 Path Sum I && II,分别写了两个dfs。1 void dfs(TreeNode node , int sum , ArrayList curPath)2 void dfs(TreeNode node , int sum , boolean ifEx...
分类:编程语言   时间:2014-05-28 13:11:14    阅读次数:361
[leetcode]_Sum Root to Leaf Numbers
题目:计算一棵二叉树所有路径组成的数的总和。思考:也是DFS的基础应用。虽然还是套着别人的DFS框架写的,但是学习通常会经历先模拟,再创新的过程。代码: 1 private int sum = 0; 2 public int sumNumbers(TreeNode root) { 3...
分类:其他好文   时间:2014-05-28 11:13:01    阅读次数:225
[leetcode]_Best Time to Buy and Sell Stock I && II
一个系列三道题,我都不会做,google之答案。过了两道,第三道看不懂,放置,稍后继续。一、Best Time to Buy and Sell Stock I题目:一个数组表示一支股票的价格变换。要求只买卖一次,获得最大收益。思路:一开始我认为是寻找最大、最小值,但由于最大值不一定总是出现在最小值的...
分类:其他好文   时间:2014-05-28 01:21:52    阅读次数:262
【LeetCode】Implement strStr()
Implement strStr()Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.标准KMP算法。...
分类:其他好文   时间:2014-05-27 23:41:07    阅读次数:366
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!