String to Integer (atoi)
Examples
Example 1:
Input: s = "42"
Output: 42
Example 2:
Input: s = " -042"
Output: -42
Explanation:
Example 3:
Input: s = "1337c0d3"
Output: 1337
Example 1:
Input: s = "42"
Output: 42
Example 2:
Input: s = " -042"
Output: -42
Explanation:
Example 3:
Input: s = "1337c0d3"
Output: 1337
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer.
The algorithm for myAtoi(string s) is as follows:
" ").'-' or '+'; read the sign if present.0.[-2^31, 2^31 - 1].Skip leading spaces, read sign, then parse digits until a non-digit appears.
0 <= s.length <= 200s consists of English letters, digits (0-9), space (' '), and symbols ('+', '-', '.').