241. Different Ways to Add Parentheses Medium
1/**
2 * [241] Different Ways to Add Parentheses
3 *
4 * Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order.
5 * The test cases are generated such that the output values fit in a 32-bit integer and the number of different results does not exceed 10^4.
6 *
7 * Example 1:
8 *
9 * Input: expression = "2-1-1"
10 * Output: [0,2]
11 * Explanation:
12 * ((2-1)-1) = 0
13 * (2-(1-1)) = 2
14 *
15 * Example 2:
16 *
17 * Input: expression = "2*3-4*5"
18 * Output: [-34,-14,-10,-10,10]
19 * Explanation:
20 * (2*(3-(4*5))) = -34
21 * ((2*3)-(4*5)) = -14
22 * ((2*(3-4))*5) = -10
23 * (2*((3-4)*5)) = -10
24 * (((2*3)-4)*5) = 10
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= expression.length <= 20
30 * expression consists of digits and the operator '+', '-', and '*'.
31 * All the integer values in the input expression are in the range [0, 99].
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/different-ways-to-add-parentheses/
37// discuss: https://leetcode.com/problems/different-ways-to-add-parentheses/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn diff_ways_to_compute(expression: String) -> Vec<i32> {
43 vec![]
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_241() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.