360笔试A卷
第一题 go
var dfs func(idx int, left int, count int)
dfs = func(idx int, left int, count int) {
if left <= 0 && count == 0 {
ans++
return
}
if count == 0 && left > 0 {
return
}
if idx >= n {
return
}
dfs(idx+1, left, count)
dfs(idx+1, left-arr[idx], count-1)
}
var dfs func(idx int, left int, count int)
dfs = func(idx int, left int, count int) {
if left <= 0 && count == 0 {
ans++
return
}
if count == 0 && left > 0 {
return
}
if idx >= n {
return
}
dfs(idx+1, left, count)
dfs(idx+1, left-arr[idx], count-1)
}
全部评论
相关推荐