File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
solution/0000-0099/0003.Longest Substring Without Repeating Characters Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,26 @@ class Solution {
106
106
}
107
107
```
108
108
109
+ ### ** TypeScript**
110
+
111
+ ``` ts
112
+ function lengthOfLongestSubstring(s : string ): number {
113
+ // 滑动窗口+哈希表
114
+ let left = - 1 ;
115
+ let maxLen = 0 ;
116
+ let hashTable = new Map ();
117
+ for (let right = 0 ; right < s .length ; right ++ ) {
118
+ let cur = s .charAt (right );
119
+ if (hashTable .has (cur )) {
120
+ left = Math .max (left , hashTable .get (cur ));
121
+ }
122
+ hashTable .set (cur , right );
123
+ maxLen = Math .max (maxLen , right - left );
124
+ }
125
+ return maxLen ;
126
+ };
127
+ ```
128
+
109
129
### ** Swift**
110
130
111
131
``` swift
Original file line number Diff line number Diff line change @@ -88,6 +88,26 @@ class Solution {
88
88
}
89
89
```
90
90
91
+ ### ** TypeScript**
92
+
93
+ ``` ts
94
+ function lengthOfLongestSubstring(s : string ): number {
95
+ // 滑动窗口+哈希表
96
+ let left = - 1 ;
97
+ let maxLen = 0 ;
98
+ let hashTable = new Map ();
99
+ for (let right = 0 ; right < s .length ; right ++ ) {
100
+ let cur = s .charAt (right );
101
+ if (hashTable .has (cur )) {
102
+ left = Math .max (left , hashTable .get (cur ));
103
+ }
104
+ hashTable .set (cur , right );
105
+ maxLen = Math .max (maxLen , right - left );
106
+ }
107
+ return maxLen ;
108
+ };
109
+ ```
110
+
91
111
### ** Swift**
92
112
93
113
``` swift
Original file line number Diff line number Diff line change
1
+ function lengthOfLongestSubstring ( s : string ) : number {
2
+ // 滑动窗口+哈希表
3
+ let left = - 1 ;
4
+ let maxLen = 0 ;
5
+ let hashTable = new Map ( ) ;
6
+ for ( let right = 0 ; right < s . length ; right ++ ) {
7
+ let cur = s . charAt ( right ) ;
8
+ if ( hashTable . has ( cur ) ) {
9
+ left = Math . max ( left , hashTable . get ( cur ) ) ;
10
+ }
11
+ hashTable . set ( cur , right ) ;
12
+ maxLen = Math . max ( maxLen , right - left ) ;
13
+ }
14
+ return maxLen ;
15
+ } ;
You can’t perform that action at this time.
0 commit comments