640. Solve the Equation Medium
1/**
2 * [640] Solve the Equation
3 *
4 * 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.
5 * If there is exactly one solution for the equation, we ensure that the value of 'x' is an integer.
6 *
7 * Example 1:
8 *
9 * Input: equation = "x+5-3+x=6+x-2"
10 * Output: "x=2"
11 *
12 * Example 2:
13 *
14 * Input: equation = "x=x"
15 * Output: "Infinite solutions"
16 *
17 * Example 3:
18 *
19 * Input: equation = "2x=x"
20 * Output: "x=0"
21 *
22 *
23 * Constraints:
24 *
25 * 3 <= equation.length <= 1000
26 * equation has exactly one '='.
27 * equation consists of integers with an absolute value in the range [0, 100] without any leading zeros, and the variable 'x'.
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/solve-the-equation/
33// discuss: https://leetcode.com/problems/solve-the-equation/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn solve_equation(equation: String) -> String {
39 String::new()
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_640() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.