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. img标签使用onload进行src更改时出现的内存溢出问题

    最近在开发时需要在img标签加载完成后修改src属性,使用了onload方法. 但是在方法体中最后没有把onload事件指向null, 导致了循环调用onload方法,CPU占用一直居高不下,最后只要 ...

  2. Java 常用工具类之基本对象包装类

    为了方便操作基本数据类型值, 将其包装成对象, 在对象中定义了属性和行为, 丰富了该数据的操作. 用于描述该对象的类就称为基本数据类型对象包装类. 基本数据类型对应关系 基本数据类型(8种) 包装类 ...

  3. 这些Python骚操作,你知道吗?

    0x00 世界,你好 ​程序员第一次接触语言或者框架,基本上都有个 Hello World 的例子,这里 Python 直接将它做成了一个包. 0x01 Python 哲学 ​ Python 执行 i ...

  4. SSD(Single Shot MultiBox Detector)二读paper

    SSD KeyWords:Real-time Object Detection; Convolutional Neural Network Introduction 目前最尖端(State-of-ar ...

  5. linux c编程:Posix信号量

    POSIX信号量接口,意在解决XSI信号量接口的几个不足之处: POSIX信号量接口相比于XSI信号量接口,允许更高性能的实现. POSIX信号量接口简单易用:没有信号量集,其中一些接口模仿了我们熟悉 ...

  6. sql server迁移数据(文件组之间的互相迁移与 文件组内文件的互相迁移)

    转自:https://www.cnblogs.com/lyhabc/p/3504380.html?utm_source=tuicool SQLSERVER将数据移到另一个文件组之后清空文件组并删除文件 ...

  7. (转)VLC播放RTP打包发送的.264文件

    VLC播放RTP打包发送的.264文件 1,要有一个发送RTP包的264文件的服务器; 具体代码如下: rtp.h #include <WinSock2.h> #pragma commen ...

  8. 关于shared pool的深入探讨(二)【转载】

    关于shared pool的深入探讨(二)   作者:eygle |English [转载时请标明出处和作者信息]|[恩墨学院 OCM培训传DBA成功之道]链接:http://www.eygle.co ...

  9. Mahout学习路线图-张丹老师

    前言 Mahout是Hadoop家族中与众不同的一个成员,是基于一个Hadoop的机器学习和数据挖掘的分布式计算框架.Mahout是一个跨学科产品,同时也是我认为Hadoop家族中,最有竞争力,最难掌 ...

  10. C# 并行 反射 去掉实体属性多余空格

          有时会遇到很多不合理的数据附件到实体后有大量空格需要处理,这里提供一个方法,通过并行反射的方式高效清理空格.   Code: //清除字符串空格 public static object ...