Tap here to switch tabs
Problem
Submissions

Problem: Solve the Equation

med
30 min
Try to solve the Solve the Equation problem.

Statement

Given a string equation representing a linear equation, solve the equation and return the value of x as a string.

The result should be formatted as follows:

  • If the equation has a single unique solution, return "x=#", where # represents the integer value of x.

  • If the equation has infinitely many solutions, return "Infinite solutions".

  • If the equation has no solution, return "No solution".

Constraints:

  • 3≤3 \leq equation.length ≤1000\leq 1000

  • equation has exactly one '='.

  • equation consists of integers with an absolute value in the range [0,100][0, 100] without any leading zeros, and the variable 'x'.

  • The input is generated such that if there is a single solution, it will be an integer.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Solve the Equation

med
30 min
Try to solve the Solve the Equation problem.

Statement

Given a string equation representing a linear equation, solve the equation and return the value of x as a string.

The result should be formatted as follows:

  • If the equation has a single unique solution, return "x=#", where # represents the integer value of x.

  • If the equation has infinitely many solutions, return "Infinite solutions".

  • If the equation has no solution, return "No solution".

Constraints:

  • 3≤3 \leq equation.length ≤1000\leq 1000

  • equation has exactly one '='.

  • equation consists of integers with an absolute value in the range [0,100][0, 100] without any leading zeros, and the variable 'x'.

  • The input is generated such that if there is a single solution, it will be an integer.