1/**2* Definition for singly-linked list. public class ListNode { int val; ListNode next; ListNode() {}3* ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val;4* this.next = next; } }5*/6class Solution {7public ListNode reverseList(ListNode head) {89if (head == null || head.next == null) return head;1011ListNode curr = head;12ListNode temp = null, next = curr.next;13curr.next = null;1415while (curr != null && next != null) {16// before cutting off link between next & its next, save next.next17temp = next.next;18// let next point to curr19next.next = curr;2021curr = next;22next = temp;23}2425return curr;26}27}