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. django博客项目7

    ................

  2. 流畅的python 对象引用 可变性和垃圾回收

    对象引用.可变性和垃圾回收 变量不是盒子 人们经常使用“变量是盒子”这样的比喻,但是这有碍于理解面向对象语言中的引用式变量.Python 变量类似于 Java 中的引用式变量,因此最好把它们理解为附加 ...

  3. 使用Xcode改动iOS项目project名和路径名

    对,好.错.改正. ------ 前言 系统 10.9 开发平台 xcode 5.0 旧project名 MyProject-iPad 改动之后 新project名 FjSk-iPad 点击项目,进入 ...

  4. Red Hat Enterprise Linux

    以下是支持 Docker 的 RHEL 版本: Red Hat Enterprise Linux 7 (64-bit) Red Hat Enterprise Linux 6.5 (64-bit) 或更 ...

  5. Webbench进行网站压力测试

    今天突然发现一个新大陆,Webbench,是linux下,用这很方便,开源,不限制并发访问次数和时间....大爱啊! 下载Webbench 使用wget  或者windows下载好导入linux也行, ...

  6. mysql 获取随机10条数据

    SELECT * FROM s_user WHERE id>= ((SELECT MAX(id) FROM s_user)-(SELECT MIN(id) FROM s_user)) * RAN ...

  7. 创建pfx数字证书

    相关参考: 安全工具: http://msdn.microsoft.com/zh-cn/library/dd233106(v=vs.110).aspx makecert: http://msdn.mi ...

  8. effective C++ 条款25 swap

    item 25:一个不抛异常的swap函数 标准库有一个swap用于交换两个对象值 namespace std{ template<typename T> void swap(T& ...

  9. Soap 教程

    SOAP 构建模块 一条 SOAP 消息就是一个普通的 XML 文档,包含下列元素: · 必需的 Envelope 元素,可把此 XML 文档标识为一条 SOAP 消息 · 可选的 Header 元素 ...

  10. HDOJ 1257 最少拦截系统 【DP】

    HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...