Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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) {
- ListNode prev = null;
- while (head != null) {
- ListNode temp = head.next;
- head.next = prev;
- prev = head;
- head = temp;
- }
- return prev;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement