翻转链表

/**

  • Definition for ListNode.
  • public class ListNode {
  • int val;
    
  • ListNode next;
    
  • ListNode(int val) {
    
  •     this.val = val;
    
  •     this.next = null;
    
  • }
    
  • }
    /
    public class Solution {
    /
    *
    • @param head: The head of linked list.
    • @return: The new head of reversed linked list.
      */
      public ListNode reverse(ListNode head){
      // write your code here
      if (head == null || head.next == null)
      return head;
      ListNode second = head.next;
      head.next = null;
      ListNode res = reverse(second);
      second.next = head;
      return res;
      }
      }
posted @ 2017-08-22 01:59  逸文皓  阅读(84)  评论(0编辑  收藏  举报