当前位置:网站首页>[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!!!
边栏推荐
猜你喜欢

局部敏感哈希:如何在常数时间内搜索Embedding最近邻

KICAD 拉线宽度无法修改,解决方法

canal同步Mariadb到Mysql

Use DBeaver for mysql data backup and recovery

字典常用方法

BioVendor人俱乐部细胞蛋白(CC16)Elisa试剂盒研究领域

analog IC layout-Design for reliability

【每日一道LeetCode】——1. 两数之和

How ReentrantLock works

Analysis of the status quo of digital transformation of manufacturing enterprises
随机推荐
svm.SVC应用实践1--乳腺癌检测
淘宝详情.
GTK RGB图像绘制
Reflex WMS Intermediate Series 7: What should I do if I want to cancel the picking of an HD that has finished picking but has not yet been loaded?
1688API
【LeetCode】144.二叉树的前序遍历
Nanoprobes Polyhistidine (His-) Tag: Recombinant Protein Detection Protocol
C#测试项目中属性的用法
EFCore 反向工程
亲身经历过的面试题
60 Feature Engineering Operations: Using Custom Aggregate Functions【Favorites】
Use DBeaver for mysql data backup and recovery
【LeetCode】20.有效的括号
记一次gorm事务及调试解决mysql死锁
通用客户端架构
Remember a pit for gorm initialization
简单的页面跳转活动
AcWing 1285. Word Problem Solving (AC Automata)
项目场景 with ERRTYPE = cudaError CUDA failure 999 unknown error
AcWing 1285. 单词 题解(AC自动机)