<p>Solve a given equation and return the value of <code>&#39;x&#39;</code> in the form of a string <code>&quot;x=#value&quot;</code>. The equation contains only <code>&#39;+&#39;</code>, <code>&#39;-&#39;</code> operation, the variable <code>&#39;x&#39;</code> and its coefficient. You should return <code>&quot;No solution&quot;</code> if there is no solution for the equation, or <code>&quot;Infinite solutions&quot;</code> if there are infinite solutions for the equation.</p>

<p>If there is exactly one solution for the equation, we ensure that the value of <code>&#39;x&#39;</code> is an integer.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> equation = &quot;x+5-3+x=6+x-2&quot;
<strong>Output:</strong> &quot;x=2&quot;
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> equation = &quot;x=x&quot;
<strong>Output:</strong> &quot;Infinite solutions&quot;
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> equation = &quot;2x=x&quot;
<strong>Output:</strong> &quot;x=0&quot;
</pre>

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

<ul>
	<li><code>3 &lt;= equation.length &lt;= 1000</code></li>
	<li><code>equation</code> has exactly one <code>&#39;=&#39;</code>.</li>
	<li><code>equation</code> consists of integers with an absolute value in the range <code>[0, 100]</code> without any leading zeros, and the variable <code>&#39;x&#39;</code>.</li>
	<li>The input is generated that if there is a single solution, it will be an integer.</li>
</ul>

class Solution:
    def solveEquation(self, equation: str) -> str:
        
        left, right = equation.split('=')
        left_side, right_side = 0, 0

        # solving for left side equation
        i, n = 0, len(left)
        while i < n:
            curr = ""
            if left[i] in ['+', '-']:
                curr += left[i]
                i += 1
            
            while i < n and left[i].isdigit():
                curr += left[i]
                i += 1

            # for x literals, i.e. only x, -x or +x
            if curr in ["", "-", "+"]:
                curr += "1"

            curr = int(curr)

            if i < n and left[i] == 'x':
                left_side += curr
                i += 1
            else:
                right_side -= curr
        


        # solving for right side equation
        i, n = 0, len(right)
        while i < n:
            curr = ""
            if right[i] in ['+', '-']:
                curr += right[i]
                i += 1
            
            while i < n and right[i].isdigit():
                curr += right[i]
                i += 1


            # for x literals:
            if curr in ["", "-", "+"]:
                curr += "1"

            curr = int(curr)

            if i < n and right[i] == 'x':
                left_side -= curr
                i += 1
            else:
                right_side += curr
            

        # "x=x", 0 = 0
        if left_side == 0 and right_side == 0:
            return "Infinite solutions"
        
        # x-x=1, 0 = 1
        if left_side == 0:
            return "No solution"
        
        
        # in question it is written that:
        # we ensure that the value of 'x' is an integer
        # meaning left_side >= right_side
        right_side = right_side // left_side
        return f'x={right_side}'
16400