File tree Expand file tree Collapse file tree 4 files changed +23
-29
lines changed
0026_remove_duplicates_from_sorted_array
0076_minimum_window_substring Expand file tree Collapse file tree 4 files changed +23
-29
lines changed Original file line number Diff line number Diff line change 11#include <stdio.h>
22#include <stdlib.h>
33
4+
45static int removeDuplicates (int * nums , int numsSize )
56{
6- if (numsSize <= 1 ) {
7- return numsSize ;
8- }
9-
10- int i , count = 1 ;
7+ int i , size = 0 ;
118 for (i = 1 ; i < numsSize ; i ++ ) {
12- if (nums [i - 1 ] != nums [i ]) {
13- nums [count ++ ] = nums [i ];
9+ if (nums [size ] != nums [i ]) {
10+ nums [++ size ] = nums [i ];
1411 }
1512 }
1613
17- return count ;
14+ return size + 1 ;
1815}
1916
2017int main (int argc , char * * argv )
Original file line number Diff line number Diff line change @@ -5,16 +5,13 @@ using namespace std;
55class Solution {
66public:
77 int removeDuplicates (vector<int >& nums) {
8- if (nums.size () == 0 ) {
9- return 0 ;
10- }
11-
12- int count = 1 ;
8+ int size = 0 ;
139 for (int i = 1 ; i < nums.size (); i++) {
14- if (nums[i - 1 ] != nums[i]) {
15- nums[count++ ] = nums[i];
10+ if (nums[size ] != nums[i]) {
11+ nums[++size ] = nums[i];
1612 }
1713 }
18- return count;
14+
15+ return size + 1 ;
1916 }
2017};
Original file line number Diff line number Diff line change 22#include <stdlib.h>
33#include <string.h>
44
5- static int dfs (int n , int * count )
5+ static int dfs (int n , int * steps )
66{
77 if (n == 1 ) {
88 return 1 ;
99 } else if (n == 2 ) {
1010 return 2 ;
11- } else if (count [n ] > 0 ) {
12- return count [n ];
11+ } else if (steps [n ] > 0 ) {
12+ return steps [n ];
1313 } else {
14- count [n ] += dfs (n - 1 , count );
15- count [n ] += dfs (n - 2 , count );
16- return count [n ];
14+ steps [n ] += dfs (n - 1 , steps );
15+ steps [n ] += dfs (n - 2 , steps );
16+ return steps [n ];
1717 }
1818}
1919
2020static int climbStairs (int n )
2121{
2222#if 1
2323 if (n < 1 ) return 0 ;
24- int * count = malloc ((n + 1 ) * sizeof (int ));
25- memset (count , 0 , (n + 1 ) * sizeof (int ));
26- return dfs (n , count );
24+ int * steps = malloc ((n + 1 ) * sizeof (int ));
25+ memset (steps , 0 , (n + 1 ) * sizeof (int ));
26+ return dfs (n , steps );
2727#else
2828 int i , a = 1 , b = 2 , c ;
2929 for (i = 3 ; i <= n ; i ++ ) {
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ static char *minWindow(char *s, char *t)
2222 int l = 0 , r = 0 ;
2323 int min_len = slen + 1 ;
2424 int start = 0 ;
25- int chars_to_meet = 0 ;
25+ int len = 0 ;
2626
2727 for (i = 0 ; i < tlen ; i ++ ) {
2828 count [t [i ]]++ ;
@@ -31,18 +31,18 @@ static char *minWindow(char *s, char *t)
3131 while (r < slen ) {
3232 if (-- count [s [r ++ ]] >= 0 ) {
3333 /* pattern found */
34- chars_to_meet ++ ;
34+ len ++ ;
3535 }
3636
37- while (chars_to_meet = = tlen ) {
37+ while (len > = tlen ) {
3838 if (r - l < min_len ) {
3939 min_len = r - l ;
4040 start = l ;
4141 }
4242
4343 /* Chars with negative count are not included in the pattern string */
4444 if (++ count [s [l ++ ]] > 0 ) {
45- chars_to_meet -- ;
45+ len -- ;
4646 }
4747 }
4848 }
You can’t perform that action at this time.
0 commit comments