From 8068c426885aa013c0a97a03c6c15a1c1d5e6c2b Mon Sep 17 00:00:00 2001 From: Hongyun Zhang <67003874+hongyun-robot@users.noreply.github.com> Date: Fri, 21 Jul 2023 14:47:37 +0800 Subject: [PATCH] fixed error when the list is empty (#637) * feat: Add Go code to binary search recursion under divide and conquer * style: Code comment standardization * style: modify function comment * fix: fixed error when the list is empty * Update print_utils.go * Delete print_utils_test.go --------- Co-authored-by: Yudong Jin --- codes/go/pkg/print_utils.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/codes/go/pkg/print_utils.go b/codes/go/pkg/print_utils.go index d65ebba1d..0e85a189f 100644 --- a/codes/go/pkg/print_utils.go +++ b/codes/go/pkg/print_utils.go @@ -19,6 +19,10 @@ func PrintSlice[T any](nums []T) { // PrintList Print a list func PrintList(list *list.List) { + if list.Len() == 0 { + fmt.Print("[]\n") + return + } e := list.Front() // 强转为 string, 会影响效率 fmt.Print("[")