← 返回 bloomberg 的题目列表Implement atoi (string to integer conversion)
类型:online_judge
Problem
Implement a function to convert a numeric string into an integer.
Input: a string s consisting only of digits 0-9
Output: the corresponding base-10 integer
For this problem, ignore signs, whitespace, and overflow (the input is guaranteed to be a valid non-negative integer string).
Constraints
1 <= len(s) <= 1e5
Examples
Input: "123" Output: 123
Input: "0" Output: 0
Requirements
Time complexity: O(n)
Do not call built-in string-to-integer conversion (e.g., int(s)).
Example
Input
123
Output
123