码迷,mamicode.com
首页 >  
搜索关键字:solution    ( 11547个结果
LeetCode Length of Last Word
class Solution {public: int lengthOfLastWord(const char *s) { if (s == NULL) return 0; int mlen = 0, len = 0; bool inword = fa...
分类:其他好文   时间:2014-06-29 14:13:37    阅读次数:229
LeetCode Permutations II
class Solution { public: vector > permuteUnique(vector &num) { vector > result; if (num.size() path; dfs(n...
分类:其他好文   时间:2014-06-29 14:09:34    阅读次数:220
Leetcode Add Two Numbers
class Solution {public: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { ListNode* p = l1; ListNode* q = l2; ListNode* re...
分类:其他好文   时间:2014-06-07 03:50:49    阅读次数:218
leetcode -- 4sum
class Solution {public: vector > ret; vector subret;public: vector > fourSum(vector &num, int target) { sort(num.begin(),num.end()); ...
分类:其他好文   时间:2014-05-29 09:31:13    阅读次数:288
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 Spiral Matrix
class Solution { public: vector spiralOrder(vector > &matrix) { vector ret; int cols = 0; ...
分类:其他好文   时间:2014-05-28 14:38:02    阅读次数:236
LeetCode Spiral Matrix II
class Solution { public: vector > generateMatrix(int n) { vector > matrix; if (n (n, 0)); }...
分类:其他好文   时间:2014-05-28 09:42:14    阅读次数:233
LeedCode --- Best Time to Buy and Sell Stock
题目链接题意: find the maximum positive difference between the price on the ith day and the jth day附上代码: 1 class Solution { 2 public: 3 int maxProfit(ve...
分类:其他好文   时间:2014-05-28 03:49:45    阅读次数:307
Sqrt(x)
Implementint sqrt(int x).Compute and return the square root ofx.思路:二分查找法解决这道题class Solution {public: int sqrt(int x) { if(x1e-6) { ...
分类:其他好文   时间:2014-05-25 19:35:33    阅读次数:225
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!