j 今天刷的第三道题是 LeetCode 第 142 题, 跟 141 很像, 就直接贴代码了
- public static ListNode solution(ListNode head){
- List<ListNode> list=new ArrayList<>();
- if (head==null||head.next==head)return head;
- ListNode temp=head;
- while (temp!=null&&!list.contains(temp)){
- list.add(temp);
- temp=temp.next;
- }
- if (temp==null)return null;
- else {
- return temp;
- }
- }
来源: http://www.bubuko.com/infodetail-3203755.html