3
Time Complexity : O(logN), Since we are going through the entire number4
digit by digit, the time complexity should be O(log10N). The reason behind5
log10 is because we are dealing with integers which are base 10.7
Space Complexity : O(1), We are not using any data structure for interim8
operations, therefore, the space complexity is O(1).16
int myAtoi(string s) {23
bool positive = s[i] == '+';24
bool negative = s[i] == '-';25
positive == true ? i++ : i;26
negative == true ? i++ : i;27
while (i < len && s[i] >= '0' && s[i] <= '9') {28
num = num * 10 + (s[i] - '0');31
num = negative ? -num : num;33
num = (num > INT_MAX) ? INT_MAX : num;34
num = (num < INT_MIN) ? INT_MIN : num;