我正在尝试使用python解决此链接上的问题:
https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/tds-and-his-breakup/
我用两种方法解决了:
n = int(input())
min_skill = int(input())
for i in range(n):
if int(input()) >= min_skill:
print("YES")
else:
print("NO")
n = int(input())
min_skill = int(input())
list_skill = []
for i in range(n):
temp = int(input())
list_skill.append(temp)
for skill in list_skill:
if skill >= min_skill:
print("YES")
else:
print("NO")
尽管第二种方法使用一个列表来存储输入以及对输入进行两次迭代,为什么第一种方法所需的时间和内存大于第二种方法?