Implement a function that converts a string to a 32-bit signed integer, similar to C's atoi function.
The algorithm is as follows:
'+' or '-', read it and determine the sign. Assume positive if neither is present.'0' through '9'). Stop at the first non-digit character or end of string.[-2^31, 2^31 - 1], clamp it to the nearest boundary.If no digits are read, return 0.
s = "42"42s = " -42"-42s = "4193 with words"41930 <= s.length <= 200s consists of English letters, digits, spaces, and the characters '+' and '-'.Result must be clamped to [-2^31, 2^31 - 1].Run your code to see results
Use Cmd+Enter to run