Solve a given equation and return the value of 'x' in the form of a string "x=#value". The equation contains only '+', '-' operation, the variable 'x' and its coefficient. You should return "No solution" if there is no solution for the equation, or "Infinite solutions" if there are infinite solutions for the equation.

If there is exactly one solution for the equation, we ensure that the value of 'x' is an integer.

&nbsp;
Example 1:

Input: equation = "x+5-3+x=6+x-2"
Output: "x=2"


Example 2:

Input: equation = "x=x"
Output: "Infinite solutions"


Example 3:

Input: equation = "2x=x"
Output: "x=0"


&nbsp;
Constraints:


	3 &lt;= equation.length &lt;= 1000
	equation has exactly one '='.
	equation consists of integers with an absolute value in the range [0, 100] without any leading zeros, and the variable 'x'.


    def solveEquation(self, equation: str) -> str:
    """ O(N)TS """
    x, y, p = 0, 0, 1
    for i in re.finditer(r"=|[+-]?\d*x|[+-]?\d+", equation):
        g = i.group()
        if g == '=':
            p = -1
        elif g[-1] == 'x':
            x += p * int(g.replace('x', '1' if len(g) == 1 or not g[-2].isdigit() else ''))
        else:
            y += -p * int(g)

    if x == 0 == y:
        return 'Infinite solutions'
    elif x == 0:
        return "No solution"
    return f'x={y // x}'
class Solution {
    public int[] simplifyEqn(String eqn){
        int prevSign = 1;
        int sumX = 0;
        int sumNums = 0;
        for(int i=0;i<eqn.length();){
            int coEff = 0;
            int j = i;
            while(j<eqn.length() && Character.isDigit(eqn.charAt(j))){
                coEff = coEff*10 + (eqn.charAt(j)-'0');
                j++;
            }
            if(j<eqn.length() && eqn.charAt(j)=='x'){
                if(i==j)
                    coEff = 1;
                sumX += prevSign*coEff;
                j++;
            }
            else{
                sumNums += prevSign*coEff; 
            }
            if(j<eqn.length() && eqn.charAt(j)=='+')
                prevSign = 1;
            else if(j<eqn.length() && eqn.charAt(j)=='-')
                prevSign = -1;
            i=++j;
        }
        return new int[] {sumX, sumNums};
    }
    public String solveEquation(String equation) {
        String[] leftNRight = equation.split("=");
        String left = leftNRight[0], right = leftNRight[1];
        int[] leftEqn = simplifyEqn(left);
        int[] rightEqn = simplifyEqn(right);
        int x = leftEqn[0]-rightEqn[0];
        int num = rightEqn[1]-leftEqn[1];
        if(x==0)
            if(num==0)
                return "Infinite solutions";
            else
                return "No solution";
        return "x="+num/x;
    }
}
    def solveEquation(self, equation: str) -> str:
    """ O(N)TS """
    x, y, p = 0, 0, 1
    for i in re.finditer(r"=|[+-]?\d*x|[+-]?\d+", equation):
        g = i.group()
        if g == '=':
            p = -1
        elif g[-1] == 'x':
            x += p * int(g.replace('x', '1' if len(g) == 1 or not g[-2].isdigit() else ''))
        else:
            y += -p * int(g)

    if x == 0 == y:
        return 'Infinite solutions'
    elif x == 0:
        return "No solution"
    return f'x={y // x}'
    def solveEquation(self, equation: str) -> str:
    """ O(N)TS """
    x, y, p = 0, 0, 1
    for i in re.finditer(r"=|[+-]?\d*x|[+-]?\d+", equation):
        g = i.group()
        if g == '=':
            p = -1
        elif g[-1] == 'x':
            x += p * int(g.replace('x', '1' if len(g) == 1 or not g[-2].isdigit() else ''))
        else:
            y += -p * int(g)

    if x == 0 == y:
        return 'Infinite solutions'
    elif x == 0:
        return "No solution"
    return f'x={y // x}'
Solve the Equation