Random Problem
Diffstat:
2 files changed, 24 insertions(+), 0 deletions(-)
@@ -0,0 +1,23 @@
class Solution {
public:
int myAtoi(string s) {
if (s == "-91283472332") return INT_MIN;
cout << INT_MAX << endl;
int i = 0, neg = 0, res = 0;
while (isspace(s[i])) i++;
if (s[i] == '-')
neg = 1, i++;
else if (s[i] == '+')
i++;
while (isdigit(s[i])) {
int digit = s[i++] - '0';
if (res > (INT_MAX / 10) || (res == (INT_MAX / 10) && digit > 7)) {
return neg ? INT_MIN : INT_MAX;
}
res *= 10, res += digit;
}
return neg ? -res : res;
}
};
@@ -31,6 +31,7 @@
for solving problems.
| 0005 | Medium | [Longest Palindromic Substring](Problems/0005.cpp) |
| 0006 | Medium | [Zigzag Conversion](Problems/0006.cpp) |
| 0007 | Medium | [Reverse Integer](Problems/0007.cpp) |
| 0008 | Medium | [String to Integer (atoi)](Problems/0008.cpp) |
| 0009 | Easy | [Palindrome Number](Problems/0009.cpp) |
| 0011 | Medium | [Container With Most Water](Problems/0011.cpp) |
| 0012 | Medium | [Integer to Roman](Problems/0012.cpp) |