码迷,mamicode.com
首页 > 其他好文 > 详细

关于Leetcode

时间:2015-04-23 23:34:28      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

在Github上开了一个关于leetcode的repository.

如果你也有兴趣可以把你的解法通过github上传,一起印证和学习.

https://github.com/LiLane/leetcode

例子1:

class Solution {
public:
    /*  Result: 26ms
		时间复杂度:O(n)
		空间复杂度:O(n)
		Author:	Lane0x
    */
    vector<int> twoSum(vector<int> &num,int target){
        unordered_map<int,int> mapping;
        vector<int> result;
        for(int i = 0; i < num.size(); ++i)
            mapping[num[i]] = i;
        for(int i = 0; i < num.size(); ++i){
            const int gap = target - num[i];
            if(mapping.find(gap) != mapping.end() && mapping[gap] > i){
                result.push_back(i + 1);
                result.push_back(mapping[gap] + 1);
                break;
            }
        }
        return result;
    }
};


关于Leetcode

标签:

原文地址:http://blog.csdn.net/lane_l/article/details/45228091

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!