国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1. Two Sum

2019-11-06 08:21:17
字體:
來源:轉載
供稿:網友

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example: Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].

#include<algorithm>class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> re;//存儲結果 vector<int> temp=nums;//存儲原來的輸出 int low=0,high=nums.size()-1; sort(nums.begin(),nums.end());//對原來輸出進行排序 while(nums[low]+nums[high]!=target)//求那兩個數的排序后位置 { if(nums[low]+nums[high]>target) high--; else low++; } low=nums[low];//求那兩個數的值 high=nums[high]; for(int t=0;t<nums.size();t++)//通過值來求原來的位置 if(temp[t]==low || temp[t]==high) re.push_back(t); return re; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 静安区| 全南县| 临朐县| 广河县| 客服| 涞源县| 从江县| 铜鼓县| 黄骅市| 横山县| 大名县| 安新县| 青河县| 图木舒克市| 武义县| 青铜峡市| 崇仁县| 赤城县| 巩义市| 峨眉山市| 铅山县| 闻喜县| 类乌齐县| 清流县| 昌黎县| 井冈山市| 兴文县| 集贤县| 疏附县| 太谷县| 凯里市| 二连浩特市| 荣昌县| 香港 | 呼和浩特市| 莫力| 公安县| 宾阳县| 江山市| 阳江市| 壤塘县|