I. What
Given an list of number (no ‘0’) and a target, combined with any operator from +
, -
, *
, /
, check if they can form into an formular which evaluated to be target.
example:
- Array:
[4, 2, 3, 1, 5, 6]
- target:
10
- should return true, as
[1, "+", 5, "+", 6, "+", 4, "-", 2, "*", 3] = 10
II. Analysis
try to put each element to be the n-th operand, followed by each operator as a potential prefix as follows:
1 | 1 2 3 4 5 |
III. Code
1 | /** |