close
two-sum
class Solution:
    def twoSum(self, nums: 'List[int]', target: 'int') -> 'List[int]':
        tmp={}
        for i in range(len(nums)):
            if target-nums[i] in tmp:
                return(tmp[target-nums[i]],i)
            else:
                tmp[nums[i]]=i;
add-two-numbers
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def addTwoNumbers(self, l1: 'ListNode', l2: 'ListNode') -> 'ListNode':
        head=ListNode(0)
        answer=head
        carry=0
        while l1 and l2:
            add=l1.val+l2.val+carry
            carry=1if add >=10 else 0
            head.next=ListNode(add%10)
            head=head.next
            l1,l2=l1.next,l2.next
        l=l1 if l1 else l2
        while l:
            add=l.val + carry
            carry=1 if add>=10 else 0

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 低階ㄇㄋ 的頭像
    低階ㄇㄋ

    蟲匯聚之所

    低階ㄇㄋ 發表在 痞客邦 留言(0) 人氣()