草庐IT

currNode

全部标签

go - golang 中动态大小的数组?

这个问题在这里已经有了答案:HowtoimplementresizablearraysinGo(7个答案)关闭3年前。我想知道是否有任何方法可以创建动态大小的数组以避免下面代码中的运行时错误。错误:panic:runtimeerror:indexoutofrangeinGo代码:/***Definitionforsingly-linkedlist.*typeListNodestruct{*Valint*Next*ListNode*}*/funcnextLargerNodes(head*ListNode)[]int{vara[]intvarphainthNum:=0currNode:=h