class Solution {
public:
int reverse(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
char nums[11];
memset(nums, 11, 0);
bool negative = false;
if (x<0) {
negative = true;
x=-x;
}
sprintf(nums, "%d", x);
char* start = nums;
char* end = start+strlen(nums)-1;
while(start < end) {
char temp = *start;
*start = *end;
*end = temp;
start++;
end--;
}
if (negative) {
return -atoi(nums);
}
return atoi(nums);
}
};
public:
int reverse(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
char nums[11];
memset(nums, 11, 0);
bool negative = false;
if (x<0) {
negative = true;
x=-x;
}
sprintf(nums, "%d", x);
char* start = nums;
char* end = start+strlen(nums)-1;
while(start < end) {
char temp = *start;
*start = *end;
*end = temp;
start++;
end--;
}
if (negative) {
return -atoi(nums);
}
return atoi(nums);
}
};