result = []
for i in n:
for jj in range(len(m)):
if jj < 3:
result.append((n,m))
else:
jj = len(m)
n and m are two Python array.
时间复杂度是多少呢?
- O(n*m) 因为是嵌套循环
- O(n) 因为 inner loop is fixed always 3
- 其他?
讨论一下?
result = []
for i in n:
for jj in range(len(m)):
if jj < 3:
result.append((n,m))
else:
jj = len(m)
n and m are two Python array.
时间复杂度是多少呢?
讨论一下?
|
kuangwinnieJun 4, 2021
1
??这难道不是取决于你 m 是不是定值吗
|
|
2
『 O(n) 因为 inner loop is fixed always 3 』是错的
例如 m 的长度是 10,尽管你 result 只`append`了 3 次,但你的`jj=len(m)`会执行 7 次 |
|
polaaJun 4, 2021
3
O(n*len(m))
|
|
4
0
因为两个空格缩进的 Python 跑不了 |
|
rrfengJun 4, 2021
5
@IgniteWhite 哈哈哈哈哈哈,启动解释器和读取文件的时间不算了吗
|
|
7
|