🌐
LeetCode
leetcode.com › problems › string-to-integer-atoi
8. String to Integer (atoi)
Return the integer as the final result. Note:​​​​​​​ You must not use any built-in library function that converts a string to a number (for example, atoi, stoi, Integer.parseInt, int(), parseInt, Number()).
Explore
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
The World's Leading Online Programming Learning Platform
Boost your coding interview skills and confidence by practicing real interview questions with LeetCode. Our platform offers a range of essential problems for practice, as well as the latest questions being asked by top-tier companies.
Top Interview 150
Must-do List for Interview Prep
Premium
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › write-your-own-atoi
String to Integer - Write your own atoi() - GeeksforGeeks
Traverse the string from left to right, skipping whitespaces, handling the optional sign, and building the number digit by digit. At each step, ensure the value stays within 32-bit integer limits to avoid overflow.
Published: April 14, 2026
🌐
WalkCCC
walkccc.me › LeetCode › problems › 8
8. String to Integer (atoi) - LeetCode Solutions
LeetCode Solutions in C++23, Java, Python, MySQL, and TypeScript.
🌐
GitHub
github.com › doocs › leetcode › blob › main › solution › 0000-0099 › 0008.String to Integer (atoi) › README_EN.md
leetcode/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md at main · doocs/leetcode · GitHub
Conversion: Read the integer by skipping leading zeros until a non-digit character is encountered or the end of the string is reached. If no digits were read, then the result is 0. Rounding: If the integer is out of the 32-bit signed integer ...
Author: doocs
🌐
AlgoMonster
algo.monster › home › 8. string to integer (atoi)
8. String to Integer (atoi) - In-Depth Explanation
By comparing against (2**31 - 1) // 10 and checking the last digit separately when equal, we avoid actual integer overflow in our calculation. This ensures the algorithm works correctly even in languages with fixed integer sizes. The time complexity is O(n) where n is the length of the string, ...
🌐
YouTube
youtube.com › watch
String to Integer atoi 🔥| Leetcode 8 | String - YouTube
Timestamps:Problem explanation: 00:00Approaching the problem: 04:14Dry Run: 06:53Code Explanation: 13:15Complexity Analysis: 16:38Time Complexity : O(n)Space...
Published: January 14, 2022
🌐
GitHub
github.com › ACEMerlin › leetcode-ruby › blob › master › 8.string-to-integer-atoi.rb
leetcode-ruby/8.string-to-integer-atoi.rb at master · ACEMerlin/leetcode-ruby · GitHub
# [8] String to Integer (atoi) # # https://leetcode.com/problems/string-to-integer-atoi/description/ # # Implement atoi which converts a string to an integer. # # The function first discards as many whitespace characters as · # necessary until ...
Author: ACEMerlin
🌐
YouTube
youtube.com › watch
STRING TO INTEGER (ATOI) | PYTHON | LEETCODE # 8 - YouTube
In this video we are solving a popular interview question at top tech companies Google, Facebook, Microsoft, and others. This is a pretty simple question but...
Published: March 2, 2022
🌐
Gitbooks
frankchen0521.gitbooks.io › leetcode-swift › content › 8string-to-integer-atoi.html
8.String to Integer (atoi) · LeetCode - Swift - Frank Chen
If no valid conversion could be performed, a zero value is returned. If the correct value is out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is returned. ... class Solution { func myAtoi(_ str: String) -> Int { let sign:[Character] = ["+", "-"]; let ...
Find elsewhere
🌐
GitHub
github.com › chenjienan › python-leetcode › blob › master › 8.string-to-integer-atoi.py
python-leetcode/8.string-to-integer-atoi.py at master · chenjienan/python-leetcode · GitHub
# [8] String to Integer (atoi) # class Solution(object): def myAtoi(self, str): """ :type str: str · :rtype: int · """ # if not s: return 0 · ls = list(s.strip()) if not ls: return 0 · sign = 1 ·
Author: chenjienan
🌐
codingcircle
codingcircle.in › 8-string-to-integer-atoi
codingcircle » 8. String to Integer (atoi)
February 22, 2025 - Read the subsequent characters until a non-digit is encountered or the end of the string is reached. These characters represent the numeric part of the string. Convert the sequence of digits into an integer.
🌐
DEV Community
dev.to › aaradhyanegi009 › leetcode-solution-8-string-to-integer-atoi-2jli
LeetCode Solution: 8. String to Integer (atoi) - DEV Community
May 18, 2026 - Since we handled all overflows during step 3, this final cast will safely return the correct, clamped 32-bit integer. ... Combining all these steps gives us a complete and robust atoi function! #include <string> // For std::string #include <climits> // For INT_MAX, INT_MIN #include <cctype> // For isdigit (good practice to include explicitly) class Solution { public: int myAtoi(std::string s) { int i = 0; // Step 1: Skip leading whitespace while (i < s.length() && s[i] == ' ') { i++; } // Step 2: Determine sign int sign = 1; // Assume positive initially if (i < s.length() && (s[i] == '-' || s[i] == '+')) { sign = (s[i] == '-') ?
🌐
Red Quark
redquark.org › leetcode › 0008-string-to-integer-atoi
LeetCode #8 - String To Integer (atoi) | Red Quark
We are not using any data structure ... if (str == null || str.length() < 1) { return 0; } // MAX and MIN values for integers final int INT_MAX = 2147483647; final int INT_MIN = -2147483648; // Trimmed string str = s...
🌐
YouTube
youtube.com › watch
String To Integer (atoi) - 8. LeetCode - Java - YouTube
String To Integer (atoi) - 8. LeetCode - Java Github repo: https://github.com/teddysmithdev/LeetCodeJava2024LeetCode description: https://leetcode.com/proble...
Published: August 20, 2024
🌐
Gitbook
zhenchaogan.gitbook.io › leetcode-solution › leetcode-8-string-to-integer-atoi
LeetCode 8. String to Integer (atoi) | leetcode solution
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).
🌐
XpandNotes
blueskyson.github.io › 2021 › 07 › 25 › leetcode-8
Leetcode #8 String to Integer (atoi) - XpandNotes
July 25, 2021 - Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++’s atoi function).
🌐
LeetCode
leetcode.ca › all › 8.html
8. String to Integer (atoi) - leetcode.ca
The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.
🌐
Paul Coroneos
pcoroneos.com › blog › atoi
Solving Leetcode 8 - String to Integer (atoi) (JavaScript) - Paul Coroneos
July 29, 2020 - The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.
🌐
YouTube
youtube.com › watch
LeetCode Tutorial 8. String to Integer (atoi) - YouTube
GoodTecher LeetCode Tutorial 8. String to Integer (atoi) (Java). http://www.goodtecher.com/leetcode-8-string-integer-atoi-java/LeetCode Tutorial by GoodTeche...
Published: February 24, 2017