文件名称:扩展矩阵leetcode-my-leetcode:我的leetcode
文件大小:11KB
文件格式:ZIP
更新时间:2024-07-20 21:00:13
系统开源
扩展矩阵leetcode 我的 Leetcode 目录 大批 链表 深度优先搜索 哈希表 数学 动态规划 其他 二和 Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. O(n) class Solution ( object ): def twoSum ( self , nums , target ): """ :type nums: List[int] :type target: int :rtype: List[int] """ seen = {} for i in range ( len ( nums )): remaining = target - nums [ i ] if remaining in seen : return [ seen [ remaining ], i ] seen [ nums [ i ]] = i 两个数字相加 Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 ->
【文件预览】:
my-leetcode-master
----README.md(47KB)