Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd383df0

Browse files
authored
Merge pull requestneetcode-gh#2065 from josuebrunel/feat/0047-permutations-ii.go
Create 0047-permutations-ii.go
2 parentsfef3c9c +6c137fe commitd383df0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

‎go/0047-permutations-ii.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
funcpermuteUnique(nums []int) [][]int {
2+
numLen:=len(nums)
3+
res:= [][]int{}
4+
counter:=make(map[int]int)
5+
6+
for_,n:=rangenums {
7+
counter[n]++
8+
}
9+
10+
varbacktrackfunc([]int,map[int]int)
11+
12+
backtrack=func(perm []int,countermap[int]int) {
13+
iflen(perm)==numLen {
14+
res=append(res,append([]int{},perm...))
15+
return
16+
}
17+
18+
forn,count:=rangecounter {
19+
ifcount==0 {
20+
continue
21+
}
22+
perm=append(perm,n)
23+
counter[n]--
24+
backtrack(perm,counter)
25+
perm=perm[:len(perm)-1]
26+
counter[n]++
27+
}
28+
}
29+
30+
backtrack([]int{},counter)
31+
32+
returnres
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp