We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Solution{ public: vector twosum(vector& nums,int target) { int i, sum; vector results; map<int, int> hmap; for(i=0; i<nums.size(); i++){ if(!hmap.count(nums[i])){ hmap.insert(pair<int, int>(nums[i], i)); } if(hmap.count(target-nums[i])){ int n=hmap[target-nums[i]]; if(n<i){ results.push_back(n+1); results.push_back(i+1); //cout<<n+1<<", "<<i+1<<endl; return results; }
} } }
}; 重点学习掌握了map 与vector 优化程序执行时间
The text was updated successfully, but these errors were encountered:
No branches or pull requests
class Solution{
public:
vector twosum(vector& nums,int target)
{
int i, sum;
vector results;
map<int, int> hmap;
for(i=0; i<nums.size(); i++){
if(!hmap.count(nums[i])){
hmap.insert(pair<int, int>(nums[i], i));
}
if(hmap.count(target-nums[i])){
int n=hmap[target-nums[i]];
if(n<i){
results.push_back(n+1);
results.push_back(i+1);
//cout<<n+1<<", "<<i+1<<endl;
return results;
}
};
重点学习掌握了map 与vector 优化程序执行时间
The text was updated successfully, but these errors were encountered: