思路:两个嵌套的for循环(不推荐,应该有更好的。)
具体代码:function longestConsec(strarr, k) {
// your code
var n = strarr.length;
if(n == 0 || k > n || k <= 0)
return "";
var maxStr = "";
for(var l = 0; l < k; l++)
{
maxStr += strarr[l];
}
var tempStr = "";
for(var i = 0; i <= strarr.length - k; i++){
for(var j = 0; j < k; j++)
{
tempStr += strarr[i+j];
}
if(tempStr.length > maxStr.length)
maxStr = tempStr;
tempStr = "";
}
return maxStr;
}
时间: 2024-11-05 22:48:50