华为机试HJ55挑7
题目:
想法:
遍历输入的数值,找到其中7的倍数和包含7的数值,记录个数并输出
input_number = int(input())
count = 0
for i in range(1, input_number+1):
if i % 7 == 0 or "7" in str(i):
count += 1
print(count)
时间复杂度:
O
(
n
l
o
g
(
n
)
)
O(nlog(n))
O(nlog(n)),(其中判断字符串中是否包含7的时间复杂度为
O
(
l
o
g
(
n
)
)
O(log(n))
O(log(n)))
空间复杂度:
O
(
1
)
O(1)
O(1)