File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ def generate_log():
17
17
18
18
def find_unique_id_cycling (log ):
19
19
"""
20
+ Iterates through the whole list once for each of the items in the list. Adds 1 to a counter per iteration through
21
+ the list and if the counter = 1, that is the unique instance.
20
22
time complexity: n^2
21
23
space complexity: 1
22
24
"""
@@ -37,6 +39,8 @@ def find_unique_id_cycling(log):
37
39
def find_unique_cycling_reduction (log ):
38
40
"""
39
41
time complexity: (((n-1) / 2) ^ 2) + (n-1) / 2
42
+ why? n - 1 / 2 is the number of ids, ^2 because you need to trace through the list recursively but /2 because
43
+ you're reducing the list as you go
40
44
space complexity: 1
41
45
"""
42
46
copied_log = log .copy ()
@@ -74,18 +78,18 @@ def find_unique_dict(log):
74
78
def find_unique_sort (log ):
75
79
"""
76
80
time complexity: nlogn + (n-1)
77
- space complexity: n
81
+ space complexity: 1
78
82
"""
79
- sorted_log = sorted ( log )
83
+ log . sort ( )
80
84
for a in range (len (log )):
81
85
try :
82
- if sorted_log [0 ] == sorted_log [1 ]:
83
- sorted_log .pop (1 )
84
- sorted_log .pop (0 )
86
+ if log [0 ] == log [1 ]:
87
+ log .pop (1 )
88
+ log .pop (0 )
85
89
else :
86
- return sorted_log [a ]
90
+ return log [a ]
87
91
except IndexError :
88
- return sorted_log [0 ]
92
+ return log [0 ]
89
93
90
94
91
95
def find_unique_crazy_xor (delivery_ids ):
You can’t perform that action at this time.
0 commit comments