关于Leetcode

来源:互联网 发布:美股王软件 编辑:程序博客网 时间:2024/06/10 09:39

在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;    }};


0 0
原创粉丝点击