博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Two Sum(Java实现)
阅读量:4044 次
发布时间:2019-05-24

本文共 800 字,大约阅读时间需要 2 分钟。

Two Sum(Java实现)

问题:

Given an array of integers nums and an integer target,return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution,and you may not use the same element twice.

You can return the answer in any order.

方法1:暴力法

public static int [] TowNumberSum_1(int []nums,int target)    {
for(int i=0;i

方法2:哈希表法

public static int[] TowNumberSum_2(int [] nums,int target)    {
Map
map=new HashMap<>(); for(int i=0;i

完整代码(附运行结果)

package leetcode;import java.util.Arrays;import java.util.HashMap;import java.util.Map;public class TowSum {
//暴力法 /* public static int [] TowNumberSum_1(int []nums,int target) { for(int i=0;i
map=new HashMap<>(); for(int i=0;i

在这里插入图片描述

转载地址:http://yyhdi.baihongyu.com/

你可能感兴趣的文章
学习设计模式(3)——单例模式和类的成员函数中的静态变量的作用域
查看>>
自然计算时间复杂度杂谈
查看>>
当前主要目标和工作
查看>>
使用 Springboot 对 Kettle 进行调度开发
查看>>
一文看清HBase的使用场景
查看>>
解析zookeeper的工作流程
查看>>
搞定Java面试中的数据结构问题
查看>>
慢慢欣赏linux make uImage流程
查看>>
linux内核学习(7)脱胎换骨解压缩的内核
查看>>
以太网基础知识
查看>>
慢慢欣赏linux 内核模块引用
查看>>
kprobe学习
查看>>
慢慢欣赏linux phy驱动初始化2
查看>>
慢慢欣赏linux CPU占用率学习
查看>>
2020年终总结
查看>>
Homebrew指令集
查看>>
React Native(一):搭建开发环境、出Hello World
查看>>
React Native(二):属性、状态
查看>>
JSX使用总结
查看>>
React Native(四):布局(使用Flexbox)
查看>>