leetcode算法题主函数如何写-leetcode-top_100:leetcode-top_100

时间:2024-07-19 23:00:40
【文件属性】:

文件名称:leetcode算法题主函数如何写-leetcode-top_100:leetcode-top_100

文件大小:10KB

文件格式:ZIP

更新时间:2024-07-19 23:00:40

系统开源

leetcode算法题主函数如何写 leetcode-top_100 1. 两数之和 问题:给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。 代码: class Solution(object): def twoSum(self, nums, target): hashmap = {} for index, num in enumerate(nums): another_num = target - num if another_num in hashmap: return [hashmap[another_num], index] hashmap[num] = index return None 2.两数相加 问题:给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。您可以假设除了数字


【文件预览】:
leetcode-top_100-master
----README.md(17KB)
----.idea()
--------workspace.xml(8KB)
--------vcs.xml(180B)
--------top_100.iml(398B)
--------misc.xml(288B)
--------modules.xml(266B)
----.DS_Store(6KB)

网友评论