题目:https://leetcode.com/problems/two-sum/description/

stl map代码:

class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
map<int,int> m;
vector<int> v;
for(int i = ;i < nums.size(); i++){
if(m[target - nums[i]] != ){
v.push_back(m[target - nums[i]]-);
v.push_back(i);
break;
}
m[nums[i]] = i+;
}
return v;
}
};

LeetCode 1. Two Sum (c++ stl map)的更多相关文章

  1. LeetCode 437. Path Sum III (STL map前缀和)

    找遍所有路径,特判以根为起点的串即可. 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * Tr ...

  2. Leetcode 1. Two Sum(hash+stl)

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  3. LeetCode 1 Two Sum 解题报告

    LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...

  4. [LeetCode] #167# Two Sum II : 数组/二分查找/双指针

    一. 题目 1. Two Sum II Given an array of integers that is already sorted in ascending order, find two n ...

  5. POJ 3096 Surprising Strings(STL map string set vector)

    题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...

  6. LeetCode 560. Subarray Sum Equals K (子数组之和等于K)

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  7. LeetCode one Two Sum

    LeetCode one Two Sum (JAVA) 简介:给定一个数组和目标值,寻找数组中符合求和条件的两个数. 问题详解: 给定一个数据类型为int的数组,一个数据类型为int的目标值targe ...

  8. [LeetCode] 1. Two Sum 两数和

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  9. stl::map之const函数访问

    如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const ...

随机推荐

  1. QT-解除connect

    前言:解除关联. 一.新建工程 二.新建部件 在ui设计界面拖入一个line edit,一个label以及两个button按钮 右键“关联”按钮转到槽,选择clicked(),添加如下代码: void ...

  2. Windows环境下配置thrift编译器(VS2015)

        参考官方文档:http://svn.apache.org/repos/asf/thrift/attic/trunk/compiler/cpp/README_Windows.txt   编译器( ...

  3. Java之Foreach语句

    Foreach是for语句的特殊简化版本,但任何时候的foreach语句都可以改写成for语句.Foreach语句在遍历数组等方面为程序员提供了很大的方便 语法如下: For(元素变量 x:遍历对象o ...

  4. CorelDRAW X6冰点价加推800套燃爆6月

    CorelDRAW是迄今最具创意的图形设计程序,并获得所有行业的公认的知名工具.在刚刚结束的CorelDRAW X6限量活动之后,CorelDRAW官方继续加推800套CorelDRAW X6满足用户 ...

  5. 在用HTML+css写页面中遇到的问题

    一.清除浮动. (1)verflow:hidden;这个CSS样式是大家常用到的CSS样式,但是大多数人对这个样式的理解仅仅局限于隐藏溢出,而对于清除浮动这个含义不是很 了解.一提到清除浮动,我们就会 ...

  6. Linux系统串口接收数据编

    http://blog.csdn.net/bg2bkk/article/details/8668576 之前基于IBM deveplopworks社区的代码,做了串口初始化和发送的程序,今天在此基础上 ...

  7. 从YV12到NV12

    Media SDK的decoder,vpp,encoder对输入输出格式有着严格的限制,现在仅仅支持NV12.那么如何从其他格式转化为NV12是日常工作中经常遇到的事情.本篇文章以此为目的,讨论如何将 ...

  8. selenium chrome.options禁止加载图片和js

    #新建一个选项卡 from selenium import webdriver options = webdriver.ChromeOptions() #禁止加载图片 prefs = { 'profi ...

  9. JavaScript中的基础测试题

                                                                                                    Java ...

  10. 2015 Multi-University Training Contest 7 hdu 5372 Segment Game

    Segment Game Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...