<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:
    ListNode* doubleIt(ListNode* head) {
        ListNode* t = head;
        vector<int> ans;
        while(t){
            ans.push_back(t->val);
            t = t->next;
        }
        reverse(ans.begin(),ans.end());
        vector<int> actualans;
        int y = 0;
        bool out = true;
        for(int i=0;i<ans.size();i++){
            int s = (ans[i] * 2);
            bool flag = true;

            if(s + y <= 9){
                actualans.push_back(s + y);
                y = 0;
            }
            else{
                actualans.push_back((s+y)%10);
                y = (s+y)/10;
                flag = false;
            }
            if(flag == true) out = true;
            else out = false;
        }
        if(out == false && y > 0) actualans.push_back(y);
        reverse(actualans.begin(),actualans.end());
        t = head;
        int aqua = -1;
        for(int i=0;i<actualans.size() && t;i++){
            t->val = actualans[i];
            if(t->next != NULL) t = t->next;
            else{
                aqua = i;
                break;
            }
        }
        
        for(int i=aqua+1;i<actualans.size();i++){
            ListNode* naya = new ListNode(actualans[i]);
            t->next = naya;
            t = t->next;
        }
        return head;


        
    }
};
82845