[Python] 3.9
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
...全文
相关推荐
ubuntu安装python3.9 ubuntu安装python3.9
ubuntu安装python3.9 ubuntu安装python3.9 ubuntu安装python3.9 ubuntu安装python3.9 ubuntu安装python3.9 ubuntu安装python3.9 ubuntu安装python3.9 ubuntu安装python3.9 ubuntu安装python3.9
Python 3.9 安装包
Python是一种编程语言,可让您快速工作 无论您是编程新手还是经验丰富的开发人,都可以轻松学习和使用Python
Python3.9安装包下载,适用Macbook 10.9及以上系统。python-3.9.10-macosx10.9
Python3.9安装包下载,适用Macbook 10.9及以上系统。python-3.9.10-macosx10.9
python3.7.9
python3.7.9python3.7.9python3.7.9python3.7.9python3.7.9
python3.9安装包
python3.9


