Skip to content

Commit be15493

Browse files
authored
feat: add nim-lang solution to lc problem: No.0003.Longest Substring (doocs#574)
1 parent d990cb6 commit be15493

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,28 @@ func max(x, y int) int {
202202
}
203203
```
204204

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+
205227
### **...**
206228

207229
```

solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ func max(x, y int) int {
184184
}
185185
```
186186

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+
187209
### **...**
188210

189211
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy