 All Problems
String to Integer (atoi)
medium
strings
amazon
microsoft
google
facebook

Implement myAtoi which converts a string to a 32-bit signed integer following these rules:

1. Skip leading whitespace.

2. Read optional + or -.

3. Read digits until non-digit or end.

4. Clamp result to [-2³¹, 2³¹-1].

Example 1:

Input:  42
Output: 42

Example 2:

Input:  -91283472332
Output: -2147483648

Input format: A single string.

Run to check your code against the sample cases, or submit to run every case