Class Solution
java.lang.Object
g0601_0700.s0640_solve_the_equation.Solution
640 - Solve the Equation.<p>Medium</p>
<p>Solve a given equation and return the value of <code>'x'</code> in the form of a string <code>"x=#value"</code>. The equation contains only <code>'+'</code>, <code>'-'</code> operation, the variable <code>'x'</code> and its coefficient. You should return <code>"No solution"</code> if there is no solution for the equation, or <code>"Infinite solutions"</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>'x'</code> is an integer.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> equation = “x+5-3+x=6+x-2”</p>
<p><strong>Output:</strong> “x=2”</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> equation = “x=x”</p>
<p><strong>Output:</strong> “Infinite solutions”</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> equation = “2x=x”</p>
<p><strong>Output:</strong> “x=0”</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 <= equation.length <= 1000</code></li>
<li><code>equation</code> has exactly one <code>'='</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>'x'</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
solveEquation
-