File tree Expand file tree Collapse file tree 7 files changed +255
-0
lines changed
0010.Regular Expression Matching
0011.Container With Most Water Expand file tree Collapse file tree 7 files changed +255
-0
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,44 @@ public class Solution {
331
331
}
332
332
```
333
333
334
+ #### C
335
+
336
+ ``` c
337
+ #define MAX_LEN 1000
338
+
339
+ char *ss, *pp;
340
+ int m, n;
341
+ int f[MAX_LEN + 1 ][MAX_LEN + 1 ];
342
+
343
+ bool dfs (int i, int j) {
344
+ if (j >= n) {
345
+ return i == m;
346
+ }
347
+ if (f[ i] [ j ] != 0) {
348
+ return f[ i] [ j ] == 1;
349
+ }
350
+ int res = -1;
351
+ if (j + 1 < n && pp[ j + 1] == '* ') {
352
+ if (dfs(i, j + 2) || (i < m && (ss[ i] == pp[ j] || pp[ j] == '.') && dfs(i + 1, j))) {
353
+ res = 1;
354
+ }
355
+ } else if (i < m && (ss[ i] == pp[ j] || pp[ j] == '.') && dfs(i + 1, j + 1)) {
356
+ res = 1;
357
+ }
358
+ f[ i] [ j ] = res;
359
+ return res == 1;
360
+ }
361
+
362
+ bool isMatch(char* s, char* p) {
363
+ ss = s;
364
+ pp = p;
365
+ m = strlen(s);
366
+ n = strlen(p);
367
+ memset(f, 0, sizeof(f));
368
+ return dfs(0, 0);
369
+ }
370
+ ```
371
+
334
372
<!-- tabs:end -->
335
373
336
374
<!-- solution:end -->
@@ -579,6 +617,31 @@ class Solution {
579
617
}
580
618
```
581
619
620
+ #### C
621
+
622
+ ``` c
623
+ bool isMatch (char* s, char* p) {
624
+ int m = strlen(s), n = strlen(p);
625
+ bool f[ m + 1] [ n + 1 ] ;
626
+ memset(f, 0, sizeof(f));
627
+ f[ 0] [ 0 ] = true;
628
+
629
+ for (int i = 0; i <= m; ++i) {
630
+ for (int j = 1; j <= n; ++j) {
631
+ if (p[j - 1] == '*') {
632
+ f[i][j] = f[i][j - 2];
633
+ if (i > 0 && (p[j - 2] == '.' || p[j - 2] == s[i - 1])) {
634
+ f[i][j] = f[i][j] || f[i - 1][j];
635
+ }
636
+ } else if (i > 0 && (p[j - 1] == '.' || p[j - 1] == s[i - 1])) {
637
+ f[i][j] = f[i - 1][j - 1];
638
+ }
639
+ }
640
+ }
641
+ return f[m][n];
642
+ }
643
+ ```
644
+
582
645
<!-- tabs:end -->
583
646
584
647
<!-- solution:end -->
Original file line number Diff line number Diff line change @@ -330,6 +330,44 @@ public class Solution {
330
330
}
331
331
```
332
332
333
+ #### C
334
+
335
+ ``` c
336
+ #define MAX_LEN 1000
337
+
338
+ char *ss, *pp;
339
+ int m, n;
340
+ int f[MAX_LEN + 1 ][MAX_LEN + 1 ];
341
+
342
+ bool dfs (int i, int j) {
343
+ if (j >= n) {
344
+ return i == m;
345
+ }
346
+ if (f[ i] [ j ] != 0) {
347
+ return f[ i] [ j ] == 1;
348
+ }
349
+ int res = -1;
350
+ if (j + 1 < n && pp[ j + 1] == '* ') {
351
+ if (dfs(i, j + 2) || (i < m && (ss[ i] == pp[ j] || pp[ j] == '.') && dfs(i + 1, j))) {
352
+ res = 1;
353
+ }
354
+ } else if (i < m && (ss[ i] == pp[ j] || pp[ j] == '.') && dfs(i + 1, j + 1)) {
355
+ res = 1;
356
+ }
357
+ f[ i] [ j ] = res;
358
+ return res == 1;
359
+ }
360
+
361
+ bool isMatch(char* s, char* p) {
362
+ ss = s;
363
+ pp = p;
364
+ m = strlen(s);
365
+ n = strlen(p);
366
+ memset(f, 0, sizeof(f));
367
+ return dfs(0, 0);
368
+ }
369
+ ```
370
+
333
371
<!-- tabs:end -->
334
372
335
373
<!-- solution:end -->
@@ -578,6 +616,31 @@ class Solution {
578
616
}
579
617
```
580
618
619
+ #### C
620
+
621
+ ``` c
622
+ bool isMatch (char* s, char* p) {
623
+ int m = strlen(s), n = strlen(p);
624
+ bool f[ m + 1] [ n + 1 ] ;
625
+ memset(f, 0, sizeof(f));
626
+ f[ 0] [ 0 ] = true;
627
+
628
+ for (int i = 0; i <= m; ++i) {
629
+ for (int j = 1; j <= n; ++j) {
630
+ if (p[j - 1] == '*') {
631
+ f[i][j] = f[i][j - 2];
632
+ if (i > 0 && (p[j - 2] == '.' || p[j - 2] == s[i - 1])) {
633
+ f[i][j] = f[i][j] || f[i - 1][j];
634
+ }
635
+ } else if (i > 0 && (p[j - 1] == '.' || p[j - 1] == s[i - 1])) {
636
+ f[i][j] = f[i - 1][j - 1];
637
+ }
638
+ }
639
+ }
640
+ return f[m][n];
641
+ }
642
+ ```
643
+
581
644
<!-- tabs:end -->
582
645
583
646
<!-- solution:end -->
Original file line number Diff line number Diff line change
1
+ #define MAX_LEN 1000
2
+
3
+ char * ss , * pp ;
4
+ int m , n ;
5
+ int f [MAX_LEN + 1 ][MAX_LEN + 1 ];
6
+
7
+ bool dfs (int i , int j ) {
8
+ if (j >= n ) {
9
+ return i == m ;
10
+ }
11
+ if (f [i ][j ] != 0 ) {
12
+ return f [i ][j ] == 1 ;
13
+ }
14
+ int res = -1 ;
15
+ if (j + 1 < n && pp [j + 1 ] == '*' ) {
16
+ if (dfs (i , j + 2 ) || (i < m && (ss [i ] == pp [j ] || pp [j ] == '.' ) && dfs (i + 1 , j ))) {
17
+ res = 1 ;
18
+ }
19
+ } else if (i < m && (ss [i ] == pp [j ] || pp [j ] == '.' ) && dfs (i + 1 , j + 1 )) {
20
+ res = 1 ;
21
+ }
22
+ f [i ][j ] = res ;
23
+ return res == 1 ;
24
+ }
25
+
26
+ bool isMatch (char * s , char * p ) {
27
+ ss = s ;
28
+ pp = p ;
29
+ m = strlen (s );
30
+ n = strlen (p );
31
+ memset (f , 0 , sizeof (f ));
32
+ return dfs (0 , 0 );
33
+ }
Original file line number Diff line number Diff line change
1
+ bool isMatch (char * s , char * p ) {
2
+ int m = strlen (s ), n = strlen (p );
3
+ bool f [m + 1 ][n + 1 ];
4
+ memset (f , 0 , sizeof (f ));
5
+ f [0 ][0 ] = true;
6
+
7
+ for (int i = 0 ; i <= m ; ++ i ) {
8
+ for (int j = 1 ; j <= n ; ++ j ) {
9
+ if (p [j - 1 ] == '*' ) {
10
+ f [i ][j ] = f [i ][j - 2 ];
11
+ if (i > 0 && (p [j - 2 ] == '.' || p [j - 2 ] == s [i - 1 ])) {
12
+ f [i ][j ] = f [i ][j ] || f [i - 1 ][j ];
13
+ }
14
+ } else if (i > 0 && (p [j - 1 ] == '.' || p [j - 1 ] == s [i - 1 ])) {
15
+ f [i ][j ] = f [i - 1 ][j - 1 ];
16
+ }
17
+ }
18
+ }
19
+ return f [m ][n ];
20
+ }
Original file line number Diff line number Diff line change @@ -262,6 +262,33 @@ class Solution {
262
262
}
263
263
```
264
264
265
+ #### C
266
+
267
+ ``` c
268
+ int min (int a, int b) {
269
+ return a < b ? a : b;
270
+ }
271
+
272
+ int max(int a, int b) {
273
+ return a > b ? a : b;
274
+ }
275
+
276
+ int maxArea(int* height, int heightSize) {
277
+ int l = 0, r = heightSize - 1;
278
+ int ans = 0;
279
+ while (l < r) {
280
+ int t = min(height[ l] , height[ r] ) * (r - l);
281
+ ans = max(ans, t);
282
+ if (height[ l] < height[ r] ) {
283
+ ++l;
284
+ } else {
285
+ --r;
286
+ }
287
+ }
288
+ return ans;
289
+ }
290
+ ```
291
+
265
292
<!-- tabs:end -->
266
293
267
294
<!-- solution:end -->
Original file line number Diff line number Diff line change @@ -259,6 +259,33 @@ class Solution {
259
259
}
260
260
```
261
261
262
+ #### C
263
+
264
+ ``` c
265
+ int min (int a, int b) {
266
+ return a < b ? a : b;
267
+ }
268
+
269
+ int max(int a, int b) {
270
+ return a > b ? a : b;
271
+ }
272
+
273
+ int maxArea(int* height, int heightSize) {
274
+ int l = 0, r = heightSize - 1;
275
+ int ans = 0;
276
+ while (l < r) {
277
+ int t = min(height[ l] , height[ r] ) * (r - l);
278
+ ans = max(ans, t);
279
+ if (height[ l] < height[ r] ) {
280
+ ++l;
281
+ } else {
282
+ --r;
283
+ }
284
+ }
285
+ return ans;
286
+ }
287
+ ```
288
+
262
289
<!-- tabs:end -->
263
290
264
291
<!-- solution:end -->
Original file line number Diff line number Diff line change
1
+ int min (int a , int b ) {
2
+ return a < b ? a : b ;
3
+ }
4
+
5
+ int max (int a , int b ) {
6
+ return a > b ? a : b ;
7
+ }
8
+
9
+ int maxArea (int * height , int heightSize ) {
10
+ int l = 0 , r = heightSize - 1 ;
11
+ int ans = 0 ;
12
+ while (l < r ) {
13
+ int t = min (height [l ], height [r ]) * (r - l );
14
+ ans = max (ans , t );
15
+ if (height [l ] < height [r ]) {
16
+ ++ l ;
17
+ } else {
18
+ -- r ;
19
+ }
20
+ }
21
+ return ans ;
22
+ }
You can’t perform that action at this time.
0 commit comments