import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* public ListNode(int val) {
* this.val = val;
* }
* }
*/
public class Solution {
// public ListNode ReverseList (ListNode head) {
// Stack<ListNode> stack=new Stack<>();
// while(head!=null){
// stack.add(head);
// head=head.next;
// }
// ListNode tmp=stack.pop();
// ListNode arr=tmp;
// while(!stack.isEmpty()){
// tmp.next=stack.pop();
// tmp=tmp.next;
// }
// tmp.next=null;
// return arr;
// }
public ListNode ReverseList (ListNode head) {
ListNode node=null;
while(head!=null){
ListNode tmp=head.next;
head.next=node;
node=head;
head=tmp;
}
return node;
}
}