万佛请教特浓咖啡机espresso推荐# PhotoGear - 摄影器材
s*n
1 楼
这个题目我做的只能pass一个case,不知道后面的case错在哪里了。后面附上我的代码
http://www.testdome.com/for-developers/solve-question/10283?visibility=1
http://www.testdome.com/for-developers/solve-question/10283?visibility=1
#include
#include
#include
#include
#include
class TwoSum
{
public:
static std::pair findTwoSum(const std::vector& list, int
sum)
{
std::unordered_map hashed;
for(unsigned int i = 0; i < list.size(); i ++){
hashed.insert(std::pair(list[i], static_cast(i)));
}
for(auto i:hashed){
int a1 = i.first;
int a2 = sum - a1;
if(hashed.count(a2) != 0){
return std::pair(i.second, static_cast(hashed
[a2]));
}
}
return std::pair(-1, -1);
}
};
#ifndef RunTests
int main()
{
std::vector list;
list.push_back(1);
list.push_back(3);
list.push_back(5);
list.push_back(7);
list.push_back(9);
std::pair indices = TwoSum::findTwoSum(list, 12);
std::cout << indices.first << 'n' << indices.second;
}
#endif
http://www.testdome.com/for-developers/solve-question/10283?visibility=1
http://www.testdome.com/for-developers/solve-question/10283?visibility=1
#include
#include
#include
#include
#include
class TwoSum
{
public:
static std::pair
sum)
{
std::unordered_map
for(unsigned int i = 0; i < list.size(); i ++){
hashed.insert(std::pair
}
for(auto i:hashed){
int a1 = i.first;
int a2 = sum - a1;
if(hashed.count(a2) != 0){
return std::pair
[a2]));
}
}
return std::pair
}
};
#ifndef RunTests
int main()
{
std::vector
list.push_back(1);
list.push_back(3);
list.push_back(5);
list.push_back(7);
list.push_back(9);
std::pair
std::cout << indices.first << 'n' << indices.second;
}
#endif