题解 | #重排链表#

重排链表

http://www.nowcoder.com/practice/3d281dc0b3704347846a110bf561ef6b

/**

  • Definition for singly-linked list.

  • class ListNode {

  • int val;
    
  • ListNode next;
    
  • ListNode(int x) {
    
  •     val = x;
    
  •     next = null;
    
  • }
    
  • } / import java.util.; public class Solution { public void reorderList(ListNode head) { if(head == null || head.next == null || head.next.next == null) return; List list = new ArrayList<>(); ListNode current = head; while (current != null) { list.add(current.val); current = current.next; } if(list.size()==1){

     }
     current = head;
     int i = 0;
     while (current != null) {
         current.val = list.get(i);
         current = current.next;
         if(current!=null){
             current.val = list.get(list.size() - 1 - i);
             current = current.next;
         }
         i++;
     }
    

    } }

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:24
大家还是用ai改吧,我心疼得要死,就当花钱买教训吧,人家直接拿完钱就跑路了
程序员小白条:简历修改700....神奇,又不是帮你面试,咋的,简历修改从双非变92了还是没实习变成有大厂实习了
点赞 评论 收藏
分享
Rena1ssanc...:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务