We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://go.dev/play/p/DwZgPX8HhBs
package main import ( "fmt" "golang.design/x/reflect" ) type ListNode struct { Val int Next *ListNode } func main() { n := ListNode{Val: 1} n2 := reflect.DeepCopy(n) fmt.Printf("%+v %+v\n", n, n2) fmt.Println(n2.Next.Val) // 0 }
n.Next is nil, but becomes &ListNode{} after the deep copy.
n.Next
&ListNode{}
The text was updated successfully, but these errors were encountered:
Interesting, perhaps the recursive processing was not correct engouth.
Sorry, something went wrong.
最简单的:
var n4 *ListNode n5 := reflect.DeepCopy(n4) fmt.Println(n4, n5) // <nil> &{0 <nil>}
这里还有一个 deepCopy 的库,倒是没有这个问题,而且实现简单粗暴 https://github.com/darkgopher/darkness/blob/master/deepcopy.go
I don't yet have time to look deeper into this. Hence it is greatly welcome if there is a PR to fix this
No branches or pull requests
https://go.dev/play/p/DwZgPX8HhBs
n.Next
is nil, but becomes&ListNode{}
after the deep copy.The text was updated successfully, but these errors were encountered: