41.和为s的两个数字VS和为s的连续正数序列

bool FindNumbersWithSum(int data[], int length, int sum, int* num1, int* num2)
{
bool found = false;
if (length < 1 || num1 == NULL || num2 == NULL)
return found;
int ahead = length - 1;
int behind = 0;
{
long long curSum = data[ahead] + data[behind];
if (curSum == sum)
{
*num1 = data[behind];
found = true;
break;
}
else if (curSum > sum)
else
behind++;
}
return found;
}

void FindContinuousSequence(int sum)
{
if (sum < 3)
return;
int small = 1;
int big = 2;
int middle = (1 + sum) / 2;
int curSum = small + big;
while (sum<middle)
{
if (curSum == sum)
PrintContinuousSequence(small, big);
while (curSum > sum&&small < middle)
{
curSum -= small;
small++;
if (curSum == sum)
PrintContinuousSequence(small, big);
}
big++;
curSum += big;
}
}
void PrintContinuousSequence(int small,int big)
{
for (int i = small; i <= big; ++i)
printf("%d",i);
printf("\n");
}

剑指Offer面试题41（Java版）：和为s的两个数字VS和为s的连续正数序列

2015-08-10 19:47:11

剑指Offer：和为s的两个数字VS和为s的连续正数序列

2018-02-27 14:56:08

剑指Offer面试题41：求和为s的两个数字；求和为s的连续正数序列 Java实现

2016-09-25 16:40:44

剑指offer面试题之和为S的连续正数序列

2016-04-04 19:18:18

剑指offer----和为S的连续正数序列----java实现

2016-08-15 12:48:23

输出所有和为S的连续正数序列。序列内按照从小至大的顺序，序列间按照开始数字从小到大的顺序

2017-11-20 20:46:33

剑指Offer——输入正整数S,打印出所有和为S的连续正数序列（至少含有两个正数）

2016-04-07 14:16:52

牛客网刷题之和为S的连续正数序列

2016-10-29 09:31:38

《剑指offer》——和为s的连续整数序列

2016-02-24 10:28:31

不良信息举报

41.和为s的两个数字VS和为s的连续正数序列