题目链接
https://leetcode.com/problems/two-sum/
题目原文
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution.Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
题目翻译
给定一个整数数组nums,返回数组中“和是某个给定值target”的两个数的下标。假设对于每次输入有且只有一个解。
比如:给定nums = [2, 7, 11, 15],target = 9,因为nums[0] + nums[1] = 2 + 7 = 9,所以返回[0, 1]。
思路方法
思路一
直观思路,暴力求解,两重循环。效率很低。。。
代码
class Solution(object)

这篇博客介绍了LeetCode中的1. Two Sum问题,目标是找到数组中两个数的下标,使得它们相加等于特定目标值。文章提供了两种解题思路,包括暴力求解和优化的解决方案,使用Python语言实现。作者是一名LeetCode新手,欢迎指正。
最低0.47元/天 解锁文章
2720





