当前位置:网站首页>[daily exercises] 1 Sum of two numbers
[daily exercises] 1 Sum of two numbers
2022-06-11 05:46:00 【swindler.】
Sum of two numbers
Title Description : Given an array of integers nums And an integer target value target, Please find... In the array And is the target value target the Two Integers , And return their array subscripts .
Example 1:
Input :nums = [2,7,11,15], target = 9
Output :[0,1]
explain : because nums[0] + nums[1] == 9 , return [0, 1] .
Example 2:
Input :nums = [3,2,4], target = 6
Output :[1,2]
Example 3:
Input :nums = [3,3], target = 6
Output :[0,1]
Their thinking : Set a primitive array containing two elements , Double traversal , Assign the index obtained by traversal to the two elements in the array in turn , Finally, return the array .
class Solution {
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var tagrgetNum : [Int] = [0,0]
for i in 0..<nums.count {
for j in 0..<i {
if nums[i] + nums[j] == target {
tagrgetNum[0] = i
tagrgetNum[1] = j
}
}
}
return tagrgetNum
}
}
边栏推荐
- VSCode插件开发
- 27. Remove elements
- NDK learning notes (IX) POSIX sockect connection oriented communication
- [go deep into kotlin] - get to know flow for the first time
- AttributeError: ‘HistGradientBoostingClassifier‘ object has no attribute ‘_ n_ features‘
- “All in ONE”一个平台解决所有需求,运维监控3.0时代已来
- NDK learning notes (13) create an avi video player using avilib+opengl es 2.0
- Basics of customized view
- Vscode plug-in development
- If the MAC fails to connect with MySQL, it will start and report an error
猜你喜欢

NFC Development -- the method of using NFC mobile phones as access control cards (II)

Write a list with kotlin

在未来,机器人或 AI 还有多久才能具备人类的创造力?

Recherche sur l'optimisation de Spark SQL basée sur CBO pour kangourou Cloud Stack

NFC Development -- utility tools and development documents (IV)

getBackgroundAudioManager控制音乐播放(类名的动态绑定)

Stone game -- leetcode practice

Why is the smart door lock so popular? What about the smart door locks of MI family and zhiting?

Wechat applet learning record

NDK learning notes (VI) Basics: memory management, standard file i/o
随机推荐
Dism command usage summary
Jsonobject jsonarray for parsing
Create cool collectionviewcell conversion animation
NDK learning notes (14) create an avi video player using avilib+window
微信小程序text内置组件换行符不换行的原因-wxs处理换行符,正则加段首空格
Further efficient identification of memory leakage based on memory optimization tool leakcanary and bytecode instrumentation technology
使用Batch设置IP地址
Bit operation marks multiple switches with one parameter
NDK learning notes (x) POSIX socket for connectionless communication
Combination sum Ⅳ -- leetcode exercise
Tencent X5 kernel initialization failed tbsreaderview not support by:***
Concepts and differences of parallel computing, distributed computing and cluster (to be updated for beginners)
Wechat applet, automatic line feed for purchasing commodity attributes, fixed number of divs, automatic line feed for excess parts
Recursively process data accumulation
Xposed bypasses 360 reinforcement to get a real classloader
NDK learning notes (IV) functions, classes and exceptions of swig
项目-智慧城市
Flask develops and implements the like comment module of the online question and answer system
Error:Execution failed for task ':app:buildNative'. & gt; A problem occurred'x/x/x/'NDK build' error resolution
Altiumdesigner2020 import 3D body SolidWorks 3D model