当前位置:网站首页>[Daily LeetCode]——1. The sum of two numbers
[Daily LeetCode]——1. The sum of two numbers
2022-08-02 02:46:00 【The moon chews into stars~】

Table of Contents
Original title: Sum of two numbers
OriginalQuestion: Sum of two numbers
Given an integer array nums and an integer target value target, please find the two integers whose and is the target value target in the array, and return their array indices.
You can assume that there will only be one answer per input.However, the same element in the array cannot be repeated in the answer.
You can return answers in any order.
Example 1:
Input: nums = [2,7,11,15], target = 9Output: [0,1]Explanation: Because nums[0] + nums[1] == 9 , return [0, 1] .Example 2:
Input: nums = [3,2,4], target = 6Output: [1,2]Example 3:
Input: nums = [3,3], target = 6Output: [0,1]Solution ideas:
Start from the first element of the array. Since we want to compare the sum of the two numbers and the target number is equal, we need to use a loop to compare each number after the number to see if the sum is equal toThe target number, returns its subscript if they are equal, or returns no subscript if not.
Code implementation:
class Solution {public int[] twoSum(int[] nums, int target) {int length=nums.length;for(int i=0;iExecution result:

Summary:
Brush every day, don't slack off!!!
边栏推荐
- 永磁同步电机36问(二)——机械量与电物理量如何转化?
- ros多客户端请求服务
- PHP live source code to achieve simple barrage effect related code
- Nanoprobes丨1-mercapto-(triethylene glycol) methyl ether functionalized gold nanoparticles
- 【LeetCode】102.二叉树的层序遍历
- 【LeetCode】83.删除排序链表中的重复元素
- BI - SQL 丨 WHILE
- 通用客户端架构
- BioVendor人俱乐部细胞蛋白(CC16)Elisa试剂盒研究领域
- Nanoprobes Polyhistidine (His-) Tag: Recombinant Protein Detection Protocol
猜你喜欢

Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案

MySQL索引优化实战

面对职场“毕业”,PM&PMO应该如何从容的应对?如何跳槽能够大幅度升职加薪?

Install mysql using docker

极大似然估计

How engineers treat open source

忽晴忽雨

【web】Understanding Cookie and Session Mechanism

Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products

很有意思的经历,很有意思的项目--文件夹对比工具
随机推荐
mysql 查看死锁
aws s3 upload file
NAS和私有云盘的区别?1篇文章说清楚
Chrome浏览器无法加载已解压的.crx文件的解决办法
* 比较版本号
使用self和_(下划线)的区别
CASE2023
analog IC layout-Environmental noise
Unable to log in to the Westward Journey
四元数、罗德里格斯公式、欧拉角、旋转矩阵推导和资料
递归检查配置项是否更变并替换
BI-SQL丨WHILE
svm.SVC application practice 1--Breast cancer detection
The state status is displayed incorrectly after the openGauss switch
How ReentrantLock works
Flask入门学习教程
MySQL - CRUD operations
亲身经历过的面试题
永磁同步电机36问(三)——SVPWM代码实现
Moonbeam and Project integration of the Galaxy, bring brand-new user experience for the community