File tree 3 files changed +63
-0
lines changed
solution/0000-0099/0003.Longest Substring Without Repeating Characters
3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -202,6 +202,28 @@ func max(x, y int) int {
202
202
}
203
203
```
204
204
205
+ ### ** Nim**
206
+
207
+ ``` nim
208
+ proc lengthOfLongestSubstring(s: string): int =
209
+ var
210
+ i = 0
211
+ j = 0
212
+ res = 0
213
+ literals: set[char] = {}
214
+
215
+ while i < s.len:
216
+ while s[i] in literals:
217
+ if s[j] in literals:
218
+ excl(literals, s[j])
219
+ j += 1
220
+ literals.incl(s[i]) # Uniform Function Call Syntax f(x) = x.f
221
+ res = max(res, i - j + 1)
222
+ i += 1
223
+
224
+ result = res # result has the default return value
225
+ ```
226
+
205
227
### ** ...**
206
228
207
229
```
Original file line number Diff line number Diff line change @@ -184,6 +184,28 @@ func max(x, y int) int {
184
184
}
185
185
```
186
186
187
+ ### ** Nim**
188
+
189
+ ``` nim
190
+ proc lengthOfLongestSubstring(s: string): int =
191
+ var
192
+ i = 0
193
+ j = 0
194
+ res = 0
195
+ literals: set[char] = {}
196
+
197
+ while i < s.len:
198
+ while s[i] in literals:
199
+ if s[j] in literals:
200
+ excl(literals, s[j])
201
+ j += 1
202
+ literals.incl(s[i]) # Uniform Function Call Syntax f(x) = x.f
203
+ res = max(res, i - j + 1)
204
+ i += 1
205
+
206
+ result = res # result has the default return value
207
+ ```
208
+
187
209
### ** ...**
188
210
189
211
```
Original file line number Diff line number Diff line change
1
+ proc lengthOfLongestSubstring (s: string ): int =
2
+ var
3
+ i = 0
4
+ j = 0
5
+ res = 0
6
+ literals: set [char ] = {}
7
+
8
+ while i < s.len:
9
+ while s[i] in literals:
10
+ if s[j] in literals:
11
+ excl (literals, s[j])
12
+ j += 1
13
+ literals.incl (s[i]) # Uniform Function Call Syntax f(x) = x.f
14
+ res = max (res, i - j + 1 )
15
+ i += 1
16
+
17
+ result = res # result has the default return value
18
+
19
+ echo lengthOfLongestSubstring (" abcddabcf" )
You can’t perform that action at this time.
0 commit comments