mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 10:26:27 +08:00
fix(go): fix go code , refer to @joengtou @wcig @shenjq (#992)
This commit is contained in:
parent
406eed82a3
commit
d0f4fa69a6
3 changed files with 6 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue