题解 | #两数之和#

两数之和

https://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f

class Solution:
    def twoSum(self , numbers: List[int], target: int) -> List[int]:
        dict_index, lens = {}, len(numbers)
        list_num = []
        for num in range(0, lens, 1):
            if target-numbers[num] in dict_index.keys():
                list_num.append(dict_index[target-numbers[num]])
                list_num.append(num+1)
                return list_num
            else:
                dict_index[numbers[num]] = num+1

全部评论

相关推荐

04-01 16:02
已编辑
武汉工程大学 Java
牛客98843461...:处女面??我还种马面渣男面处男面呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务