Explore the solution
Log in or sign up to explore the explanation and learn how to solve this problem.
Log in or sign up to explore the explanation and learn how to solve this problem.
/*Definition of singly linked list:struct ListNode{ int val; ListNode *next; ListNode() { val = 0; next = NULL; } ListNode(int data1) { val = data1; next = NULL; } ListNode(int data1, ListNode *next1) { val = data1; next = next1; }};*/ class Solution {public: ListNode* reverseList(ListNode* head) { }};Input: