当前位置:网站首页>NC61 两数之和
NC61 两数之和
2022-08-09 13:02:00 【syc596】
NC61 两数之和
//map
//注:返回的数组下标从1开始算起
import java.util.*;
public class Solution {
public int[] twoSum (int[] array, int target) {
int[] ret=new int[0];
HashMap<Integer,Integer> map=new HashMap<>();
for(int i=0;i<array.length;i++){
if(map.containsKey(target-array[i])){
return new int[]{map.get(target-array[i])+1,i+1};
}else{
map.put(array[i],i);
}
}
return ret;
}
}
边栏推荐
- Explanation of RTSP protocol
- Standing wave ratio calculation method
- FFmpeg多媒体文件处理(FFMPEG日志系统)
- 5G China unicom general exception handling
- Yocto 可以下载的第三方库
- 5G China unicom 一般性异常处理
- NFS pays special attention to the problem of permissions
- Record the system calls and C library functions used in this project-2
- Q_06_02 类型模型
- WSA工具箱安装应用商店提示无法工作怎么解决?
猜你喜欢
随机推荐
力扣解法汇总1413-逐步求和得到正数的最小值
An Offer 21. Adjust the array in order to make odd in even the front (loop invariant)
5G China unicom 一般性异常处理
puzzle(016.5)逻辑电路
Jenkins API groovy调用实践: Jenkins Core Api & Job DSL创建项目
缓存和数据库一致性问题
WSA toolkit installed app store tip doesn't work how to solve?
Microsoft 10/11 命令行打开系统设置页(WUAP,!WIN32)
剑指 Offer 57 - II. 和为s的连续正数序列(滑动窗口)
【瑞吉外卖】day05:增、删、改、查分类以及公共字段自动填充
IDEA Gradle 常遇问题(二)(持续更新)
Dry+Bean+Dataset R语言数据分析,报告英文
GIN中GET POST PUT DELETE请求
Professor Chen Qiang the machine learning and R application course chapter 18 assignments
Q_08 更多信息
陈强教授《机器学习及R应用》课程 第十三章作业
The FPGA - work summary recently
5G China unicom AP:B SMS ASCII Transcoding Requirements
驻波比计算方法
The sword refers to Offer 57 - II. and is a continuous positive sequence of s (sliding window)