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

Sign up
Appearance settings

Commit 5e1fdfe

Browse files
update
1 parent 45200ba commit 5e1fdfe

File tree

3 files changed

+44
-25
lines changed

3 files changed

+44
-25
lines changed

‎leetcode/1.two_sum/1.TwoSum_Kris.java‎

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,22 @@
11
// Source : https://leetcode.com/problems/two-sum/
22
// Author : Kris
3-
// Date : 2020-10-08
3+
// Date : 2020-08-15
44

55
/*****************************************************************************************************
66
*
7-
* Given an array of integers nums and an integer target, return indices of the two numbers such that
8-
* they add up to target.
7+
* Given an array of integers, return indices of the two numbers such that they add up to a specific
8+
* target.
99
*
1010
* You may assume that each input would have exactly one solution, and you may not use the same
1111
* element twice.
1212
*
13-
* You can return the answer in any order.
13+
* Example:
1414
*
15-
* Example 1:
15+
* Given nums = [2, 7, 11, 15], target = 9,
1616
*
17-
* Input: nums = [2,7,11,15], target = 9
18-
* Output: [0,1]
19-
* Output: Because nums[0] + nums[1] == 9, we return [0, 1].
17+
* Because nums[0] + nums[1] = 2 + 7 = 9,
18+
* return [0, 1].
2019
*
21-
* Example 2:
22-
*
23-
* Input: nums = [3,2,4], target = 6
24-
* Output: [1,2]
25-
*
26-
* Example 3:
27-
*
28-
* Input: nums = [3,3], target = 6
29-
* Output: [0,1]
30-
*
31-
* Constraints:
32-
*
33-
* 2 <= nums.length <= 105
34-
* -109 <= nums[i] <= 109
35-
* -109 <= target <= 109
36-
* Only one valid answer exists.
3720
******************************************************************************************************/
3821

3922
class Solution {

‎leetcode/1.two_sum/1.TwoSum_henrytine.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
******************************************************************************************************/
2121

22-
#include "ac.h"
22+
#include "../inc/ac.h"
2323
class Solution {
2424
public:
2525
vector<int> twoSum(vector<int> &nums, int target) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Source : https://leetcode.com/problems/two-sum/
2+
// Author : zhangsl
3+
// Date : 2020年08月17日
4+
package main
5+
/*****************************************************************************************************
6+
*
7+
* Given an array of integers, return indices of the two numbers such that they add up to a specific
8+
* target.
9+
*
10+
* You may assume that each input would have exactly one solution, and you may not use the same
11+
* element twice.
12+
*
13+
* Example:
14+
*
15+
* Given nums = [2, 7, 11, 15], target = 9,
16+
*
17+
* Because nums[0] + nums[1] = 2 + 7 = 9,
18+
* return [0, 1].
19+
*
20+
******************************************************************************************************/
21+
//time:97 mem:14
22+
23+
func twoSum(nums []int, target int) []int {
24+
var (
25+
mp = map[int]int{}
26+
)
27+
for k,_:=range nums{
28+
mp[nums[k]] = k
29+
}
30+
for k,_:=range nums{
31+
if v,ok:=mp[target-nums[k]];ok&&v!=k{
32+
return []int{k,v}
33+
}
34+
}
35+
return []int{}
36+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /