Leetcode - Conversion
50. Pow(x, n)[M]
https://leetcode.com/problems/powx-n/
Description
Implement pow(x, n), which calculates x raised to the power n (xn).
Example 1:
1 | Input: 2.00000, 10 |
Example 2:
1 | Input: 2.10000, 3 |
Example 3:
1 | Input: 2.00000, -2 |
Note:
- -100.0 < x < 100.0
- n is a 32-bit signed integer, within the range [−231, 231 − 1
Solution
1 | class Solution: |
https://leetcode.com/discuss/93413/iterative-log-n-solution-with-clear-explanation
1 | class Solution: |
231. Power of Two[E]
https://leetcode.com/problems/power-of-two/
Description
Given an integer, write a function to determine if it is a power of two.
Example 1:
1 | Input: 1 |
Example 2:
1 | Input: 16 |
Example 3:
1 | Input: 218 |
Solution
1 | class Solution: |
326. Power of Three[E]
https://leetcode.com/problems/power-of-three/
Description
Given an integer, write a function to determine if it is a power of three.
Example 1:
1 | Input: 27 |
Example 2:
1 | Input: 0 |
Example 3:
1 | Input: 9 |
Example 4:
1 | Input: 45 |
Follow up:
Could you do it without using any loop / recursion?
Solution
https://leetcode.com/problems/power-of-three/solution/
1 | class Solution: |
342. Power of Four[E]
https://leetcode.com/problems/power-of-four/
Description
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
Example 1:
1 | Input: 16 |
Example 2:
1 | Input: 5 |
Follow up: Could you solve it without loops/recursion?
Solution
1 | class Solution: |
372. Super Pow[M]
https://leetcode.com/problems/super-pow/
Description
Your task is to calculate a**b mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
Example 1:
1 | Input: a = 2, b = [3] |
Example 2:
1 | Input: a = 2, b = [1,0] |
Solution
1 | class Solution: |





