Medium

Quiz

#640 Solve the Equation

APPROACH

Given a linear equation string involving 'x', constants, '+', and '-', solve for x and return "x=#value". If no value of x satisfies the equation, return "No solution". If every value works, return "Infinite solutions". When a unique integer solution exists, return it in the format "x=#value".

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"
1 of 4
1:00

What is the optimal approach for this problem?