FunctionRacerProblemsRace

String to Integer

MediumStringsPython, JavaScript, TypeScript, Java, C++

Turn s into an integer like this:

Return the integer.

Example 1

s " -42abc"
returns -42

Spaces skipped, sign -, digits 42: result -42.

Example 2

s "words 987"
returns 0

Starts with a letter, so no digits are read: 0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems