File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
8.String to Integer (atoi)/shadowcoder
9.Palindrome Number/shadowcoder Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ int myAtoi (char * str ) {
2
+ int i = 0 , flag = 1 ;
3
+ while (str [i ] && str [i ] == ' ' ) i += 1 ;
4
+ if (!str [i ]) return 0 ;
5
+ if (str [i ] == '-' ) {flag = -1 ;i += 1 ;}
6
+ else if (str [i ] == '+' ) i += 1 ;
7
+
8
+ if (!isdigit (str [i ])) return 0 ;
9
+ long long num = 0 ;
10
+ sscanf (str + i , "%lld" , & num );
11
+ {
12
+ if (flag > 0 ) {
13
+ if (num > INT_MAX ) return INT_MAX ;
14
+ else return num ;
15
+ } else {
16
+ if (- num < INT_MIN ) return INT_MIN ;
17
+ else return - num ;
18
+ }
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ bool isy (int x ) {
2
+ int y = 0 ;
3
+ int origin = x ;
4
+ if (x < 0 ) return 0 ;
5
+ while (x != 0 ) {
6
+ y = y * 10 + x % 10 ;
7
+ x /= 10 ;
8
+ }
9
+
10
+ return y == origin ;
11
+ }
You can’t perform that action at this time.
0 commit comments