1. Two Sum [easy] (Python)

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接

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]。

思路方法

思路一

直观思路,暴力求解,两重循环。效率很低。。。

代码

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值