Skip to content

Commit ef80af0

Browse files
committed
update: 50
1 parent 744b754 commit ef80af0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
4141
| 46 | [Permutations](https://leetcode.com/problems/permutations/) | [JavaScript](./src/permutations/res.js) | Medium |
4242
| 48 | [Rotate Image](https://leetcode.com/problems/rotate-image/) | [JavaScript](./src/rotate-image/res.js) | Medium |
4343
| 49 | [Group Anagrams](https://leetcode.com/problems/anagrams/) | [JavaScript](./src/anagrams/res.js) | Medium |
44+
| 50 | [powx-n](https://leetcode.com/problems/powx-n/) | [TypeScript](./src/powx-n/res.ts) | Medium |
4445
| 53 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | [JavaScript](./src/maximum-subarray/res.js) · [TypeScript](./src/maximum-subarray/res.ts) | Easy |
4546
| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) | [JavaScript](./src/spiral-matrix/res.js) | Medium |
4647
| 55 | [Jump Game](https://leetcode.com/problems/jump-game/) <sup>*</sup> | [JavaScript](./src/jump-game/res.js) | Medium |

‎src/powx-n/res.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function myPow(x: number, n: number): number {
2+
if (n === 0) {
3+
return 1;
4+
} else if (n === 1) {
5+
return x;
6+
} else if (n > 0) {
7+
if (n % 2 === 0) {
8+
return myPow(x*x, n/2);
9+
} else {
10+
return x * myPow(x, n-1);
11+
}
12+
} else {
13+
return 1 / myPow(x, -n);
14+
}
15+
};

0 commit comments

Comments
 (0)