Skip to main content
String to Integer (atoi) | AlgoCracked
AlgoCracked
ProblemsString to Integer (atoi)
Medium17.0% acceptance
String

String to Integer (atoi)

Implement myAtoi , which converts a string to a 32-bit signed integer. Process the string in order: skip any leading spaces, read an optional + or - sign, then read consecutive digits and stop at the first non-digit. Ignore everything after the number. If no digits are read, the result is 0 . Finally clamp the value to the range [-2147483648, 2147483647] . Input format Input is [s] , e.g. [ -042 ] .

Loading workspace…