题目: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. jsoup HTML parser hello world examples--转

    原文地址:http://www.mkyong.com/java/jsoup-html-parser-hello-world-examples/ Jsoup, a HTML parser, its “j ...

  2. 【转】C# ABP WebApi与Swagger UI的集成

    以前在做WebAPI调用测试时,一直在使用Fiddler测试工具了,而且这个用起来比较繁琐,需要各种配置,并且不直观,还有一点是还得弄明白URL地址和要传递的参数,然后才能调用.  最近新入职,公司里 ...

  3. Log4net根据日志等级输出到不同文件

    <?xml version="1.0" encoding="utf-8"?> <configuration> <configSec ...

  4. gcc编译c中有与lua交互的代码

    编译C程序中有与Lua有关的程序(编译环境是Linux系统,lua解释器是luajit)gcc -o test30 test30.cpp -I/usr/local/include/luajit-2.0 ...

  5. Python多线程原理与实现

    Date: 2019-06-04 Author: Sun Python多线程原理与实战 目的: (1)了解python线程执行原理 (2)掌握多线程编程与线程同步 (3)了解线程池的使用 1 线程基本 ...

  6. 记一次mybatis<if>标签的问题

    前言 到底还是没理解清楚的锅~~~~搞了好久...啊啊啊啊 错误: There is no getter for property named 'name' in 'class java.lang.L ...

  7. 路飞学城Python-Day37(practise)

    #1.自行创建测试数据 create database homework; use homework; # 年级表->老师表->课程表->班级表->学生表->成绩表-&g ...

  8. Java简述

    Java的特点(11个关键术语)from<Java核心技术I> 1) 简单性 2)  面向对象 3)  分布式 Java有一个丰富的例程库,用于处理像HTTP和FTP之类的TCP/IP协议 ...

  9. nefu 84 ( 拓展欧几里德模板题 )

    链接:传送门 思路:拓展欧几里德模板题,设大圣至少翻转 t 次,大圣起始位置为 x ,大圣目标位置为 y + n * s ( 大圣到达目标位置 y 可能需要多圈,所以用 s 来表示圈数 ),因为只能逆 ...

  10. Mybatis之MySql批量insert后返回主键

    需求:使用批量插入后,需要insert之后的每一条记录的ID 注意:Mybatis3.3.1的版本以后支持批量插入后返回主键ID 示例: domin.java: public class User { ...