Skip to content

Commit 71cfef1

Browse files
committed
longest-substring-without-repeating-characters solution
1 parent 22ae50f commit 71cfef1

File tree

1 file changed

+27
-0
lines changed
  • longest-substring-without-repeating-characters

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var lengthOfLongestSubstring = function(s) {
6+
let maxLength = 0;
7+
const charSet = new Set();
8+
9+
let start = 0, end = 0;
10+
11+
while (end < s.length) {
12+
if (charSet.has(s[end])) {
13+
charSet.delete(s[start]);
14+
start += 1;
15+
continue;
16+
}
17+
18+
charSet.add(s[end]);
19+
end += 1;
20+
maxLength = Math.max(maxLength, end - start);
21+
}
22+
23+
return maxLength;
24+
};
25+
26+
// 시간복잡도: O(n)
27+
// 공간복잡도: O(n)

0 commit comments

Comments
 (0)