From 210ca488b4f1c603aa061927010ea077dedb22d6 Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Fri, 9 Dec 2022 21:23:03 +0800 Subject: [PATCH] =?UTF-8?q?update=200046.=E5=85=A8=E6=8E=92=E5=88=97:=20?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=20go=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0046.全排列.md | 45 +++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/problems/0046.全排列.md b/problems/0046.全排列.md index 805bc457..c437f7ca 100644 --- a/problems/0046.全排列.md +++ b/problems/0046.全排列.md @@ -275,29 +275,34 @@ class Solution: ### Go ```Go -var res [][]int +var ( + res [][]int + path []int + st []bool // state的缩写 +) func permute(nums []int) [][]int { - res = [][]int{} - backTrack(nums,len(nums),[]int{}) - return res -} -func backTrack(nums []int,numsLen int,path []int) { - if len(nums)==0{ - p:=make([]int,len(path)) - copy(p,path) - res = append(res,p) - } - for i:=0;i