【发布时间】:2020-04-02 22:49:29
【问题描述】:
这个函数的空间复杂度是N^2,因为输出是一个链表吗?
我正在学校学习空间复杂性,并被困在这个问题上。
def myHealthcare(record):
l2=[]
count=0 # num of records generated and the specific time
for i in range(record):
l=[]
now = datetime.datetime.now()
ts = now.strftime("%d/%m/%Y %H:%M:%S") # str timestamp
ts=ts +' '+str(count)
l.append(ts)
l.append(rand.randint(36,39)) #temp
l.append(rand.randint(55,100)) #hr
l.append(rand.randint(55,100)) #Pulse
l.append(rand.randint(120,121)) #bp
l.append(rand.randint(11,17)) #respiratory rate
l.append(rand.randint(93,100)) #oxygen sat
l.append(round(rand.uniform(7.1,7.6),1)) #pH
l2.append(l)
count+=1
return l2
【问题讨论】:
-
你能更详细地解释一下你的思考过程吗?为什么作为链表意味着它是 O(n^2)?
标签: python python-3.x big-o space-complexity