public class Solution {

public ListNode reverseList(ListNode head) {

Stack<ListNode> stack = new Stack<ListNode>();

ListNode node = head;

```
if(node == null){
return null;
}
while(node.next != null){
stack.push(node.next);
node = node.next;
}
node = head;
while(!stack.empty()){
node.next = stack.pop();
node = node.next;
}
node.next = null;
return head;
}
```

}