<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>

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
 static const bool Booster = [](){
    std::ios_base::sync_with_stdio(false);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
    return true;
}();

inline bool is_digit(char c) {
    return (c >= '0') && (c <= '9');
}

bool Solve = [](){
    std::ofstream out("user.out");
    for (std::string s; std::getline(std::cin, s);) {
        std::stack<char> st;
        int carry = 0;
        for (int i = s.size() - 2; i > 0; i -= 2) {
            int old_val = s[i] - '0';
            int new_val = 2 * old_val + carry;
            carry = new_val / 10;
            new_val = new_val % 10;
            st.push(new_val + '0');
            // if (is_digit(s[i])) {
            // }
        }
        out << "[";
        if (carry > 0) {
            out << carry << ",";
        }
        while (st.size() > 1) {
            out << st.top() << ",";
            st.pop();
        }
        out << st.top() << "]\n";
    }
    out.flush();
    exit(0); 
    return true;
}();

class Solution {
public:
    ListNode* doubleIt(ListNode* head) {
        int len=0;
        ListNode* temp=head;
        stack<int>st,st2;
        while(temp!=NULL){
st.push(temp->val);
temp=temp->next;
++len;
        }
        temp=head;
        int carry=0;

        while(!st.empty()){
int num=st.top()*2+carry;
st.pop();
carry=num/10;
st2.push(num%10);


        }
        if(carry!=0){st2.push(carry);}
        
       
        while(!st2.empty()){
temp->val=st2.top();
st2.pop();
if(st2.size()==1&&temp->next==NULL){temp->next=new ListNode(0);}
temp=temp->next;
        }
   return head; }
};
11035