Search⌘ K
AI Features

Solution: Different Ways to Add Parentheses

C# solution for the Different Ways to Add Parentheses problem using the Dynamic Programming pattern.

Statement

Given a string expression representing a valid arithmetic expression made of non negative integers and the binary operators +, -, and *, return all possible results from computing the expression by inserting parentheses in every possible way.

The returned list may be in any order, and duplicate results are allowed if different parenthesizations produce the same value.

Note: The input contains only numbers and the operators +, -, and *, and the numbers are written without an explicit sign.

Constraints:

  • 11 \leq expression.length ...