30,416
社区成员




class Solution:
def convertToBase7(self, num: int) -> str:
hep = 0
index = 0
abs_num = abs(num)
str_hep = ''
if num > 0:
while num > 0:
hep += (num % 7) * pow(10, index)
index += 1
num //= 7
str_hep = str(hep)
elif num < 0:
num = abs_num
while num > 0:
hep += (num % 7) * pow(10, index)
index += 1
num //= 7
str_hep = '-' + str(hep)
else:
str_hep = '0'
return (str_hep)
class Solution:
def isPowerOfFour(self, n: int) -> bool:
index = 0 # 四进制的位数
quater = 0 # n 的四进制
while n > 0:
quater += (n % 4) * pow(10, index)
index += 1
n //= 4
s = str(quater)
if s[0] == '1' and s[1:].count('0') == index - 1:
return True
else:
return False