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

This commit is contained in:
Reanon 2023-12-16 18:52:28 +08:00 committed by GitHub
parent 406eed82a3
commit d0f4fa69a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View file

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

View file

@ -41,7 +41,7 @@ func (m *hashMapChaining) hashFunc(key int) int {
/* 负载因子 */
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)
// 遍历桶,若遇到指定 key ,则更新对应 val 并返回
for _, p := range m.buckets[idx] {
if p.key == key {
p.val = val
for i := range m.buckets[idx] {
if m.buckets[idx][i].key == key {
m.buckets[idx][i].val = val
return
}
}

View file

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