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. JD-GUI

    JD-GUI http://jd.benow.ca/ JD-GUI可到官網直接下載.官網除了JD-GUI之外,另提供了Eclipse(JD-Eclipse)和IntelliJ(JD-IntelliJ) ...

  2. 第03章—打造RESTful风格API

    spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...

  3. 利用Django中间件middleware解决用户未登录问题(转)

    add by zhj: Django的中间件一般用于处理通用性的问题,分为五种,按处理顺序为request_middleware,view_middleware,exception_middlewar ...

  4. 001-前端系列-react系列

    一.概述 原文地址:http://www.ruanyifeng.com/blog/2016/09/react-technology-stack.html 二.摘要 ES6 语法:教程 [可以了解] B ...

  5. beego——原生SQL查询

    使用Raw SQL查询,无需使用ORM表定义. 多数据库,都可直接使用占位符号?,自动转换. 查询时的参数,支持使用Model Struct和Slice,Array ids := []int{1, 2 ...

  6. Unity,自带Random函数,上下限注意的地方

    Random.Range() 该函数有两个重载,分别是 float和 int 的,这两者还是有差别的,具体是: float型,随机值涵盖: 最小和最大值 Random.Range(0f,1f) 是有可 ...

  7. hive--[ array、map、struct]使用

    复合数据类型 Structs: structs内部的数据可以通过DOT(.)来存取,例如,表中一列c的类型为STRUCT{a INT; b INT},我们可以通过c.a来访问域a Maps(K-V对) ...

  8. python入门四:异常

    一.异常 异常就是在触发异常条件时(解释器或程序员)而采取相应的措施 c++中异常使用try, throw, catch等关键字,而python中使用try, raise, except等 二.标准异 ...

  9. angularjs 的controller的三种写法

    AngularJS 的controller其实就是一个方法,它有三种写法: 第一种: <pre name="code" class="javascript" ...

  10. 认识shiro

    shiro是安全(权限)框架,不仅可以在javase中也可以在javaee中 shiro可以完成认证.授权.加密.会话管理,与web进行集成.缓存等. Authentication:身份认证/登录,验 ...