We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8706278 commit 49b8c7aCopy full SHA for 49b8c7a
.gitignore
@@ -1,4 +1,3 @@
1
-3-lengthOfLongestSubstring.js
2
4-medianOfTwoSortedArrays.js
3
5-longestPalindromicSubstring.js
4
6-ZigZagConversion.js
3-lengthOfLongestSubstring.js
@@ -0,0 +1,23 @@
+/**
+ * @param {string} s
+ * @return {number}
+ */
5
+var lengthOfLongestSubstring = function (s) {
6
+ let maxSubstring = [];
7
+ for (let i = 0; i < s.length; i++) {
8
+ let substring = [s[i]];
9
+ for (j = i + 1; j < s.length; j++) {
10
+ if (!substring.includes(s[j])) {
11
+ substring.push(s[j]);
12
+ } else {
13
+ break;
14
+ }
15
16
+ if (substring.length > maxSubstring.length) {
17
+ maxSubstring = substring;
18
19
20
+ return maxSubstring.length;
21
+};
22
+
23
+console.log(lengthOfLongestSubstring("abcabcbb"));
0 commit comments