当前位置:网站首页>[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;i
Execution result:
Summary:
Brush every day, don't slack off!!!
边栏推荐
猜你喜欢
2022牛客多校四_G M
Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案
AI目标分割能力,无需绿幕即可实现快速视频抠图
数仓:为什么说 ETL 的未来不是 ELT,而是 EL (T)
一次SQL优化,数据库查询速度提升 60 倍
第10章_索引优化与查询优化
Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products
记一次gorm事务及调试解决mysql死锁
项目场景 with ERRTYPE = cudaError CUDA failure 999 unknown error
The failure to create a role in Dahua Westward Journey has been solved
随机推荐
项目场景 with ERRTYPE = cudaError CUDA failure 999 unknown error
Safety (2)
2022牛客多校四_G M
Install mysql using docker
【web】理解 Cookie 和 Session 机制
微服务:微智能在软件系统的简述
通用客户端架构
qt点云配准软件
Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products
一次SQL优化,数据库查询速度提升 60 倍
搭建zabbix监控及邮件报警(超详细教学)
OC和Swift语言的区别
esp32经典蓝牙和单片机连接,,,手机蓝牙作为主机
790. 数的三次方根
AI target segmentation capability for fast video cutout without green screen
很有意思的经历,很有意思的项目--文件夹对比工具
The state status is displayed incorrectly after the openGauss switch
数仓:数仓从ETL到ELT架构的转化以及俩者的区别
【LeetCode】20.有效的括号
Good News | AR opens a new model for the textile industry, and ALVA Systems wins another award!