<p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>

<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example.png" style="width: 401px; height: 81px;" />
<pre>
<strong>Input:</strong> head = [1,8,9]
<strong>Output:</strong> [3,7,8]
<strong>Explanation:</strong> The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example2.png" style="width: 401px; height: 81px;" />
<pre>
<strong>Input:</strong> head = [9,9,9]
<strong>Output:</strong> [1,9,9,8]
<strong>Explanation:</strong> The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998. 
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in the list is in the range <code>[1, 10<sup>4</sup>]</code></li>
	<li><font face="monospace"><code>0 &lt;= Node.val &lt;= 9</code></font></li>
	<li>The input is generated such that the list represents a number that does not have leading zeros, except the number <code>0</code> itself.</li>
</ul>

class Solution {
public:
    void helper(ListNode* h1,ListNode* h2,ListNode* &nh){
        if(h2->next == NULL){
            nh = h2;
            h2->next = h1;
             return;
        }
        helper(h1->next,h2->next,nh);
        h2->next = h1;
    }
    ListNode* reverseList(ListNode* head) {
        ListNode* nh = NULL;
        if(head == NULL || head->next == NULL) return head;
        ListNode* h1 = head;
        ListNode* h2 = head->next;
        helper(h1,h2,nh);
        head->next = NULL;
        return nh;
        
    }
    ListNode* doubleIt(ListNode* head) {
        string ans = "";
        ListNode* temp = head;
        while(temp){
            ans+=to_string(temp->val);
            temp = temp->next;
        }
        temp = head;
        int i = ans.length() - 1;
        while(temp){
            temp->val = (ans[i] - '0');
            i--;
            temp = temp->next;
        }
        temp = head;
        int c = 0;
        ListNode* ptr;
        while(temp){
            int x = temp->val;
            x*=2;
            temp->val = x%10 + c;
            c = x/10;
            if(temp && temp->next == NULL) ptr = temp;
            temp = temp->next;
        }

        if(c != 0){
            ListNode* q = new ListNode(c);
            ptr->next = q;
        }

        return reverseList(head);
       

    }
};

 // long long x = 2*stol(ans);
        // str = to_string(x);
        // cout<<endl<<str;
        // ListNode* h = new ListNode(-1);
        // temp = h;
        // ListNode* curr;
        // for(int i = 0;i<str.length();i++){
        //     int val = str[i] - '0';
        //     ListNode* t = new ListNode(val);
        //     temp->next = t;
        //     temp = t;
        // }

        // return h->next;
36085