넘치게 채우기

[LeetCode] 50. Pow(x, n) 본문

PS/LeetCode

[LeetCode] 50. Pow(x, n)

riveroverflow 2023. 7. 24. 16:54
728x90
반응형

https://leetcode.com/problems/powx-n/description/

 

Pow(x, n) - LeetCode

Can you solve this real interview question? Pow(x, n) - Implement pow(x, n) [http://www.cplusplus.com/reference/valarray/pow/], which calculates x raised to the power n (i.e., xn).   Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Inpu

leetcode.com

문제 유형 : 수학

문제 난이도 : Medium

 

문제

Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

 

x의n승을 반환하시오.

 

풀이

cmath 라이브러리의 pow(a,b)함수를 쓰면 된다. a의 b제곱을 반환한다.

 

코드(C++)

class Solution {
public:
    double myPow(double x, int n) {
        return pow(x, n);
    }
};
 
728x90
반응형