You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: leetcode/divide-and-conquer/282-expression-add-operators.md
+105-4Lines changed: 105 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,15 +44,116 @@ Output: []
44
44
## Thought Process {#thought-process}
45
45
46
46
1. Divide and Conquer
47
-
1. Similar to 241, we can divide the number at each position and check if there is way to get target using different operation
48
-
2. Time complexity O\(?\)
49
-
3. Space complexity O\(?\)
50
-
2. asd
47
+
1. We can divide the number at each position and check if there is way to get target using different operations
48
+
2. At each position \(after getting the value\), we recursively look at these three operations
49
+
3. If we only have +-, the computation is easier, we can move forward without worry about the previous value being used in multiply
50
+
4. Now, we need a separate variable to hold the previous value and reverse the result by subtracting previous value and then compute with right order
51
+
5. We create a separate function recur\(chars, index, value, pre, stringbuilder, target, result\) where index points to the current character and value is the current evaluated result, pre is previous number, stringbuilder holds the
52
+
6. Time complexity O\(n\*3^n\), where n^2 comes from n loops and n character in stringBuilder.toString\(\), and 3^n from 3 operators and looping for each digit
53
+
7. Space complexity O\(n^2\*3^n\), where n^2 comes from ways to break operands
0 commit comments