1.Two Sum

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

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,

return [0, 1].

记录第一个LeetCode题, c++的STL库不会用, (╥╯^╰╥)

class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> ret; for (int i = 0; i < nums.size() - 1; i++) {
for (int j = i + 1; j < nums.size(); j++) {
if(target == (nums[i] + nums[j])){
ret.push_back(i);
ret.push_back(j);
return ret;
}
}
}
return ret;
}
};

1_Two Sum的更多相关文章

  1. 1_Two Sum --LeetCode

    原题如下: 思路:将nums放到一个map<int,int>中,其中,键是nums中元素,值对应其下标.然后遍历nums,取nums中一个值nums[i],接着用target减去它,最后再 ...

  2. LeetCode - Two Sum

    Two Sum 題目連結 官網題目說明: 解法: 從給定的一組值內找出第一組兩數相加剛好等於給定的目標值,暴力解很簡單(只會這樣= =),兩個迴圈,只要找到相加的值就跳出. /// <summa ...

  3. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  4. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  5. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  6. BZOJ 3944 Sum

    题目链接:Sum 嗯--不要在意--我发这篇博客只是为了保存一下杜教筛的板子的-- 你说你不会杜教筛?有一篇博客写的很好,看完应该就会了-- 这道题就是杜教筛板子题,也没什么好讲的-- 下面贴代码(不 ...

  7. [LeetCode] Path Sum III 二叉树的路径和之三

    You are given a binary tree in which each node contains an integer value. Find the number of paths t ...

  8. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  9. [LeetCode] Split Array Largest Sum 分割数组的最大值

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

随机推荐

  1. c++ 中. 和 ->,波浪号 ~ 符号怎么用 ————很重要

    参考:https://www.cnblogs.com/Simulation-Campus/p/8809999.html 1.  用在类中的析构函数之前,表示该函数是析构函数.如类A的析构函数 clas ...

  2. FOV

    来源:https://blog.csdn.net/chepwavege/article/details/98876550 视场 (视图字段) 是指现场对面相机镜头的立体角.图如下图所示︰ 高频通气︰  ...

  3. JavaFX FileChooser文件选择器,缓存上一次打开的目录

    例1:点击按钮Choose File打开文件选择器,并打开指定的目录.这是通过final void setInitialDirectory(final File value)方法实现的. 1 impo ...

  4. 伺服电机的Arduino库函数

    servo.attach(pin)  //连接伺服电机的信号线于控制板的引脚,9或10号引脚servo.attach(pin, min, max) servo: a variable of type ...

  5. Ubuntu通过Nginx安装Webdav

    使用KeePass保存密码,在个人服务器上安装WebDav协议. # nginx nginx-extras apache2-utils sudo aptitude install nginx ngin ...

  6. Docker安装MongoDB、MySQL、Jenkins、Gitlab、Nginx

    Docker安装MongoDB.MySQL.Jenkins.Gitlab.Nginx 安装MongoDB 1. 拉取镜像 $ sudo docker pull mongo 2. 运行镜像 $ sudo ...

  7. Jmeter JDBC Request 使用详解

    本篇博文讲解以MySQL为例,搞懂JDBC Request中MySQL的使用方法,换成其它数据库, 如Oracle.PSQL也会很容易上手. 一.基本配置 1.首先我们先了解一下,不同数据库的驱动类和 ...

  8. php数据显示在html截取字符

    <?php    echo mb_subsrt($s['content'],0,20,'gbkj')?> gbk也可以是utf8根据实际情况来

  9. Flask实现群聊

    后端 from geventwebsocket.handler import WebSocketHandler from gevent.pywsgi import WSGIServer from ge ...

  10. pytest文档45-allure添加环境配置(environment)

    前言 在 allure 报告首页 ENVIRONMENT 显示 'There are no environment variables' 没有环境变量的配置信息. 环境变量配置可以添加报告相关的配置参 ...