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 067f198

Browse files
rename java
1 parent e871d4a commit 067f198

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+10
-6
lines changed

‎.DS_Store‎

0 Bytes
Binary file not shown.

‎.gitignore‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ build/
3434

3535
### log ###
3636
*.log
37-
*.gz
37+
*.gz
38+
39+
.DS_Store
40+
src/.DS_Store
41+
src/main/.DS_Store

‎go/1.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ import "fmt"
88
* 思路1:2次哈希求解:将数组放入散列表,遍历散列表,通过target-key得出匹配数组,并且判断非自身元素,返回数组,时间复杂度 O(n)
99
* 思路2[runtime beats(最优解)]:1次哈希求解:在遍历 num 数组,如果哈希表不包含 target - num[i] ,则将 num[i], i 放入哈希表,如果包含则直接返回 [hash[num[i], i]] 下标
1010
*/
11-
func twoSum(nums []int, target int) []int {
11+
func twoSum(nums []int, target int) []int {
1212
hashMap := map[int]int{}
1313
for i := 0; i < len(nums); i++ {
14-
p, ok := hashMap[target-nums[i]]
14+
p, ok := hashMap[target-nums[i]]
1515
if ok {
1616
return []int{p, i}
1717
}
1818
hashMap[nums[i]] = i
1919
}
2020
return nil
21-
}
21+
}
2222

2323
func main() {
24-
// 声明 slice
24+
// 声明 slice
2525
nums := []int{2, 7, 11, 15}
2626
target := 9
2727
p := twoSum(nums, target)
2828
fmt.Println("p value:", p)
29-
}
29+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
(0)

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