# LeetCode 50: Pow(x, n) Solution [LeetCode 50: Pow(x, n)](https://leetcode.com/problems/powx-n/description/) Exponentiation by squaring ```clike= class Solution { public: double myPow(double x, long long n) { if(n == 0 || x == 1) return 1; if(n < 0) { return 1.0 / myPow(x, -n); } double temp = 1; if(n % 2 == 1) temp = x; double rec = myPow(x, n / 2); return rec * rec * temp; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up