Hot100
1. 哈希
1. 两数之和
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。
遍历数组,将数组中的元素作为键,索引作为值,存入字典中,通过是否存在键等于target-num的元素,如果存在则返回当前索引和target-num的索引。
1 | class Solution: |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 薄荷巧克力!

