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 a64103b

Browse files
go: 1
1 parent 53cd4e9 commit a64103b

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

‎CONTRIBUTING.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ All solutions of LeetCode, must be created in package of `codes`.
2929

3030
### Python
3131

32-
- Class Name: Start with `_`, then spell problem number of LeetCode.
32+
- Python File Name: Start with `_`, then spell problem number of LeetCode.
3333
- Method Name: Initial in lowercase, then spell with `_`, if method name have more than one word.
3434

3535
### Go
3636

37-
- Class Name: Start with `_`, then spell problem number of LeetCode.
37+
- Go File Name: Start with `_`, then spell problem number of LeetCode.
3838
- Method Name: Initial in lowercase, then follow hump format.
3939

40+
## Commit style
41+
42+
- Specify commit prefix based on language, such as `java:``python:` and `go:`.
43+
4044

4145

4246

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ You can also ask for problem solving ideas and discuss in GitHub issues directly
878878

879879
| # | Title | Solutions | Difficulty | Tag
880880
|-----|----------------|:---------------:|:--------:|:-------------:
881-
|1|[Two Sum](https://leetcode.com/problems/two-sum/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/hash_table/_1.java) & Python |Easy| Array
881+
|1|[Two Sum](https://leetcode.com/problems/two-sum/description/)|[Java](../master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/hash_table/_1.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/_1.go) |Easy| Array
882882
|7|[Reverse Integer](https://leetcode.com/problems/reverse-integer/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/strings/_7.java) & Python |Easy| Strings
883883
|8|[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/strings/_8.java) & Python |Medium| Strings
884884
|13|[Roman to Integer](https://leetcode.com/problems/roman-to-integer/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/math/_13.java) & Python |Easy| Math
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package easy_collection
2+
3+
/**
4+
* 1. Two Sum
5+
* <p>
6+
* Given an array of integers, return indices of the two numbers such that they add up to a specific target.
7+
* <p>
8+
* You may assume that each input would have exactly one solution, and you may not use the same element twice.
9+
* <p>
10+
* Example:
11+
* <p>
12+
* Given nums = [2, 7, 11, 15], target = 9,
13+
* <p>
14+
* Because nums[0] + nums[1] = 2 + 7 = 9,
15+
* <p>
16+
* return [0, 1].
17+
*/
18+
19+
func twoSum(nums []int, target int) []int {
20+
if len(nums) < 1 {
21+
return []int{}
22+
}
23+
24+
numAndIndexMap := make(map[int]int)
25+
for i, n := range nums {
26+
remain := target - n
27+
if index, ok := numAndIndexMap[remain]; ok {
28+
return []int{index, i}
29+
}
30+
numAndIndexMap[n] = i
31+
}
32+
return []int{}
33+
}

0 commit comments

Comments
(0)

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