From 28058028159bc15a70d77fd3b60a3c92d23108cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B1=89=E5=8D=BF?= <15176331678@163.com> Date: Mon, 10 Jun 2019 17:59:07 +0800 Subject: [PATCH 1/5] =?UTF-8?q?new=20dir=20=E5=AE=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Recursion/\345\256\266/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "Recursion/\345\256\266/.keep" diff --git "a/Recursion/\345\256\266/.keep" "b/Recursion/\345\256\266/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 374df7db407bd1a80e15ec92a8188eb7bc0507c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B1=89=E5=8D=BF?= <15176331678@163.com> Date: Mon, 10 Jun 2019 18:06:59 +0800 Subject: [PATCH 2/5] 1112231 --- "Recursion/\345\256\266/\345\256\266_46" | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "Recursion/\345\256\266/\345\256\266_46" diff --git "a/Recursion/\345\256\266/\345\256\266_46" "b/Recursion/\345\256\266/\345\256\266_46" new file mode 100644 index 0000000..a5a25d7 --- /dev/null +++ "b/Recursion/\345\256\266/\345\256\266_46" @@ -0,0 +1,32 @@ +``` +/** + * 作者:家 + * 思路:回溯,循环+递归,用一个Map记录访问过的元素即可 + * 时间复杂度:O(n^2)?不是很确定,用了Map可以保证获取重复元素时为O(1) + * 空间复杂度:O(n),递归最多到n层,加上n长度的Map + */ + func permute(nums []int) [][]int { + l := len(nums) + if l == 0 { + return [][]int{} + } + var dfs func([]int) + have := map[int]bool{} + re := [][]int{} + dfs = func(r []int) { + if len(r) == l { + re = append(re,append([]int{},r...)) + return + } + for i:=0;i Date: Mon, 10 Jun 2019 18:12:18 +0800 Subject: [PATCH 3/5] 12312312313 --- "Recursion/\345\256\266/\345\256\266_77.md" | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "Recursion/\345\256\266/\345\256\266_77.md" diff --git "a/Recursion/\345\256\266/\345\256\266_77.md" "b/Recursion/\345\256\266/\345\256\266_77.md" new file mode 100644 index 0000000..e2ba412 --- /dev/null +++ "b/Recursion/\345\256\266/\345\256\266_77.md" @@ -0,0 +1,23 @@ +``` +/** + * 作者:家 + * 思路:回溯,循环+递归标配 + * 时间复杂度:O(n*k)?不是很确定,循环n次(递减的等差数列)*递归k次 + * 空间复杂度:O(k),递归最多到k层 + */ +func combine(n int, k int) [][]int { + re := [][]int{} + var dfs func(int,[]int) + dfs = func(index int,r []int) { + if len(r) == k { + re = append(re,append([]int{},r...)) + return + } + for i:=index;i<=n;i++ { + dfs(i+1,append(r,i)) + } + } + dfs(1,[]int{}) + return re +} +``` \ No newline at end of file -- Gitee From 30eeb7793a2115999a89a93580406ad6bc2b7d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B1=89=E5=8D=BF?= <15176331678@163.com> Date: Mon, 10 Jun 2019 18:12:43 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6Recursion/=E5=AE=B6/=E5=AE=B6=5F46=E4=B8=BARecursion/?= =?UTF-8?q?=E5=AE=B6/=E5=AE=B6=5F46.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\345\256\266/\345\256\266_46.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "Recursion/\345\256\266/\345\256\266_46" => "Recursion/\345\256\266/\345\256\266_46.md" (100%) diff --git "a/Recursion/\345\256\266/\345\256\266_46" "b/Recursion/\345\256\266/\345\256\266_46.md" similarity index 100% rename from "Recursion/\345\256\266/\345\256\266_46" rename to "Recursion/\345\256\266/\345\256\266_46.md" -- Gitee From 9cdd1ed840a72417b811439ddd69951092ee3148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B1=89=E5=8D=BF?= <15176331678@163.com> Date: Mon, 10 Jun 2019 18:15:46 +0800 Subject: [PATCH 5/5] 123412341234 --- "Recursion/\345\256\266/\345\256\266_69.md" | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "Recursion/\345\256\266/\345\256\266_69.md" diff --git "a/Recursion/\345\256\266/\345\256\266_69.md" "b/Recursion/\345\256\266/\345\256\266_69.md" new file mode 100644 index 0000000..f7cdc01 --- /dev/null +++ "b/Recursion/\345\256\266/\345\256\266_69.md" @@ -0,0 +1,23 @@ +``` +/** + * 作者:家 + * 思路:二分法即可,思路比较简单,可以通过牛顿法优化 + * 时间复杂度:O(logN) + * 空间复杂度:O(logN)?不是很确定,貌似最多递归logN层 + */ +func mySqrt(x int) int { + return rec(x,0,x) +} +func rec(x int, l int, r int) int{ + mid := l+(r-l)/2 + now := mid*mid + if now == x || now < x && (mid+1)*(mid+1) > x{ + return mid + }else if now > x { + return rec(x,l,mid-1) + } + return rec(x,mid+1,r) +} + + +``` \ No newline at end of file -- Gitee