All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0201_0300.s0282_expression_add_operators.readme.md Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
282\. Expression Add Operators

Hard

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_.

Note that operands in the returned expressions **should not** contain leading zeros.

**Example 1:**

**Input:** num = "123", target = 6

**Output:** ["1\*2\*3","1+2+3"]

**Explanation:** Both "1\*2\*3" and "1+2+3" evaluate to 6.

**Example 2:**

**Input:** num = "232", target = 8

**Output:** ["2\*3+2","2+3\*2"]

**Explanation:** Both "2\*3+2" and "2+3\*2" evaluate to 8.

**Example 3:**

**Input:** num = "3456237490", target = 9191

**Output:** []

**Explanation:** There are no expressions that can be created from "3456237490" to evaluate to 9191.

**Constraints:**

*   `1 <= num.length <= 10`
*   `num` consists of only digits.
*   -231 <= target <= 231 - 1




© 2015 - 2024 Weber Informatics LLC | Privacy Policy