zoukankan      html  css  js  c++  java
  • leetcode 2SUM

         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 = 0; 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 = 0; i < v.size(); i++){
                for(int j = i+1; 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+1);
                        t.push_back(v[j].place+1);
                        sort(t.begin(),t.end());
                        return t;
                    }
                }
            }
            return numbers;
        }
    };
  • 相关阅读:
    消息中间件(MQ)
    java Lambda表达式
    【测试】性能测试及性能测试工具JMeter
    【Mysql】mysql集群方案之读写分离
    linux下mysql开启远程访问权限及防火墙开放3306端口
    MySQL事务提交与回滚
    MySQL索引
    MySQL视图
    MySQL事务
    MySQL参数化有效防止SQL注入
  • 原文地址:https://www.cnblogs.com/jilichuan/p/3997932.html
Copyright © 2011-2022 走看看