vector<int> twoSum(vector<int>& nums, int target)
{unordered_map<int,int> hash;int n=nums.size();for(int i=0;i<n;++i){if(hash[target-nums[i]]) return {i,hash[target-nums[i]]-1};hash[nums[i]]=i+1;}return {0,0};
}

转载于:https://www.cnblogs.com/xLester/p/7570284.html

[LeetCode] 1. Two Sum相关推荐

  1. leetcode 304. Range Sum Query 2D - Immutable |304. 二维区域和检索 - 矩阵不可变(二维前缀和问题)

    题目 https://leetcode.com/problems/range-sum-query-2d-immutable/ 题解 本题是 medium 难度,二维前缀和问题.相似题目有: Easy: ...

  2. 【动态规划】LeetCode 377. Combination Sum IV

    LeetCode 377. Combination Sum IV Solution1: 我的未能AC的答案 题目描述的和前几道题差不多,但实际上不能用DFS来做(会超时),要用动态规划,还是记录一下吧 ...

  3. 【DFS】LeetCode 39. Combination Sum

    LeetCode 39. Combination Sum Solution1: DFS,这个套路要熟记啊! class Solution { public:vector<vector<in ...

  4. LeetCode 167.Two Sum II 解题报告

    LeetCode 167.Two Sum II 解题报告 题目描述 Given an array of integers that is already sorted in ascending ord ...

  5. leetcode 1005 Maximize Sum Of Array After K Negations

    leetcode 1005 Maximize Sum Of Array After K Negations 1.题目描述 2.解题思路 3.Python代码 1.题目描述 给定一个整数数组 A,我们只 ...

  6. [勇者闯LeetCode] 1. Two Sum

    [勇者闯LeetCode] 1. Two Sum Description Given an array of integers, return indices of the two numbers s ...

  7. [勇者闯LeetCode] 112. Path Sum

    [勇者闯LeetCode] 112. Path Sum Description Given a binary tree and a sum, determine if the tree has a r ...

  8. 数据结构线段树介绍与笔试算法题-LeetCode 307. Range Sum Query - Mutable--Java解法

    此文首发于我的个人博客:zhang0peter的个人博客 LeetCode题解文章分类:LeetCode题解文章集合 LeetCode 所有题目总结:LeetCode 所有题目总结 线段树(Segme ...

  9. LeetCode 653. Two Sum IV - Input is a BST--Python解法

    题目地址:Two Sum IV - Input is a BST - LeetCode Given a Binary Search Tree and a target number, return t ...

  10. LeetCode 167. Two Sum II - Input array is sorted--Python解法

    题目地址:Two Sum II - Input array is sorted - LeetCode Given an array of integers that is already sorted ...

最新文章

  1. oracle 分区使用情况,Oracle Hash分区的使用总结
  2. [CQOI2011]动态逆序对
  3. JVM调优总结(2):一些概念(下)
  4. java post 打开新页面_JAVA后台POST/GET访问方法
  5. Pytest+Allure+Jenkins接口自动化项目实战(一)
  6. Netstars CTO陈斌:架构师的成长之路
  7. 中表名字必须大写吗_pi network改名字的重要性—非常之重要!!
  8. 周报(2017.3.19-3.16)
  9. Java 并发编程之 volatile
  10. OpenCV-计算二维矢量幅值cv::magnitude
  11. 一个 JS 框架需要做什么
  12. 装饰模式案列(OutputStream)
  13. opencv 识别微信登录验证滑动块位置
  14. Flask框架从入门到精通之消息闪现和日志记录(二十一)
  15. python爬虫入门教程04:招聘信息爬取
  16. Prometheus + Grafana 图形化监控实践
  17. [CAS]ServiceTicket [x] with service [x] does not match supplied service [x]
  18. STM32CubeMX基于HAL库实现简单串口通信
  19. linux系统中uboot的基本原理与实现方法
  20. linux获取本地ip

热门文章

  1. leetcode - 4. Median of Two Sorted Arrays
  2. [BZOJ1602BZOJ1787BZOJ2144]树上LCA的算法巩固练习
  3. Java阻塞队列的实现
  4. PAT:1031. 查验身份证(15) AC
  5. C++之---友元函数
  6. PyTorch 入坑八:卷积与转置卷积
  7. java jsp 特殊标签_JSP复习(四):JSTL标记
  8. 怎么检测mysql查询是否慢_MySQL慢查询查找和调优测试
  9. win7专业版 .bat脚本运行_IT运维老司机:聊聊BAT批处理提升工作效率
  10. web高德地图怎么加载离线地图_春节变胖了?高德地图隐藏的实用跑步功能 想怎么跑都随你...