Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Latest commit

 

History

History
executable file
·
21 lines (14 loc) · 598 Bytes

File metadata and controls

executable file
·
21 lines (14 loc) · 598 Bytes

题目

Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value.

Examples:

"123", 6 -> ["1+2+3", "1*2*3"]
"232", 8 -> ["2*3+2", "2+3*2"]
"105", 5 -> ["1*0+5","10-5"]
"00", 0 -> ["0+0", "0-0", "0*0"]
"3456237490", 9191 -> []

Credits:Special thanks to @davidtan1890 for adding this problem and creating all test cases.

解题思路

见程序注释