2232. Minimize Result by Adding Parentheses to Expression
2232. Minimize Result by Adding Parentheses to Expression
Description
You are given a 0-indexed  string expression of the form "<num1>+<num2>" where <num1> and <num2> represent positive integers.
Add a pair of parentheses to expression such that after the addition of parentheses, expression is a valid  mathematical expression and evaluates to the smallest  possible value. The left parenthesis must  be added to the left of '+' and the right parenthesis must  be added to the right of '+'.
Return expression after adding a pair of parentheses such that expression evaluates to the smallest  possible value. If there are multiple answers that yield the same result, return any of them.
The input has been generated such that the original value of expression, and the value of expression after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.
Example 1:
1  | Input: expression = "247+38"  | 
Example 2:
1  | Input: expression = "12+34"  | 
Example 3:
1  | Input: expression = "999+999"  | 
Constraints:
3 <= expression.length <= 10expressionconsists of digits from'1'to'9'and'+'.expressionstarts and ends with digits.expressioncontains exactly one'+'.- The original value of 
expression, and the value ofexpressionafter adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer. 
Hints/Notes
- 2025/04/19 Q3
 - string
 - Leetcode solution
 
Solution
Language: C++
1  | class Solution {  |