File tree Expand file tree Collapse file tree 1 file changed +18
-20
lines changed
solution/0000-0099/0003.Longest Substring Without Repeating Characters Expand file tree Collapse file tree 1 file changed +18
-20
lines changed Original file line number Diff line number Diff line change @@ -301,30 +301,28 @@ class Solution {
301
301
#### C
302
302
303
303
``` c
304
+ int lengthOfLongestSubstring (char* s) {
305
+ int freq[ 256] = {0};
306
+ int l = 0, r = 0;
307
+ int ans = 0;
308
+ int len = strlen(s);
309
+
310
+ for (r = 0; r < len; r++) {
311
+ char c = s[r];
312
+ freq[(unsigned char) c]++;
313
+
314
+ while (freq[(unsigned char) c] > 1) {
315
+ freq[(unsigned char) s[l]]--;
316
+ l++;
317
+ }
304
318
305
- int lengthOfLongestSubstring (char * s) {
306
- int freq[ 256] = {0};
307
- int l = 0, r = 0;
308
- int ans = 0;
309
- int len = strlen(s);
310
-
311
- for (r = 0; r < len; r++) {
312
- char c = s[ r] ;
313
- freq[ (unsigned char)c] ++;
314
-
315
- while (freq[(unsigned char)c] > 1) {
316
- freq[(unsigned char)s[l]]--;
317
- l++;
318
- }
319
-
320
- if (ans < r - l + 1) {
321
- ans = r - l + 1;
319
+ if (ans < r - l + 1) {
320
+ ans = r - l + 1;
321
+ }
322
322
}
323
- }
324
323
325
- return ans;
324
+ return ans;
326
325
}
327
-
328
326
```
329
327
330
328
<!-- tabs:end -->
You can’t perform that action at this time.
0 commit comments