282. Expression Add Operators Hard

@problem@discussion
#Math#String#Backtracking



1/**
2 * [282] Expression Add Operators
3 *
4 * Given a string num that contains only digits and an integer target, return all possibilities to insert the binary operators '+', '-', and/or '*' between the digits of num so that the resultant expression evaluates to the target value.
5 * Note that operands in the returned expressions should not contain leading zeros.
6 *  
7 * Example 1:
8 * 
9 * Input: num = "123", target = 6
10 * Output: ["1*2*3","1+2+3"]
11 * Explanation: Both "1*2*3" and "1+2+3" evaluate to 6.
12 * 
13 * Example 2:
14 * 
15 * Input: num = "232", target = 8
16 * Output: ["2*3+2","2+3*2"]
17 * Explanation: Both "2*3+2" and "2+3*2" evaluate to 8.
18 * 
19 * Example 3:
20 * 
21 * Input: num = "3456237490", target = 9191
22 * Output: []
23 * Explanation: There are no expressions that can be created from "3456237490" to evaluate to 9191.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= num.length <= 10
29 * 	num consists of only digits.
30 * 	-2^31 <= target <= 2^31 - 1
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/expression-add-operators/
36// discuss: https://leetcode.com/problems/expression-add-operators/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn add_operators(num: String, target: i32) -> Vec<String> {
42        vec![]
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_282() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.