Python 了解树编号总和和文件读取的复杂性

Python 了解树编号总和和文件读取的复杂性,python,time-complexity,Python,Time Complexity,我们有一个简单的txt文件,其中所有行表示一个数字的字符串。 目标是找到3个数字,你可以添加到2020年。 我是复杂性分析的初学者,所以我想知道我的思维过程是否正常 def get_product_tree(target): with open("puzzle.txt") as f: # o(2*n) Time | o(n) -> Is it really efficient ? l = list(map(lambda x : int(

我们有一个简单的txt文件,其中所有行表示一个数字的字符串。 目标是找到3个数字,你可以添加到2020年。 我是复杂性分析的初学者,所以我想知道我的思维过程是否正常

def get_product_tree(target): 

with open("puzzle.txt") as f: 
    
    # o(2*n) Time | o(n) -> Is it really efficient ? 
    l = list(map(lambda x : int(x), f)) # need to convert all strings to int
    # o(nlogn) Time
    l.sort() 
    # o(n) Time -> I'm not sure about this one since
    # it's only based on my intuitions 
    for h in range(0, len(l)): 
        i,j = h+1, len(l) - 1 
        # print(i,j,h)
        while i < j: 
            result = l[i] + l[h] + l[j]
            if result < target: 
                i += 1 
            elif result > target: 
                j -= 1 
            else: 
                # basically we return the product
                return l[i] * l[j] * l[h]

    return None
def get_product_树(目标):
将open(“puzzle.txt”)作为f:
#o(2*n)时间| o(n)->它真的有效吗?
l=list(map(lambda x:int(x),f))#需要将所有字符串转换为int
#o(nlogn)时间
l、 排序()
#o(n)时间->我不确定这一次,因为
#这只是基于我的直觉
对于范围(0,len(l))内的h:
i、 j=h+1,len(l)-1
#打印(i、j、h)
而i目标:
j-=1
其他:
#基本上我们是退货的
返回l[i]*l[j]*l[h]
一无所获
我的答案是复杂性是:o(2*n)+o(nlogn)+o(n)时间| o(n)空间~o(nlogn)时间| o(n)空间

这对我来说似乎太过分了(如果我的分析是正确的)。你知道如何使它更好吗?多谢各位