Skip to content

Commit 5317508

Browse files
author
zhangbo
committed
Merge branch 'master' of github.com:zbcoder/algorithm-exercise
2 parents 36a75fb + ae5cb2c commit 5317508

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

~.Array.M-shootingPermutation.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* 一个人投篮sum次,命中n球:加入命中为1,不命中为0,那么一次投篮的组合可以表示成n个0加sum-n个1
3+
* 请列举所有可能出现的情况
4+
*/
5+
6+
function shootingPermutation(num) {
7+
if(num === 0) return []
8+
if(num === 1) return ['1', '0']
9+
return [].concat(...['1', '0'].map(x=> shootingPermutation(num-1).map(y=> x + y)))
10+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy