Medium · Math
Convert String to Integer
Given a string s, return the 32-bit signed integer it begins with: skip leading spaces, read at most one '+' or '-', read digits up to the first non-digit, and clamp the value to [−2³¹, 2³¹ − 1]; return 0 if no digit is read.
Examples
Example 1
{
"s": " -042"
}Output: -42
Example 2
{
"s": "91283472332"
}Output: 2147483647
Rebuild it in the studio
Core interview problems are free with a full runner and lessons; Pro opens the complete library.