Skip to content

Commit 0496362

Browse files
committed
2 parents c207437 + 63a213f commit 0496362

File tree

6 files changed

+116
-119
lines changed

6 files changed

+116
-119
lines changed

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -303,29 +303,28 @@ class Solution {
303303
#### C
304304

305305
```c
306-
int lengthOfLongestSubstring(char *s) {
307-
int freq[256] = {0};
308-
int l = 0, r = 0;
309-
int ans = 0;
310-
int len = strlen(s);
311-
312-
for (r = 0; r < len; r++) {
313-
char c = s[r];
314-
freq[(unsigned char)c]++;
315-
316-
while (freq[(unsigned char)c] > 1) {
317-
freq[(unsigned char)s[l]]--;
318-
l++;
319-
}
306+
int lengthOfLongestSubstring(char* s) {
307+
int freq[256] = {0};
308+
int l = 0, r = 0;
309+
int ans = 0;
310+
int len = strlen(s);
311+
312+
for (r = 0; r < len; r++) {
313+
char c = s[r];
314+
freq[(unsigned char) c]++;
315+
316+
while (freq[(unsigned char) c] > 1) {
317+
freq[(unsigned char) s[l]]--;
318+
l++;
319+
}
320320

321-
if (ans < r - l + 1) {
322-
ans = r - l + 1;
321+
if (ans < r - l + 1) {
322+
ans = r - l + 1;
323+
}
323324
}
324-
}
325325

326-
return ans;
326+
return ans;
327327
}
328-
329328
```
330329
331330
<!-- tabs:end -->

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -301,30 +301,28 @@ class Solution {
301301
#### C
302302

303303
```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+
}
304318

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+
}
322322
}
323-
}
324323

325-
return ans;
324+
return ans;
326325
}
327-
328326
```
329327
330328
<!-- tabs:end -->
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
int lengthOfLongestSubstring(char *s) {
2-
int freq[256] = {0};
3-
int l = 0, r = 0;
4-
int ans = 0;
5-
int len = strlen(s);
1+
int lengthOfLongestSubstring(char* s) {
2+
int freq[256] = {0};
3+
int l = 0, r = 0;
4+
int ans = 0;
5+
int len = strlen(s);
66

7-
for (r = 0; r < len; r++) {
8-
char c = s[r];
9-
freq[(unsigned char)c]++;
7+
for (r = 0; r < len; r++) {
8+
char c = s[r];
9+
freq[(unsigned char) c]++;
1010

11-
while (freq[(unsigned char)c] > 1) {
12-
freq[(unsigned char)s[l]]--;
13-
l++;
14-
}
11+
while (freq[(unsigned char) c] > 1) {
12+
freq[(unsigned char) s[l]]--;
13+
l++;
14+
}
1515

16-
if (ans < r - l + 1) {
17-
ans = r - l + 1;
16+
if (ans < r - l + 1) {
17+
ans = r - l + 1;
18+
}
1819
}
19-
}
2020

21-
return ans;
21+
return ans;
2222
}

solution/0000-0099/0004.Median of Two Sorted Arrays/README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -353,30 +353,30 @@ proc medianOfTwoSortedArrays(nums1: seq[int], nums2: seq[int]): float =
353353
#### C
354354

355355
```c
356-
int findKth(int *nums1, int m, int i, int *nums2, int n, int j, int k) {
357-
if (i >= m)
358-
return nums2[j + k - 1];
359-
if (j >= n)
360-
return nums1[i + k - 1];
361-
if (k == 1)
362-
return nums1[i] < nums2[j] ? nums1[i] : nums2[j];
363-
364-
int p = k / 2;
365-
366-
int x = (i + p - 1 < m) ? nums1[i + p - 1] : INT_MAX;
367-
int y = (j + p - 1 < n) ? nums2[j + p - 1] : INT_MAX;
368-
369-
if (x < y)
370-
return findKth(nums1, m, i + p, nums2, n, j, k - p);
371-
else
372-
return findKth(nums1, m, i, nums2, n, j + p, k - p);
356+
int findKth(int* nums1, int m, int i, int* nums2, int n, int j, int k) {
357+
if (i >= m)
358+
return nums2[j + k - 1];
359+
if (j >= n)
360+
return nums1[i + k - 1];
361+
if (k == 1)
362+
return nums1[i] < nums2[j] ? nums1[i] : nums2[j];
363+
364+
int p = k / 2;
365+
366+
int x = (i + p - 1 < m) ? nums1[i + p - 1] : INT_MAX;
367+
int y = (j + p - 1 < n) ? nums2[j + p - 1] : INT_MAX;
368+
369+
if (x < y)
370+
return findKth(nums1, m, i + p, nums2, n, j, k - p);
371+
else
372+
return findKth(nums1, m, i, nums2, n, j + p, k - p);
373373
}
374374

375-
double findMedianSortedArrays(int *nums1, int m, int *nums2, int n) {
376-
int total = m + n;
377-
int a = findKth(nums1, m, 0, nums2, n, 0, (total + 1) / 2);
378-
int b = findKth(nums1, m, 0, nums2, n, 0, (total + 2) / 2);
379-
return (a + b) / 2.0;
375+
double findMedianSortedArrays(int* nums1, int m, int* nums2, int n) {
376+
int total = m + n;
377+
int a = findKth(nums1, m, 0, nums2, n, 0, (total + 1) / 2);
378+
int b = findKth(nums1, m, 0, nums2, n, 0, (total + 2) / 2);
379+
return (a + b) / 2.0;
380380
}
381381
```
382382

solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -349,30 +349,30 @@ proc medianOfTwoSortedArrays(nums1: seq[int], nums2: seq[int]): float =
349349
#### C
350350

351351
```c
352-
int findKth(int *nums1, int m, int i, int *nums2, int n, int j, int k) {
353-
if (i >= m)
354-
return nums2[j + k - 1];
355-
if (j >= n)
356-
return nums1[i + k - 1];
357-
if (k == 1)
358-
return nums1[i] < nums2[j] ? nums1[i] : nums2[j];
359-
360-
int p = k / 2;
361-
362-
int x = (i + p - 1 < m) ? nums1[i + p - 1] : INT_MAX;
363-
int y = (j + p - 1 < n) ? nums2[j + p - 1] : INT_MAX;
364-
365-
if (x < y)
366-
return findKth(nums1, m, i + p, nums2, n, j, k - p);
367-
else
368-
return findKth(nums1, m, i, nums2, n, j + p, k - p);
352+
int findKth(int* nums1, int m, int i, int* nums2, int n, int j, int k) {
353+
if (i >= m)
354+
return nums2[j + k - 1];
355+
if (j >= n)
356+
return nums1[i + k - 1];
357+
if (k == 1)
358+
return nums1[i] < nums2[j] ? nums1[i] : nums2[j];
359+
360+
int p = k / 2;
361+
362+
int x = (i + p - 1 < m) ? nums1[i + p - 1] : INT_MAX;
363+
int y = (j + p - 1 < n) ? nums2[j + p - 1] : INT_MAX;
364+
365+
if (x < y)
366+
return findKth(nums1, m, i + p, nums2, n, j, k - p);
367+
else
368+
return findKth(nums1, m, i, nums2, n, j + p, k - p);
369369
}
370370

371-
double findMedianSortedArrays(int *nums1, int m, int *nums2, int n) {
372-
int total = m + n;
373-
int a = findKth(nums1, m, 0, nums2, n, 0, (total + 1) / 2);
374-
int b = findKth(nums1, m, 0, nums2, n, 0, (total + 2) / 2);
375-
return (a + b) / 2.0;
371+
double findMedianSortedArrays(int* nums1, int m, int* nums2, int n) {
372+
int total = m + n;
373+
int a = findKth(nums1, m, 0, nums2, n, 0, (total + 1) / 2);
374+
int b = findKth(nums1, m, 0, nums2, n, 0, (total + 2) / 2);
375+
return (a + b) / 2.0;
376376
}
377377
```
378378
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
int findKth(int *nums1, int m, int i, int *nums2, int n, int j, int k) {
2-
if (i >= m)
3-
return nums2[j + k - 1];
4-
if (j >= n)
5-
return nums1[i + k - 1];
6-
if (k == 1)
7-
return nums1[i] < nums2[j] ? nums1[i] : nums2[j];
1+
int findKth(int* nums1, int m, int i, int* nums2, int n, int j, int k) {
2+
if (i >= m)
3+
return nums2[j + k - 1];
4+
if (j >= n)
5+
return nums1[i + k - 1];
6+
if (k == 1)
7+
return nums1[i] < nums2[j] ? nums1[i] : nums2[j];
88

9-
int p = k / 2;
9+
int p = k / 2;
1010

11-
int x = (i + p - 1 < m) ? nums1[i + p - 1] : INT_MAX;
12-
int y = (j + p - 1 < n) ? nums2[j + p - 1] : INT_MAX;
11+
int x = (i + p - 1 < m) ? nums1[i + p - 1] : INT_MAX;
12+
int y = (j + p - 1 < n) ? nums2[j + p - 1] : INT_MAX;
1313

14-
if (x < y)
15-
return findKth(nums1, m, i + p, nums2, n, j, k - p);
16-
else
17-
return findKth(nums1, m, i, nums2, n, j + p, k - p);
14+
if (x < y)
15+
return findKth(nums1, m, i + p, nums2, n, j, k - p);
16+
else
17+
return findKth(nums1, m, i, nums2, n, j + p, k - p);
1818
}
1919

20-
double findMedianSortedArrays(int *nums1, int m, int *nums2, int n) {
21-
int total = m + n;
22-
int a = findKth(nums1, m, 0, nums2, n, 0, (total + 1) / 2);
23-
int b = findKth(nums1, m, 0, nums2, n, 0, (total + 2) / 2);
24-
return (a + b) / 2.0;
25-
}
20+
double findMedianSortedArrays(int* nums1, int m, int* nums2, int n) {
21+
int total = m + n;
22+
int a = findKth(nums1, m, 0, nums2, n, 0, (total + 1) / 2);
23+
int b = findKth(nums1, m, 0, nums2, n, 0, (total + 2) / 2);
24+
return (a + b) / 2.0;
25+
}

0 commit comments

Comments
 (0)