Skip to content

Commit

Permalink
No.3 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrevile committed Jan 22, 2022
1 parent 0d030f7 commit 229fd0c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions leetcode JS/No.3 Longest Substring Without Repeating Characters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @param {string} s
* @return {number}
*/
var lengthOfLongestSubstring = function (s) {
let temp = "";
let result = "";
let start = 0;
for (let i = 0; i < s.length; i++) {
let idx = temp.indexOf(s[i]);
if (idx !== -1) {
start = start + idx + 1;
}
temp = s.substring(start, i + 1);
if (result.length < temp.length) {
result = temp;
}
}
return result.length;
};

0 comments on commit 229fd0c

Please sign in to comment.