167. Two Sum II - Input array is sorted
问题描述
解决方案
class Solution {
public:vector<int> twoSum(vector<int>& numbers, int target) {int index1=0,index2=numbers.size()-1;while(index1<index2){if((numbers[index1]+numbers[index2])==target) break;else if((numbers[index1]+numbers[index2])>target) --index2;else++index1;}return vector<int> {index1+1,index2+1};}
};
转载于:https://www.cnblogs.com/ucas/p/5800769.html
167. Two Sum II - Input array is sorted相关推荐
- 167. Two Sum II - Input array is sorted (C, C++, Python)
本文讲述了Array类中第167个问题的几种解法,实现语言包括C,Python以及C++. 问题: Given an array of integers that is already sorted ...
- LeetCode 167. Two Sum II - Input array is sorted
题目 : Given an array of integers that is already sorted in ascending order, find two numbers such tha ...
- leetcode python3 简单题167. Two Sum II - Input array is sorted
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百六十七题 (1)题目 英文: Given an array of intege ...
- [LeetCode By Python]167. Two Sum II - Input array is sorted
题目: Given an array of integers that is already sorted in ascending order, find two numbers such that ...
- 【LeetCode 剑指offer刷题】数组题2:57 有序数组中和为s的两个数(167 Two Sum II - Input array is sorted)...
[LeetCode & 剑指offer 刷题笔记]目录(持续更新中...) 57 有序数组中和为s的两个数 题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是 ...
- 167. Two Sum II - Input array is sorted 两数之和 II - 输入有序数组
Title 给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明: ...
- leetcode 167 Two Sum II - Input array is sorted
给定一个有序的数组,和一个整数目标,求两个数的和等于目标的索引,索引从1开始.假设必定存在解. 有两种思路: 直接找: vector<int> twoSum(vector<int&g ...
- 167. Two Sum II - Input array is sorted两数之和
1. 原始题目 给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明 ...
- LeetCode 167. Two Sum II - Input array is sorted--Python解法
题目地址:Two Sum II - Input array is sorted - LeetCode Given an array of integers that is already sorted ...
最新文章
- C语言实现的Web服务器(转-kungstriving)
- java中日期计算时间差,用java计算日期/时间差
- Discuz升级 Database Error : pre_common_syscache ADD PRIMARY KEY (cname)【解决办法】
- SD初始化过程以及Cmd解析
- C#Winform窗体实现服务端和客户端通信例子(TCP/IP)
- 本科是最底层?学历真的那么重要么?
- Python 字符串和列表的转化 ,简单到尖叫
- 华为云龙api自动化工具_聊聊华为GDE刚发布的一体化低门槛开发平台ADC 2.0
- JSch连接不上Linux服务器,JSch链接linux服务器问题解决方案:Session.connect: java.io.IOException: End of IO Stream Read...
- 知识分享 | 卡方分析的入门小知识
- Hive 字符串转日期
- 江西省谷歌高清卫星地图下载
- 今天看了了一下手册,先弄清楚芯片脚功能
- k2ttl救砖_无线路由救砖 ttl刷机教程
- 怎样设置默认打印机(HttpPrinter 易桥打印中间件)
- html怎么给图片加倒影,用CSS3实现图片倒影效果,同时给出兼容早期版本IE的方案...
- SpringBoot22-spingboot数据访问-Spring Data JPA
- pg创建数据库和用户并授权
- 阿里云大学-虚拟化技术入门-听课笔记
- 清华计算机考研复试机试,清华大学历年考研复试机试真题 - 论文