fix(go): fix go code , refer to @joengtou @wcig @shenjq (#992)

pull/996/head
Reanon 11 months ago committed by GitHub
parent 406eed82a3
commit d0f4fa69a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,7 @@ func preOrderII(root *TreeNode, res *[][]*TreeNode, path *[]*TreeNode) {
*path = append(*path, root) *path = append(*path, root)
if root.Val.(int) == 7 { if root.Val.(int) == 7 {
// 记录解 // 记录解
*res = append(*res, *path) *res = append(*res, append([]*TreeNode{}, *path...))
} }
preOrderII(root.Left, res, path) preOrderII(root.Left, res, path)
preOrderII(root.Right, res, path) preOrderII(root.Right, res, path)

@ -41,7 +41,7 @@ func (m *hashMapChaining) hashFunc(key int) int {
/* 负载因子 */ /* 负载因子 */
func (m *hashMapChaining) loadFactor() float64 { func (m *hashMapChaining) loadFactor() float64 {
return float64(m.size / m.capacity) return float64(m.size) / float64(m.capacity)
} }
/* 查询操作 */ /* 查询操作 */
@ -66,9 +66,9 @@ func (m *hashMapChaining) put(key int, val string) {
} }
idx := m.hashFunc(key) idx := m.hashFunc(key)
// 遍历桶,若遇到指定 key ,则更新对应 val 并返回 // 遍历桶,若遇到指定 key ,则更新对应 val 并返回
for _, p := range m.buckets[idx] { for i := range m.buckets[idx] {
if p.key == key { if m.buckets[idx][i].key == key {
p.val = val m.buckets[idx][i].val = val
return return
} }
} }

@ -88,6 +88,7 @@ func (m *hashMapOpenAddressing) put(key int, val string) {
// 若遇到指定 key ,则更新对应 val // 若遇到指定 key ,则更新对应 val
if m.buckets[j].key == key { if m.buckets[j].key == key {
m.buckets[j].val = val m.buckets[j].val = val
return
} }
} }
} }

Loading…
Cancel
Save