Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 8.String to Integer (atoi)/shadowcoder/StringtoInteger.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
int myAtoi(char* str) {
int i = 0, flag = 1;
while(str[i] && str[i] == ' ') i += 1;
if (!str[i]) return 0;
if (str[i] == '-') {flag = -1;i+=1;}
else if(str[i] == '+') i+= 1;

if (!isdigit(str[i])) return 0;
long long num = 0;
sscanf(str + i, "%lld", &num);
{
if (flag > 0) {
if (num > INT_MAX) return INT_MAX;
else return num;
} else {
if (-num < INT_MIN) return INT_MIN;
else return -num;
}
}
}
11 changes: 11 additions & 0 deletions 9.Palindrome Number/shadowcoder/PalindromeNum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bool isy(int x) {
int y = 0;
int origin = x;
if (x < 0) return 0;
while(x != 0) {
y = y * 10 + x % 10;
x /= 10;
}

return y == origin ;
}