当前位置:网站首页>[LeetCode]1. Sum of two numbers thirty-four
[LeetCode]1. Sum of two numbers thirty-four
2022-06-13 00:12:00 【PowerDon】
Given an array of integers nums And a target value target, Please find and as the target value in the array Two Integers , And return their array subscripts .
You can assume that each input corresponds to only one answer . however , The same element in an array cannot be used twice .
Example :
Given nums = [2, 7, 11, 15], target = 9
because nums[0] + nums[1] = 2 + 7 = 9
So back [0, 1]
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/two-sum
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
public class Solution
{
public int[] TwoSum(int[] nums, int target)
{
for (int i = 0; i < nums.Length; i++)
{
for (int j = 0; j < nums.Length; j++)
{
if (i == j)
{
continue;
}
int temp = target - nums[i];
if (nums[j] == temp)
{
return new int[2] {
i, j };
}
}
}
return null;
}
}
边栏推荐
- SAP 业务技术平台(BTP) 上的 Business Rules Service 使用介绍
- 【Matlab】二维曲线
- How does the PMP handle the withdrawal?
- 2022-06-13日报: 图灵奖得主:想要在学术生涯中获得成功,需要注意哪些问题?
- Apispace empty number detection API interface is free and easy to use
- Tsinghua University image source will cause tensorflow GPU installation failure
- [C] Inverts the binary of a decimal number and outputs it
- Matlab [path planning] - UAV drug distribution route optimization
- Actual combat | UI automation test framework design and pageobject transformation
- How to quickly query the online status of mobile phones
猜你喜欢
vs studio_ How to use scanf in 2022
The PMP examination time in March 2022 is set -- "March 27"
Learn to divide subnets in an article
如何实现OSM地图本地发布并自定义配图
Basics of network security (1)
Day 3 of jsbom and DOM learning
How to visit a website
How to control the display and hiding of layergroup through transparency in leaflet
测试平台系列(97) 完善执行case部分
MySQL index
随机推荐
What can PMP bring to you
A detailed explanation of synchronized
leaflet中如何优雅的解决百度、高德地图的偏移问题
2022年3月11日记:王老师的春天,奇异的模板模式
Information collection for network security (2)
Several interview questions in TCP three grips and four swings
How to quickly query the online status of mobile phones
2022-06-13日报: 图灵奖得主:想要在学术生涯中获得成功,需要注意哪些问题?
[hcie discussion] rr-a
Do you have to read for PMP?
【Matlab】基础运算
Binary search the specified number of numbers in the array binary advanced
Is the PMP training organization an actual training?
How to quickly query the mobile phone number home and operator
【HCIE论述】组播IGMP-A
How to control the display and hiding of layergroup through transparency in leaflet
[hcie discussion] STP-A
2022 operation of simulated examination platform for hoisting machinery command certificate
How does the PMP handle the withdrawal?
March 11, 2022 diary: Mr. Wang's spring, strange template mode