Skip to content

Commit 70a5f33

Browse files
committed
fix pullrequests/two_sum
1 parent 0858102 commit 70a5f33

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

pullrequests/two_sum/step1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package twosum
66
77
また同じ要素を2回使うのを避けるために、毎回追加する前に対応する要素がないかを確認してから追加するようにしました。
88
*/
9-
func twoSum_step1(nums []int, target int) []int {
9+
func twoSumStep1(nums []int, target int) []int {
1010
m := make(map[int]int)
1111
for i, n := range nums {
1212
if j, ok := m[target-n]; ok {

pullrequests/two_sum/step2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ GoogleのGoスタイルガイドには変数名に型名を使うのは良くな
1313
- https://github.com/seal-azarashi/leetcode/pull/11#discussion_r1672537855
1414
- https://github.com/sendahuang14/leetcode/pull/11#discussion_r1702393602
1515
*/
16-
func twoSum_step2(nums []int, target int) []int {
16+
func twoSumStep2(nums []int, target int) []int {
1717
numsMap := make(map[int]int)
1818
for i, n := range nums {
1919
if j, ok := numsMap[target-n]; ok {

pullrequests/two_sum/step3.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//lint:file-ignore U1000 Ignore all unused code
2+
package twosum
3+
4+
func twoSumStep3(nums []int, target int) []int {
5+
numToIndex := make(map[int]int)
6+
for i, n := range nums {
7+
if j, ok := numToIndex[target-n]; ok {
8+
return []int{i, j}
9+
}
10+
numToIndex[n] = i
11+
}
12+
return nil // 本来ならerrorを返したい
13+
}

0 commit comments

Comments
 (0)