今天毕业五年了,一直忙于工作和享受,自从当年找完工作后就一直没有再刷过题,作为搬砖的码农,觉得还是应该养成长期刷题的习惯坚持下去。之前坚持了每天被一会单词,如今雅思一本也快看完了,从今天开始准备在保证每周一题的最低基础上坚持下去,不为别的,主要是想多动脑,刷个几十年坚持下去,应该可以预防老年痴呆。。。
题目:
滑动窗口的解法:注意蛋疼的int[][]返回值类型,十分蛋疼
public class Solution
{
public int[][] FindContinuousSequence(int target)
{
List<int[]> res = new List<int[]>();
int leftIndex = 1;
int rightIndex = 2;
int loopNum = target/2 + 1;
target *= 2;
while(rightIndex <= loopNum)
{
int sum = (leftIndex + rightIndex) * (rightIndex - leftIndex + 1);
if(sum < target)
{
rightIndex++;
}
else if(sum > target)
{
leftIndex++;
}
else
{
List<int> seq = new List<int>();
for(int i = 0; i < rightIndex - leftIndex + 1; i++)
{
seq.Add(leftIndex + i);
}
res.Add(seq.ToArray());
leftIndex++;
rightIndex = leftIndex + 1;
}
}
return res.ToArray();
}
}