diff --git a/E_206_ReverseLinkedList.java b/E_206_ReverseLinkedList.java new file mode 100644 index 0000000..ec7d10e --- /dev/null +++ b/E_206_ReverseLinkedList.java @@ -0,0 +1,24 @@ +/** + * 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 header=null; + while(head!=null){ + ListNode next=head.next; + head.next=header; + header=head; + head=next; + + } + return header; + } +} \ No newline at end of file