我正在尝试解决leetcode网站上的任务。我解决这个问题的方法是迭代一个字符串,然后填充第一个数组,直到我找到一个重复的字符,然后开始填充另一个数组,直到我在那里找到一个重复的字符。一旦我有两个填充数组,我会比较它们并保持较长的数组,直到我完成迭代。但是通过这些方法,我最终检查了很多事情并且不确定当我填充secondArray
时我该做什么,我仍然在做subiteration,以避免填充firstArray
。
一般来说,这段代码很麻烦,我不知道怎么解决这个问题?
s = "anviaj"
s = "eeydgwdykpv"
var lengthOfLongestSubstring = function(s) {
let firstArray = [];
let secondArray = [];
let firstArrayFull = false;
let secondArrayFull = false;
let subIterationFinished = false;
if (s.length == 1)
return s;
for (var i = 0; i < s.length -1; i++) {
if (!firstArrayFull) {
firstArray.push(s.charAt(i));
} else if (!secondArrayFull) { secondArray.push(s.charAt(i)); }
for (let j = i + 1; j < s.length; j++) {
if (j + 1 == s.length) {
subIterationFinished = true;
checkArrays();
}
if (!firstArrayFull && !firstArray.includes(s.charAt(j))) {
if (secondArrayFull && !subIterationFinished) {
firstArray = firstArray;
} else {
firstArray.push(s.charAt(j));
}
} else {
firstArrayFull = true;
if (secondArrayFull) {
checkArrays();
}
}
if (firstArrayFull && secondArray.length != 0 && secondArray.includes(s.charAt(j))) {
secondArrayFull = true;
checkArrays();
}
if (firstArrayFull && secondArray.length != 0 && !secondArray.includes(s.charAt(j))) {
secondArray.push(s.charAt(j));
}
}
}
function checkArrays() {
if (secondArray.length > firstArray.length) {
firstArray = [];
firstArrayFull = false;
secondArrayFull = true;
} else {
secondArray = [];
secondArrayFull = false;
firstArrayFull = true;
}
}
return secondArray.length > firstArray.length ? secondArray : firstArray;
};
console.log(lengthOfLongestSubstring(s));
答案 0 :(得分:1)
这很有挑战性,但我想出来了
这是一个O(n)解决方案。不能做得更好呢
function lengthOfLongestSubstring(str) {
var currentLength = 0;
var result = 0;
var keys = {};
for (var i in str) {
if (keys[str[i]] === true) {
currentLength = 0;
keys = {};
}
keys[str[i]] = true;
currentLength++;
if (currentLength > result) {
result = currentLength;
}
}
return result
}
console.log(lengthOfLongestSubstring("bbbbb"));
console.log(lengthOfLongestSubstring("abcdaajkljl"));
console.log(lengthOfLongestSubstring("pwwkew"));
console.log(lengthOfLongestSubstring("ysbghjjrfumqjpyktddsnxftvdqgxzlvrneaynufhgyqxwaqzelmbsiyxaubrqvguvehpmrykhvikkqzwttg"));
答案 1 :(得分:1)
这是一个有效, O(n)解决方案,它只构造一次最终字符串,针对20.000长度字符串进行测试(它应该仍然快速有一百万字符,但stackoverflow限制输入为30K字符。)
/**
* @param {string} s
* @return {number}
*/
var lengthOfLongestSubstring = function(s) {
var l = 0;
var r = 0;
var maxL = 0;
var maxR = 0;
var length = () => r - l;
var maxLength = () => maxR - maxL;
var keys = {};
while (r < s.length) {
if (s[r] in keys) {
var newL = keys[s[r]] + 1;
for (var i = l; i < newL; i++) {
delete keys[s[i]];
}
if (maxLength() < length()) {
maxL = l;
maxR = r;
}
l = newL;
}
keys[s[r]] = r;
r = r + 1;
}
if (maxLength() < length()) {
maxL = l;
maxR = r;
}
return maxLength();
};
console.log(lengthOfLongestSubstring("2sLbj8wBPPa5RYgNNwzuYQ7Pz3IehWrxOPiAxbGTw1wpEKyPnWLEuiEiW8vPFGENfjICBeNBeslmT8UZZD7AyUp1WKrC8OneS7GzfacqpzzGB4awH4O7CosGQp3fe3UYTqPT44hHtYfGTLKaZkIt6dA1XQQCzvUYCQFFEGWxzPDFZt2D7a8XT4UEuBrUYo4ml4xds7cQflVD8Hyr9bJcCfC6BeUutQb4SrqUR3SlLNVMVlXEYsHLKbXjl0zYNFeIatfvx5w7UNEfLGqhtzNvGKVixQQ6OIIH835jo7IYp6G7FumW9asgKSjbbEQhfWKenep8yL3psmb1eUl2vWGxDKo8Z82UB4M5LcZ4o2W9nGHrpAkyOdJb6WIc3sfeThMAUHA7Ykh9bNmDrmW7J44eJ1XLbrN6xHnUC8LrGXYlFCh7x1bkjyy08Z7LVQGhnuDU1ZaovmKoTrtgPzvIEESakLXxB2t0RbrTVr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(得分:0)
使用两个变量,一个用于跟踪最长的子字符串,另一个用于跟踪当前最长的子字符串而不重复。 迭代你的字符串。 检查当前单词是否包含当前字符。
如果它包含,则检查具有最长子串的当前单词的长度。如果它更大,则更新最长的子字符串。
将当前单词从上次查看的索引更新为当前单词的长度。
继续直到输入字符串结束。
var lengthOfLongestSubstring = function(s) {
var longestSubstring = '';
var currentWord = '';
for(var i = 0 ; i < s.length ; i++){
var foundIndex = currentWord.indexOf(s[i]);
if(foundIndex > -1){
if(longestSubstring.length < currentWord.length)
longestSubstring = currentWord;
currentWord = currentWord.slice(foundIndex+1);
}
currentWord += s[i];
}
return longestSubstring.length < currentWord.length ? currentWord.length : longestSubstring.length;
};
console.log(lengthOfLongestSubstring("bbbbb"));
console.log(lengthOfLongestSubstring("abcdaajkljl"));
console.log(lengthOfLongestSubstring("pwwkew"));
console.log(lengthOfLongestSubstring("ysbghjjrfumqjpyktddsnxftvdqgxzlvrneaynufhgyqxwaqzelmbsiyxaubrqvguvehpmrykhvikkqzwttg"));
答案 3 :(得分:-1)
可以使用String#includes()
检查您的子字符串是否有重复
s = "anviaj"
s1 = "eeydgwdykpv"
function findLongest(str) {
// reduce() iterates array created from split input and returns longest sub string
return str.split('').reduce((a,c,i)=>{
// start our substring using first character of str
let sub = str[0], j = 0;
// sub.includes(char) returns true if char already in sub string
while (++j < str.length && !sub.includes(str[j])) {
// no duplicate so add char to substring
sub += str[j];
}
// remove first character from input string each iteration
str = str.slice(1);
// replace current longest if applicable
return sub.length > a.length ? sub : a;
},'');
}
console.log(findLongest(s))
console.log(findLongest(s1))
&#13;