Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit30ac3db

Browse files
author
sambabib
committed
added js solution to _3
1 parentbde6a61 commit30ac3db

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ out/
77
*.vscode/
88
src/main/java/com/fishercoder/solutions/_99999RandomQuestions.java
99
src/main/java/com/fishercoder/solutions/_Contest.java
10-
.project
10+
.project
11+
bin

‎javascript/_3.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
functionlengthOfLongestSubstring(s){
2+
// Using the "sliding window" data structure.
3+
// Create a javascript set to store unique characters.
4+
letcharSet=newSet();
5+
letleft=0;// Left pointer of the sliding window.
6+
letmaxLength=0;
7+
8+
// This moves the right pointer of the sliding window.
9+
for(letright=0;right<s.length;right++){
10+
// If the character at the right pointer is already in the set, move the left pointer.
11+
while(charSet.has(s[right])){
12+
charSet.delete(s[left]);
13+
left++;
14+
}
15+
// Add the current character at the right pointer to the set.
16+
charSet.add(s[right]);
17+
18+
// Update the maximum length of substring without repeating characters.
19+
maxLength=Math.max(maxLength,right-left+1);
20+
}
21+
22+
returnmaxLength;
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp