Implement myAtoi(s), which converts a string to a 32-bit signed integer: skip leading spaces, read an optional + or - sign, then read digits until a non-digit or the end of the string (no digits means 0). Clamp the value to the range [-2^31, 2^31 - 1] and return it.
Implement myAtoi(s), which converts a string to a 32-bit signed integer: skip leading spaces, read an optional + or - sign, then read digits until a non-digit or the end of the string (no digits means 0). Clamp the value to the range [-2^31, 2^31 - 1] and return it.
Example 1:
Input: {"s":"42"}
Output: 42
Constraints:
0≤s.length≤200
s consists of English letters (lower-case and upper-case), digits (0-9), ' ', '+', '-', and '.'.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"s":"42"}
Put the cursor i at index 0 of a 2-character string. The parse runs in stages: spaces, sign, digits.