Analysis:
Since we need to list all the possible routes, therefore backtracking is the right choice.
Then we must ignore all the numbers begined with ‘0’ since it is illegal.
We must store the previous number when computing multiply,cursum-lastnum+curnum*lastnum
to get the right outcome
Time Complexity:
- O(2^n)
Space Complexity:
- O(n)
Code
1 | class Solution(object): |