You are given a string s that represents a valid non-negative integer. Your task is to convert the string into its corresponding integer value. You are not allowed to use built-in conversion functions such as stoi(), parseInt(), or similar methods. Return the integer value.
Example 1
Input: s = "1234"
Output: 1234
Explanation: The string is converted to its integer value.
Example 2
Input: s = "0010"
Output: 10
Explanation: Leading zeros are ignored in the integer value.
Example 3
Input: s = "7"
Output: 7
Explanation: A single digit string converts directly to the same integer.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
123
123
4567
4567