/* * @lc app=leetcode id=206 lang=java * * [206] Reverse Linked List */ // @lc code=start /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null, cur = head, t; while(cur != null) { t = cur.next; cur.next = prev; prev = cur; cur = t; } return prev; } } // @lc code=end