Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
60 lines (56 loc) · 1.25 KB

File metadata and controls

60 lines (56 loc) · 1.25 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "TwoSum.h"
#include <iostream>
#include <unordered_map>
using namespace std;
TwoSum::TwoSum(){}
void TwoSum::twoSum(int nums[], int length, int target) {
if (length <= 0)
return;
unordered_map<int, int> map;
for (int i = 0; i < length; ++i) {
int num = target - nums[i];
//map.find(num) != map.end() 判断是否存在key, 存在key,find返回key的对应迭代器,不存在返回unordered_map::end
if (map.find(num) != map.end()) {
cout << i << ',' << map[num] << endl;
return;
}
map[nums[i]] = i;
}
}
//void quickSort(int nums[], int low, int high) {
// if (low >= high)
// return;
//
// int le = low - 1, mid = low, ri = high;
// int stand = nums[ri];
// while (mid <= ri) {
// if (nums[mid] > stand) {
// int temp = nums[ri];
// nums[ri] = nums[mid];
// nums[mid] = temp;
// ri--;
// }
// else if (nums[mid] < stand) {
// int temp = nums[le+1];
// nums[le+1] = nums[mid];
// nums[mid] = temp;
// mid++;
// le++;
// }
// else {
// mid++;
// }
// }
//
// quickSort(nums, low, le);
// quickSort(nums, mid, high);
//}
//int main() {
// TwoSum twoSum;
// int nums[3] = {3,2,4};
// int length = sizeof(nums) / sizeof(nums[0]);
// twoSum.twoSum(nums, length, 6);
// for (int i = 0; i < length; i++) {
// cout << nums[i] << endl;
// }
//}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.