leetcode刷题35
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; } }