1、前言

2、思路
很简单,先放进去再随机
3、代码
class Solution {
private List<Integer> list = new ArrayList<>();
public Solution(ListNode head) {
while(head != null){
list.add(head.val);
head = head.next;
}
}
public int getRandom() {
return list.get((int)(Math.random() * list.size()));
}
}
网友评论