← All problems
String to Integer (atoi)
Implement atoi: parse a string to a 32-bit signed integer, skipping leading whitespace, handling an optional sign, stopping at the first non-digit, and clamping overflow to [-2^31, 2^31 - 1].
Complexity
Time O(n), Space O(1)
Common pitfalls
- Overflow after the fact
- Sign applied wrong
- Trailing chars mishandled
Your solution
Log in to save your code and track progress.