Merge pull request #226 from kinsolee/master

fix 706:  bug with edge case
This commit is contained in:
halfrost
2022-03-01 20:56:27 -08:00
committed by GitHub
3 changed files with 8 additions and 5 deletions

View File

@ -1,6 +1,6 @@
package leetcode
const Len int = 100000
const Len int = 10000
type MyHashMap struct {
content [Len]*HashNode
@ -41,9 +41,9 @@ func (N *HashNode) Remove(key int) *HashNode {
return p
}
if N.next != nil {
return N.next.Remove(key)
N.next = N.next.Remove(key)
}
return nil
return N
}
/** Initialize your data structure here. */

View File

@ -13,6 +13,9 @@ func Test_Problem706(t *testing.T) {
fmt.Printf("Contains 7 = %v\n", obj.Get(7))
param1 := obj.Get(100)
fmt.Printf("param1 = %v\n", param1)
obj.Remove(100007)
param1 = obj.Get(7)
fmt.Printf("param1 = %v\n", param1)
obj.Remove(7)
param1 = obj.Get(7)
fmt.Printf("param1 = %v\n", param1)

View File

@ -98,9 +98,9 @@ func (N *HashNode) Remove(key int) *HashNode {
return p
}
if N.next != nil {
return N.next.Remove(key)
N.next = N.next.Remove(key)
}
return nil
return N
}
/** Initialize your data structure here. */