Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer. The algorithm reads in and ignores any leading whitespace, then reads an optional '+' or '-' sign, then reads in the digits until a non-digit character or the end. If no digits were read, the result is 0. The value is clamped to the 32-bit signed integer range [-2^31, 2^31 - 1].
Example 1
Input: s = -42
Output: -42
Explanation: The leading spaces are skipped, the '-' sets the sign, and the digits 42 are read, giving -42.
Example 2
Input: s = 42
Output: 42
Explanation: The string is just the digits 42, with no sign or spaces.
Example 3
Input: s = 4193 with words
Output: 4193
Explanation: Reading stops at the first non-digit, the space after 4193, so the rest of the text is ignored.
Process the string in four phases: skip spaces, read an optional sign, accumulate digits, and clamp to the 32-bit range.
Run checks all cases above. Submit evaluates all test cases.