long sum = 0;
int start = 0;
int end = 0;
while(start < sequence.length) {
if(sum > k || end == sequence.length) {
sum -= sequence[start];
start++;
}else{
sum += sequence[end];
end++;
}
if(sum == k) {
if(end-1 - start < answer[1] - answer[0]) {
answer[0] = start;
answer[1] = end-1;
}
}
}
Plain Text
๋ณต์ฌ