From 09d51fd394c2754e8681b91ee572a05232c77ee8 Mon Sep 17 00:00:00 2001 From: kinsolee Date: Tue, 8 Feb 2022 22:03:54 +0800 Subject: [PATCH] fix 706: bug with edge case --- leetcode/0706.Design-HashMap/706. Design HashMap.go | 6 +++--- leetcode/0706.Design-HashMap/706. Design HashMap_test.go | 3 +++ .../content/ChapterFour/0700~0799/0706.Design-HashMap.md | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/leetcode/0706.Design-HashMap/706. Design HashMap.go b/leetcode/0706.Design-HashMap/706. Design HashMap.go index acbf36fd..2845be61 100644 --- a/leetcode/0706.Design-HashMap/706. Design HashMap.go +++ b/leetcode/0706.Design-HashMap/706. Design HashMap.go @@ -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. */ diff --git a/leetcode/0706.Design-HashMap/706. Design HashMap_test.go b/leetcode/0706.Design-HashMap/706. Design HashMap_test.go index 9ff3e200..6d83ca0d 100644 --- a/leetcode/0706.Design-HashMap/706. Design HashMap_test.go +++ b/leetcode/0706.Design-HashMap/706. Design HashMap_test.go @@ -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) diff --git a/website/content/ChapterFour/0700~0799/0706.Design-HashMap.md b/website/content/ChapterFour/0700~0799/0706.Design-HashMap.md index e941b88e..e6b44160 100755 --- a/website/content/ChapterFour/0700~0799/0706.Design-HashMap.md +++ b/website/content/ChapterFour/0700~0799/0706.Design-HashMap.md @@ -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. */