File tree Expand file tree Collapse file tree 4 files changed +59
-0
lines changed
172_factorial_trailing_zeros Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ all :
2+ gcc -O2 -o test majority.c
Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ #include <stdlib.h>
3+
4+ static int majorityElement (int * nums , int numsSize )
5+ {
6+ int i , count = 1 ;
7+ int major = nums [0 ];
8+ for (i = 1 ; i < numsSize ; i ++ ) {
9+ if (count == 0 ) {
10+ major = nums [i ];
11+ count ++ ;
12+ } else if (major == nums [i ]) {
13+ count ++ ;
14+ } else {
15+ count -- ;
16+ }
17+ }
18+
19+ return major ;
20+ }
21+
22+ int main (int argc , char * * argv )
23+ {
24+ if (argc < 2 ) {
25+ fprintf (stderr , "Usage: ./test target n1 n2...\n" );
26+ exit (-1 );
27+ }
28+
29+ int i , count = argc - 1 ;
30+ int * nums = malloc (count * sizeof (int ));
31+ for (i = 0 ; i < count ; i ++ ) {
32+ nums [i ] = atoi (argv [i + 1 ]);
33+ }
34+
35+ printf ("%d\n" , majorityElement (nums , count ));
36+ return 0 ;
37+ }
Original file line number Diff line number Diff line change 1+ all :
2+ gcc -O2 -o test zeroes.c
Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ #include <stdlib.h>
3+
4+ static int trailingZeroes (int n )
5+ {
6+ return n == 0 ? 0 : trailingZeroes (n / 5 );
7+ }
8+
9+ int main (int argc , char * * argv )
10+ {
11+ if (argc != 2 ) {
12+ fprintf (stderr , "Usage: ./test n\n" );
13+ exit (-1 );
14+ }
15+
16+ printf ("%d\n" , trailingZeroes (atoi (argv [1 ])));
17+ return 0 ;
18+ }
You can’t perform that action at this time.
0 commit comments