×

Loading...

Java Implementation is here:

iamflying (自食其水果)
public static int getMaxSeqSize(int... input) {
Arrays.sort(input);
int maxLen = 1;
int end = input.length - maxLen;
for (int first = 0; first < end; first++) {
for (int second = first + 1; second <= end; second++) {
int leap = input[second] - input[first];
int next = input[second] + leap;
int len = 2;
for (int i = second +1; i < input.length; i++) {
if (input[i] == next) {
len++;
next += leap;
} else if (input[i] > next) {
break;
}
}
if (len > maxLen) {
maxLen = len;
end = input.length - maxLen;
}
}
}
return maxLen;
}
(#9937189@0)
2016-2-10 -05:00
Reply
Page address has been copied.
To share, click to copy page address.
Share Online by QR Code

Back To Topic: 一道面试题,大家给出出主意哈,我一点头绪都没有

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习学科技术