We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6bed04b commit c6a4c29Copy full SHA for c6a4c29
Dichotomy/小于 N 的最大数.md
@@ -14,7 +14,48 @@
14
15
---
16
17
-贪心 + 二分查找:详见注释。
+深度搜索优先:时间复杂度 `O n^len(target)`
18
+
19
+```go
20
+package main
21
22
+import (
23
+ "fmt"
24
+)
25
26
+var res int
27
28
+func main() {
29
+ nums := []int{2, 4, 6, 8}
30
+ target := 2411
31
+ backtrack(nums, target, 0)
32
+ fmt.Println(res)
33
+}
34
35
+func backtrack(nums []int, target, sum int) {
36
+ if sum >= target {
37
+ return
38
+ }
39
+ res = max(res, sum)
40
+ for i := range nums {
41
+ backtrack(nums, target, 10*sum+nums[i])
42
43
44
45
+func max(i, j int) int {
46
+ if i > j {
47
+ return i
48
49
+ return j
50
51
52
+```
53
54
55
56
57
58
+贪心 + 二分查找:时间复杂度 `Ologn`
59
60
```java
61
package com.example.demo.test;
0 commit comments