Skip to content

Files

Latest commit

3d9c8ef · Mar 12, 2019

History

History
16 lines (10 loc) · 500 Bytes

和为s的两个数字.md

File metadata and controls

16 lines (10 loc) · 500 Bytes

和为s的两个数字

知识点:

题目描述

输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的。 输出描述: 对应每个测试案例,输出两个数,小的先输出。

解题思路

设立两个指针p1初始指向a[0],p2初始指向a[-1],如果p1+p2的值大于sum,则p2--,否则p1++

代码

这里