How to caculate my python code time complexity (Two Sum Problem)?


  • 0
    S
    def Dick_Mark(nums):
    
        L ={}
    
        for index,key in  list(enumerate(nums)):
    
          L.setdefault(key,set()).add(index+1)
        return L
    
    def foo(nums,target):
        RESULT = []
        
        Value_Index_dict = Dick_Mark(nums)
        
        Values = set(Value_Index_dict.keys())
        print Values
        print Value_Index_dict
        for beijiashu in Values:
            if target-beijiashu in Values:
                print 'yes' 
                if beijiashu < target-beijiashu:
                    
                    print Value_Index_dict
                    RESULT.append(Value_Index_dict.get(beijiashu).pop())
                    RESULT.append(Value_Index_dict.get( target-beijiashu ).pop())
                if beijiashu == target-beijiashu:
                    
                    if len(Value_Index_dict.get(beijiashu))>1:
                        for shu in Value_Index_dict.get(beijiashu):
                            RESULT.append(shu)
        return RESULT

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.