1234567891011121314151617181920212223242526272829303132 |
- type Solution struct {
- arr []int
- n int
- }
- func Constructor(head *ListNode) (sol Solution) {
- for curr := head; curr != nil; curr = curr.Next {
- sol.arr = append(sol.arr, curr.Val)
- sol.n++
- }
- return
- }
- func (this *Solution) GetRandom() int {
- return this.arr[rand.Intn(this.n)]
- }
|