File tree Expand file tree Collapse file tree 2 files changed +38
-10
lines changed Expand file tree Collapse file tree 2 files changed +38
-10
lines changed Original file line number Diff line number Diff line change 22 "cells" : [
33 {
44 "cell_type" : " code" ,
5- "execution_count" : null ,
5+ "execution_count" : 1 ,
66 "id" : " imports" ,
77 "metadata" : {},
88 "outputs" : [],
1313 },
1414 {
1515 "cell_type" : " code" ,
16- "execution_count" : null ,
16+ "execution_count" : 2 ,
1717 "id" : " setup" ,
1818 "metadata" : {},
1919 "outputs" : [],
2626 },
2727 {
2828 "cell_type" : " code" ,
29- "execution_count" : null ,
29+ "execution_count" : 3 ,
3030 "id" : " run" ,
3131 "metadata" : {},
32- "outputs" : [],
32+ "outputs" : [
33+ {
34+ "data" : {
35+ "text/plain" : [
36+ " [0, 1]"
37+ ]
38+ },
39+ "execution_count" : 3 ,
40+ "metadata" : {},
41+ "output_type" : " execute_result"
42+ }
43+ ],
3344 "source" : [
3445 " result = run_two_sum(Solution, nums, target)\n " ,
3546 " result"
3647 ]
3748 },
3849 {
3950 "cell_type" : " code" ,
40- "execution_count" : null ,
51+ "execution_count" : 4 ,
4152 "id" : " assert" ,
4253 "metadata" : {},
43- "outputs" : [],
54+ "outputs" : [
55+ {
56+ "data" : {
57+ "text/plain" : [
58+ " True"
59+ ]
60+ },
61+ "execution_count" : 4 ,
62+ "metadata" : {},
63+ "output_type" : " execute_result"
64+ }
65+ ],
4466 "source" : [
4567 " assert_two_sum(result, expected)"
4668 ]
6082 "file_extension" : " .py" ,
6183 "mimetype" : " text/x-python" ,
6284 "name" : " python" ,
63- "nbconvert_exporter" : " python3" ,
85+ "nbconvert_exporter" : " python" ,
86+ "pygments_lexer" : " ipython3" ,
6487 "version" : " 3.13.7"
6588 }
6689 },
Original file line number Diff line number Diff line change 11class Solution :
22
3- # Time: O(? )
4- # Space: O(? )
3+ # Time: O(n )
4+ # Space: O(n )
55 def two_sum (self , nums : list [int ], target : int ) -> list [int ]:
6- # TODO: Implement two_sum
6+ seen : dict [int , int ] = {}
7+ for i , num in enumerate (nums ):
8+ complement = target - num
9+ if complement in seen :
10+ return [seen [complement ], i ]
11+ seen [num ] = i
712 return []
You can’t perform that action at this time.
0 commit comments