String to Integer (atoi)

Given a string s, convert it to a 32-bit signed integer following the rules of the C/C++ atoi function. This problem tests numeric parsing, sign handling, and overflow control.

Input Format

s = string

Output Format

parsed integer clamped to signed 32-bit range

Constraints

  • 0 <= s.length <= 200

Examples

Example 1:

Input:

s = "42"

Output:

42

Explanation:

Simple numeric parsing.

Example 2:

Input:

s = "   -42"

Output:

-42

Explanation:

Leading spaces and a sign are handled before digits.

Loading...
String to Integer (atoi) - Math DSA Problem