1 Star 0 Fork 0

catyMap/AlgorithmNote

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
permutation.go 563 Bytes
一键复制 编辑 原始数据 按行查看 历史
catyMap 提交于 2021-05-06 23:09 +08:00 . 添加动态规划等题目
package main
import (
"fmt"
)
func permutation(s string) (res []string) {
trace , book, n := "" , make(map[int]int), len(s)
set := make(map[string]int)
var depth func()
depth = func() {
if _ , ok := set[trace] ;len(trace) == n && !ok {
res = append(res, trace)
set[trace] ++
return
}
for i := 0 ; i < n ; i++ {
if v , _ := book[i] ; v > 0 {
continue
}
book[i] ++
trace += string(s[i])
depth()
book[i] --
trace = trace[:len(trace)-1]
}
}
depth()
return res
}
func main() {
fmt.Println(permutation("aab"))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dogemap/algorithm-note.git
git@gitee.com:dogemap/algorithm-note.git
dogemap
algorithm-note
AlgorithmNote
dc486f96f6c1

搜索帮助