Solve for x
equation is an equation in one unknown, such as 3x-4+x=2x+6. It has exactly one =. Each side is one or more terms joined by + and -, and the first term of a side may have a - in front. A term is a whole number (12), a whole number followed by x (3x, also 0x), or just x. There are no spaces, brackets or other signs.
Return "x=N" when exactly one number N solves the equation (it is always a whole number then), "all" when every number solves it, and "none" when no number does.
Example 1
The left side is 4x - 4 and the right side is 2x + 6, so 2x is 10 and x is 5.
Example 2
Both sides are the same, whatever x is.
Example 3
The x cancels out and leaves 0 = 1.
Constraints
3 <= len(equation) <= 60- every number in the equation is between
0and9999, written without extra leading zeros
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- String to IntegerMedium
- Substrings With Every VowelMedium
- Undo the Column ReadMedium
- Valid Decimal LiteralMedium
- Zigzag ConversionMedium
- Every Smallest Bracket RepairHard
- Expand the BracesHard
- Is It a NumberHard