File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ wheels/
2424* .egg-info /
2525.installed.cfg
2626* .egg
27+ .DS_Store
2728
2829# PyInstaller
2930# Usually these files are written by a python script from a template
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def twoSum (self , nums , target ):
3+ """
4+ :type nums: List[int]
5+ :type target: int
6+ :rtype: List[int]
7+ """
8+ d = {}
9+ for i , num in enumerate (nums ):
10+ if target - num in d :
11+ return [d [target - num ], i ]
12+ d [num ] = i
Original file line number Diff line number Diff line change 1+ # Definition for singly-linked list.
2+ class ListNode (object ):
3+ def __init__ (self , x ):
4+ self .val = x
5+ self .next = None
6+
7+
8+ class Solution (object ):
9+ def addTwoNumbers (self , l1 , l2 ):
10+ """
11+ :type l1: ListNode
12+ :type l2: ListNode
13+ :rtype: ListNode
14+ """
15+ temp = 1 if (l1 .val + l2 .val ) >= 10 else 0
16+ head = ListNode ((l1 .val + l2 .val ) % 10 )
17+ tail = head
18+ while l1 .next is not None or l2 .next is not None or temp == 1 :
19+ l1 = l1 .next if l1 .next is not None else ListNode (0 )
20+ l2 = l2 .next if l2 .next is not None else ListNode (0 )
21+ node = ListNode ((l1 .val + l2 .val + temp ) % 10 )
22+ temp = 1 if (l1 .val + l2 .val + temp ) >= 10 else 0
23+ tail .next = node
24+ tail = node
25+ return head
You can’t perform that action at this time.
0 commit comments