Skip to content

Commit cec1603

Browse files
authored
Merge pull request #224 from hellomrsun/master
Add Pow(x,n) C#
2 parents 201cb44 + f15065a commit cec1603

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Solution {
2+
public double MyPow(double x, int n) {
3+
if(n < 0) return Pow(1/x, -n);
4+
return Pow(x, n);
5+
}
6+
7+
public double Pow(double x, int n){
8+
if(n == 0) return 1;
9+
if(n == 1) return x;
10+
if(n % 2 == 0) return Pow(x * x, n/2);
11+
return x * Pow(x * x, n / 2);
12+
}
13+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Solutions in various programming languages are provided. Enjoy it.
2222
13. [Same Tree](https://github.com/AlgoStudyGroup/Leetcode/tree/master/July-LeetCoding-Challenge/13-Same-Tree): DFS
2323
14. [Angle Between Hands of a Clock](https://github.com/AlgoStudyGroup/Leetcode/tree/master/July-LeetCoding-Challenge/14-Angle-Between-Hands-of-a-Clock): Math
2424
15. [Reverse Words in a String](https://github.com/AlgoStudyGroup/Leetcode/tree/master/July-LeetCoding-Challenge/15-Reverse-Words-in-a-String): Pointer
25+
16. [16-Pow(x,n)](https://github.com/AlgoStudyGroup/Leetcode/tree/master/July-LeetCoding-Challenge/16-Pow(x,n)): Recursion
26+
2527

2628
## June LeetCoding Challenge
2729
Click [here](https://leetcode.com/explore/challenge/card/june-leetcoding-challenge/) for problem descriptions.

0 commit comments

Comments
 (0)