当前位置:网站首页>Leetcode sum of two numbers
Leetcode sum of two numbers
2022-07-18 23:29:00 【Crazy banana Nicky】
Ideas and algorithms
The easiest way to think of is to enumerate every number in an array x, Look for the existence of target - x.
When we look for target - x when , It needs to be noted that each is located in x All the previous elements have been associated with x Matched , So there's no need to match again . And each element cannot be used twice , So we just need to x Look for... In the following elements target - x.
#
# @lc app=leetcode.cn id=1 lang=python
#
# [1] Sum of two numbers
#
# @lc code=start
class Solution(object):
def twoSum(self, nums, target):
""" :type nums: List[int] :type target: int :rtype: List[int] """
n = len(nums)
for i in range(n):
for j in range(i+1,n):
if nums[i]+nums[j] == target:
return [i,j]
return []
S = Solution()
print(S.twoSum([3,2,4],6))
# @lc code=end
边栏推荐
- How does go ensure the order of concurrent reads and writes Memory model
- 二分查找题目汇总
- HiBench生成基准数据集【WordCount为例】
- 万字详解C语言文件
- Supervised learning week 3: logistic regression option_ Lab harvest record
- 11、摸清JVM对象分布
- Multithreaded application
- [C # network application programming] Experiment 3: process management exercise
- Do you want to switch to software testing? A comprehensive analysis
- 作为一款时序数据库,TDengine 是如何实现并开源其分布式集群功能?
猜你喜欢

小程序:picker-view选择器快速滚动,确认时,”值显示错误“

C # network application programming, Experiment 5: data flow exercise

Mysql内部架构

数据寻址方式

ImportError: cannot import name ‘Imputer‘ from ‘sklearn. preprocessing‘

【图片编辑小软件】FastStone Photo Resizer支持批量转换和批量重命名

7月献礼,买云盘就送特级桂七,仅限2个月,欲购从速

解决windbg无法加载ntdll符号的问题

Interviewer: tell me about the most valuable bug you found in your work

HiBench生成基准数据集【WordCount为例】
随机推荐
OSPF comprehensive experiment
Preliminary test of ZVS circuit
T-infinite Road
Wechat applet -- applet introduction and tool installation configuration
Deep analysis of fiboracci sequence
Quickly build an e-commerce platform based on Amazon cloud technology server free service - Deployment
[CVPR2019] On Stabilizing Generative Adversarial Training with Noise
[NOIP2006普及组]明明的随机数
OOM简介
绝地求生 吃鸡 98k 不自动关镜子
【百度飞桨】手写数字识别模型部署Paddle Inference
Only 22 years old! This "Post-00" doctor plans to work in 985 universities!
【决策樹】使用决策樹進行乳腺癌的診斷
Introduction to sqlmap syntax
[remote desktop] rustdesk open source remote desktop, a substitute for TeamViewer and sunflower
ACM board
(pytorch advanced road III) conv2d
Collaboration process [simple summary]
深入了解arduino舵机控制库文件Servo.h
Three scenarios take you to unit testing