题目:

单链表的逆转

 

有解题思路代码很好写,下面的图是C语言的的,但是一看就可以明白。来源:https://www.jianshu.com/p/4664af99b597

 leetcode206 单链表逆转

 

leetcode206 单链表逆转

 

 leetcode206 单链表逆转

代码:

class Solution {
    public ListNode reverseList(ListNode head) {
        if (head == null)
            return null;
        else if (head.next == null)
            return head;
        else
        {   
            ListNode a = null;
            ListNode s = head;
            while(head != null)
            {   
                head = head.next;
                s.next = a;
                a = s;
                s = head;
            }
            return a;
        }

        
    }
}

 

相关文章:

  • 2022-01-04
  • 2022-12-23
  • 2021-09-30
猜你喜欢
  • 2021-10-16
  • 2021-12-01
  • 2021-07-07
  • 2022-12-23
  • 2020-02-25
  • 2022-12-23
  • 2021-11-19
相关资源
相似解决方案