Skip to content

Commit c20072d

Browse files
committed
add code snippets
1 parent 6e358d6 commit c20072d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// returns power of a to n by Divide and Conquer
2+
function power(a,n){
3+
if(n===0){
4+
return 1;
5+
}
6+
7+
if(n > 0){
8+
if(n%2 === 0){
9+
return power(a, n/2)*power(a,n/2)
10+
}else{
11+
return power(a, Math.floor(n/2))*power(a,Math.floor(n/2))*a
12+
}
13+
}
14+
}
15+
16+
let ans = power(2,10)
17+
console.log(ans)
18+
19+
20+

0 commit comments

Comments
 (0)