thelist = [[2,3],[],[]]
n=len(thelist)
for i in range(1,n):
if i <= k:
thelist[i].append(1)
for j in thelist[i-1]:
c = j+1
thelist[i].append(c)
I am trying to figure out the time complexity for the code. Isit O(n^2) or O(n)? I think it's O(n^2) because there's 2 loops but then again I'm not using n times to run the 2nd loop so it might be O(n). I trying to get the time complexity of O(n).
thelist
is n-1 Hence it's O((n-1)*n)
, which we generally just round to O(n^2)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.