解题思路:
蛮力循环

提交代码:

class Solution {
    public void reorderList(ListNode head) {
    	if(head==null||head.next==null||head.next.next==null)	return;
    	
    	int len=1;
    	ListNode p1=head,p2=head;
    	while(p2.next!=null) {
    		p2=p2.next;
    		len++;
    	}
    	ListNode tmp=head.next;
    	p1.next=p2;
    	p2.next=tmp;
    	len-=2;
    	while(len>0) {
    		p1=p2.next;
    		p2=p1;
    		for(int i=1;i<len;i++)
    			p2=p2.next;
    		tmp=p1.next;
    		p1.next=p2;
    		p2.next=tmp;
    		len-=2;
    	}
    p2.next=null;
    }
}

运行结果:
【leetcode】143.(Medium)Reorder List

相关文章:

  • 2021-05-27
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-05-31
猜你喜欢
  • 2021-12-06
  • 2021-07-31
  • 2021-07-29
  • 2021-07-17
  • 2021-11-09
  • 2021-12-19
  • 2021-08-15
相关资源
相似解决方案