138. 复制带随机指针的链表

Map
主要需要建立next 和random 随机节点的关联
package mainimport "unsafe"type Node struct {Val intNext *NodeRandom *Node}func copyRandomList(head *Node) *Node {curr := headm := make(map[uintptr]*Node)for curr!=nil{node :=&Node{Val:curr.Val}m[uintptr(unsafe.Pointer(curr))]=nodecurr = curr.Next}curr = headfor curr!=nil{node := m[uintptr(unsafe.Pointer(curr))]node.Next = m[uintptr(unsafe.Pointer(curr.Next))]node.Random =m[uintptr(unsafe.Pointer(curr.Random))]curr = curr.Next}return m[uintptr(unsafe.Pointer(head))]}func main() {}

