Parse a Number

Parsers often need to turn user input into a number, even when the text has spaces or extra characters after the number. Write a function my_atoi that behaves like atoi: skip leading spaces, read an optional sign, then read digits until the first non-digit character. Return the parsed integer. If it goes outside the 32-bit signed integer range [-2**31, 2**31 - 1], clamp it to the nearest boundary.

Примеры

Ввод
"42"
Вывод
42
Ввод
" -42"
Вывод
-42
Ввод
"4193 with words"
Вывод
4193

Нужно реализовать

def my_atoi(s: str) -> int:

Теги

stringsmath
PostgreSQLv16

Šeit parādīsies koda izpildes rezultāts

Visible tests
1
Input
"42"
Expected42
2
Input
" -42"
Expected-42
3
Input
"4193 with words"
Expected4193
4
Input
"words and 987"
Expected0
5
Input
"-91283472332"
Expected-2147483648
6
Input
"+1"
Expected1
Focus radio
Paused · SomaFM · Fluid