Strings

Implement atoi()

medium
Implement the `myAtoi(string s)` function, which converts a string to a 32-bit signed integer. Rules (simplified LeetCode): 1. Read and ignore leading whitespace. 2. Check for optional `+` or `-`. 3. Read digits until a non-digit; ignore the rest. 4. Convert digits; clamp into 32-bit signed range `[-2³¹, 2³¹ - 1]`. 5. If no digits, return 0. Example: `myAtoi(" -42")` → `-42`.
Hint steps(0/3 revealed)
  1. 1

    Complete previous step or reveal to unlock this hint.

  2. 2

    Complete previous step or reveal to unlock this hint.

  3. 3

    Complete previous step or reveal to unlock this hint.