struct vp{
        int value;
        int place;
    };
    bool comp(const struct vp a, const struct vp b){
        return a.value<b.value;
    } class Solution {
public:          
    vector<int> twoSum(vector<int> &numbers, int target) {
        vector<struct vp> v ;
        for(int i = ; i < numbers.size(); ++i){
            struct vp tmp;
            tmp.value = numbers[i];
            tmp.place = i;
            v.push_back(tmp);
        }
        sort(v.begin(), v.end(),comp);
        for(int i = ; i < v.size(); i++){
            for(int j = i+; j < v.size(); j++){
                if(v[i].value + v[j].value > target){
                    break;
                }
                if(v[i].value + v[j].value < target){
                    continue;
                }
                if(v[i].value + v[j].value == target){
                    vector<int> t ;
                    t.push_back(v[i].place+);
                    t.push_back(v[j].place+);
                    sort(t.begin(),t.end());
                    return t;
                }
            }
        }
        return numbers;
    }
};

leetcode 2SUM的更多相关文章

  1. 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)

    转自  http://tech-wonderland.net/blog/summary-of-ksum-problems.html 前言: 做过leetcode的人都知道, 里面有2sum, 3sum ...

  2. k sum 问题系列

    转自:http://tech-wonderland.net/blog/summary-of-ksum-problems.html (中文旧版)前言: 做过leetcode的人都知道, 里面有2sum, ...

  3. LeetCode解题报告--2Sum, 3Sum, 4Sum, K Sum求和问题总结

    前言: 这几天在做LeetCode 里面有2sum, 3sum(closest), 4sum等问题, 这类问题是典型的递归思路解题.该这类问题的关键在于,在进行求和求解前,要先排序Arrays.sor ...

  4. LeetCode 3Sum Closest 最近似的3sum(2sum方法)

    题意:找到最接近target的3个元素之和,并返回该和. 思路:用2个指针,时间复杂度O(n^2). int threeSumClosest(vector<int>& nums, ...

  5. [LeetCode] Minimum Size Subarray Sum 最短子数组之和

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  6. Leetcode OJ 刷题

    Valid Palindrome吐槽一下Leetcode上各种不定义标准的输入输出(只是面试时起码能够问一下输入输出格式...),此篇文章不是详细的题解,是自己刷LeetCode的一个笔记吧,尽管没有 ...

  7. leetcode & lintcode for bug-free

    刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...

  8. LeetCode 259. 3Sum Smaller (三数之和较小值) $

    Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 < ...

  9. LeetCode第[1]题(Java):Two Sum 标签:Array

    题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...

随机推荐

  1. explorer.exe中发生未处理的win32异常

    explorer.exe中发生未处理的win32异常的错误提示,是windows系统比较常见的错误事件,多数在开机遇到,也有在电脑使用过程中遇到. 了解explorer.exe进程 从百度百科了解到, ...

  2. django之多表查询与创建

    https://www.cnblogs.com/liuqingzheng/articles/9499252.html # 一对多新增数据 添加一本北京出版社出版的书 第一种方式 ret=Book.ob ...

  3. java 多线程 day01 创建线程

    线程,即代码的执行路径java 面向对象编程.所以线程在java中也是用对象来表示的,创建线程对象的类就是 Thread如下代码即开启一个新的线程,通过线程对象的start方法,即可启动线程 Thre ...

  4. Java AES512加密算法

    AES - 高级加密标准: 高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.这 ...

  5. python16_day15【Django入门】

    一.Django基本 1.什么是框架 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表 ...

  6. str()和repr()(以及``操作符)

    内建函数str()和repr()或反引号操作符(``)可以方便的获取字符串. str它会把值转换为合理形式的字符串,可读性更好,同时对用户来说更加友好. repr它会创建一个字符串,以合法的Pytho ...

  7. Python函数之初体验

    定义函数 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回. 我们先定义一个求字符串长度的函数 ...

  8. Java基础知识陷阱(一)

    本文发表于本人博客. 事隔好多年了,重新拿起来Java这门语言,看似熟悉其实还很陌生,想想应该梳理下顺便提高下自己.这次先来看看Java里面的String这个对象. 经典的先看下面一段代码,请问最终创 ...

  9. Alluxio 安装与配置

    一.概述 Alluxio, formerly Tachyon, enables any application to interact with any data from any storage s ...

  10. web标准的理解

    首先,什么是web标准?web标准是w3c组织为解决跨浏览器兼容问题而推出的关于网页开发时应遵守的规范.在网页的四个部分中网页的内容是由网页开发者自己定义的,因此这一部分无法标准化,而网页的结构(HT ...