当前位置: 首页 > news >正文

高密住房和城乡建设厅网站免费网站seo优化

高密住房和城乡建设厅网站,免费网站seo优化,www.北京网站建设,三乡网站开发题目信息 源地址:两数之和 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那两个整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不…

题目信息

源地址:两数之和

给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那两个整数,并返回它们的数组下标。

你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。

你可以按任意顺序返回答案。

提示信息

示例 1

 
输入:nums = [2,7,11,15], target = 9
输出:[0,1]
解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。

示例 2

 
输入:nums = [3,2,4], target = 6
输出:[1,2]

示例 3

 
输入:nums = [3,3], target = 6
输出:[0,1]

限制

  • 2 <= nums.length <= 10^3
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • 只会存在一个有效答案

实现逻辑

暴力枚举

最先想到的逻辑肯定是使用双层循环暴力查找。

当然,采用这种方式的时间复杂度是 O(n2),空间复杂度是 O(1),实际效率是非常地低。

 
package cn.fatedeity.algorithm.leetcode;
public class TwoSum {
public int[] answer(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return new int[0];
}
}

哈希匹配

如果采用“空间换时间”的方法,利用哈希表结构查找时间复杂度为 O(1) 的特性,就可以一次循环快速得到结果。

最终,时间复杂度降到 O(n),空间复杂度则变成 O(n)。

 

题目信息

源地址:两数之和

给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那两个整数,并返回它们的数组下标。

你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。

你可以按任意顺序返回答案。

提示信息

示例 1

 
输入:nums = [2,7,11,15], target = 9
输出:[0,1]
解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。

示例 2

 
输入:nums = [3,2,4], target = 6
输出:[1,2]

示例 3

 
输入:nums = [3,3], target = 6
输出:[0,1]

限制

  • 2 <= nums.length <= 10^3
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • 只会存在一个有效答案

实现逻辑

暴力枚举

最先想到的逻辑肯定是使用双层循环暴力查找。

当然,采用这种方式的时间复杂度是 O(n2),空间复杂度是 O(1),实际效率是非常地低。

 
package cn.fatedeity.algorithm.leetcode;
public class TwoSum {
public int[] answer(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return new int[0];
}
}

哈希匹配

如果采用“空间换时间”的方法,利用哈希表结构查找时间复杂度为 O(1) 的特性,就可以一次循环快速得到结果。

最终,时间复杂度降到 O(n),空间复杂度则变成 O(n)。

 
package cn.fatedeity.algorithm.leetcode;
import java.util.HashMap;
public class TwoSum {
public int[] answer(int[] nums, int target) {
HashMap<Integer, Integer> hashMap = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int diff = target - nums[i];
if (hashMap.containsKey(diff)) {
return new int[]{hashMap.get(diff), i};
}
hashMap.put(nums[i], i);
}
return new int[0];
}
}
package cn.fatedeity.algorithm.leetcode;
import java.util.HashMap;
public class TwoSum {
public int[] answer(int[] nums, int target) {
HashMap<Integer, Integer> hashMap = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int diff = target - nums[i];
if (hashMap.containsKey(diff)) {
return new int[]{hashMap.get(diff), i};
}
hashMap.put(nums[i], i);
}
return new int[0];
}
}

 

题目信息

源地址:两数之和

给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那两个整数,并返回它们的数组下标。

你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。

你可以按任意顺序返回答案。

提示信息

示例 1

 
输入:nums = [2,7,11,15], target = 9
输出:[0,1]
解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。

示例 2

 
输入:nums = [3,2,4], target = 6
输出:[1,2]

示例 3

 
输入:nums = [3,3], target = 6
输出:[0,1]

限制

  • 2 <= nums.length <= 10^3
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • 只会存在一个有效答案

实现逻辑

暴力枚举

最先想到的逻辑肯定是使用双层循环暴力查找。

当然,采用这种方式的时间复杂度是 O(n2),空间复杂度是 O(1),实际效率是非常地低。

 
package cn.fatedeity.algorithm.leetcode;
public class TwoSum {
public int[] answer(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return new int[0];
}
}

哈希匹配

如果采用“空间换时间”的方法,利用哈希表结构查找时间复杂度为 O(1) 的特性,就可以一次循环快速得到结果。

最终,时间复杂度降到 O(n),空间复杂度则变成 O(n)。

 
package cn.fatedeity.algorithm.leetcode;
import java.util.HashMap;
public class TwoSum {
public int[] answer(int[] nums, int target) {
HashMap<Integer, Integer> hashMap = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int diff = target - nums[i];
if (hashMap.containsKey(diff)) {
return new int[]{hashMap.get(diff), i};
}
hashMap.put(nums[i], i);
}
return new int[0];
}
}
http://www.yidumall.com/news/27136.html

相关文章:

  • asp网站模板下载自媒体135免费版下载
  • wordpress 404.phpwin10系统优化
  • 网站建设活动计划兰州网络推广优化怎样
  • 做网站公司经营范围负面口碑营销案例
  • 台州低价网站建设互联网营销怎么赚钱
  • 12380网站建设页面设计
  • 优惠劵网站怎么做线下推广活动策划方案
  • 外贸网站空间选择深圳债务优化公司
  • wordpress投稿插件:submit posts网站文章优化技巧
  • 免费跨境电商平台有哪些网络优化工资一般多少
  • 西宁市营销网站建设公司厨师培训
  • wordpress 搜索 提示seo是什么职务
  • 阿里云Windows建立WordPressseo信息网
  • 网站建设及运营工作总结seo技术最新黑帽
  • 秀米编辑器seo搜索引擎优化薪酬
  • 佛山三水网站建设推广网站免费
  • 物业网站建设方案手机优化助手下载
  • 网站首页flash制作自动搜索关键词软件
  • 免费网站能到百度首页吗百度竞价怎么开户
  • 企业微信app下载安装安卓版如何优化培训体系
  • 阿里巴巴武汉网站建设全网搜索软件下载
  • 宁波新冠疫情最新消息上海网络seo
  • wordpress 测评宁波seo教程
  • php网站的开发背景网推接单平台有哪些
  • 专门做衬衣网站泰安seo推广
  • 中邦建设工程有限公司官方网站磁力蜘蛛种子搜索
  • 海南三亚8v1视频seo外链是什么意思
  • 做女团学什么舞蹈视频网站推广公司哪家好
  • 简单oa网站建设方案品牌网络推广运营公司
  • 公司网站建设代理一般做多久重庆seo黄智