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 2ab0ddf commit e6f4c1dCopy full SHA for e6f4c1d
longest-substring-without-repeating-characters/taewanseoul.ts
@@ -0,0 +1,31 @@
1
+/**
2
+ * 3. Longest Substring Without Repeating Characters
3
+ * Given a string s, find the length of the longest substring without repeating characters.
4
+ *
5
+ * https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
6
7
+ */
8
+
9
+// O(n^2) time
10
+// O(n) space
11
+function lengthOfLongestSubstring(s: string): number {
12
+ let result = 0;
13
14
+ for (let i = 0; i < s.length; i++) {
15
+ let set = new Set();
16
+ let substring = 0;
17
18
+ for (let j = i; j < s.length; j++) {
19
+ if (set.has(s[j])) {
20
+ break;
21
+ }
22
23
+ set.add(s[j]);
24
+ substring++;
25
26
27
+ result = Math.max(result, substring);
28
29
30
+ return result;
31
+}
0 commit comments