Created
November 20, 2020 10:35
-
-
Save ruan4261/edb1160041adec4af0edb94299313652 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 不能输入负数参数 | |
long binaryPow(long base, long exponent) { | |
long res = 1; | |
while (exponent > 0) { | |
if ((exponent & 1) == 1) res *= base; | |
base *= base; | |
exponent >>= 1; | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment