🌐
AlgoMonster
algo.monster › home › 8. string to integer (atoi)
8. String to Integer (atoi) - In-Depth Explanation
Handle overflow: The result must be within the range of a 32-bit signed integer [-2^31, 2^31 - 1], which is [-2147483648, 2147483647]. If the number would overflow: ... The solution needs to carefully handle edge cases like empty strings, strings with only spaces, and integer overflow situations ...
🌐
LeetCode
leetcode.com › problems › string-to-integer-atoi
8. String to Integer (atoi)
8. String to Integer (atoi) Medium · 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: Whitespace: Ignore any leading whitespace (" "). Signedness: ...
🌐
Medium
medium.com › @soham-khade › 8-string-to-integer-atoi-leetcode-problem-java-042a26831f49
8. String to Integer (atoi) LeetCode Problem (Java) | by Soham | Medium
October 27, 2023 - Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored. Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32).
🌐
WalkCCC
walkccc.me › LeetCode › problems › 8
8. String to Integer (atoi) - LeetCode Solutions
LeetCode Solutions in C++23, Java, Python, MySQL, and TypeScript.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › write-your-own-atoi
String to Integer - Write your own atoi() - GeeksforGeeks
Write your own atoi() that takes a string (which represents a floating point value) as an argument and returns its value as double.
Published: April 14, 2026
🌐
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
🌐
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
🌐
PROGIEZ
progiez.com › 8-string-to-integer-atoi-leetcode-solution
8. String To Integer (atoi) LeetCode Solution - Progiez
September 12, 2024 - class Solution { public int myAtoi(String s) { s = s.strip(); if (s.isEmpty()) return 0; final int sign = s.charAt(0) == '-' ? -1 : 1; if (s.charAt(0) == '+' || s.charAt(0) == '-') s = s.substring(1); long num = 0; for (final char c : s.toCharArray()) { if (!Character.isDigit(c)) break; num = num * 10 + (c - '0'); if (sign * num <= Integer.MIN_VALUE) return Integer.MIN_VALUE; if (sign * num >= Integer.MAX_VALUE) return Integer.MAX_VALUE; } return sign * (int) num; } } // code provided by PROGIEZ
🌐
Hezhigang
hezhigang.github.io › 2022 › 01 › 22 › leetcode-algorithms-string-to-integer-atoi
LeetCode - Algorithms - 8. String to Integer (atoi) | Gain time, gain life.
February 28, 2025 - Problem8. String to Integer (atoi) Java1234567891011121314151617181920212223242526272829303132333435363738394041class Solution { public int myAtoi(String s) { int re = 0; lo
Find elsewhere
🌐
Blogger
massivealgorithms.blogspot.com › 2015 › 06 › leetcode-string-to-integer-atoi-java.html
Massive Algorithms: LeetCode 8 - String to Integer (atoi)
public int myAtoi(String str) { if (str.isEmpty()) return 0; int sign = 1, base = 0, i = 0, n = str.length(); while (i < n && str.charAt(i) == ' ') ++i; if (i < n && (str.charAt(i) == '+' || str.charAt(i) == '-')) { sign = (str.charAt(i++) == '+') ? 1 : -1; } while (i < n && str.charAt(i) >= '0' && str.charAt(i) <= '9') { if (base > Integer.MAX_VALUE / 10 || (base == Integer.MAX_VALUE / 10 && str.charAt(i) - '0' > 7)) { return (sign == 1) ? Integer.MAX_VALUE : Integer.MIN_VALUE; } base = 10 * base + (str.charAt(i++) - '0'); } return base * sign; } http://www.jiuzhang.com/solutions/string-to-in
🌐
Medium
medium.com › @rutujakbhombe19 › solving-leetcode-until-i-land-a-job-306a30914738
Leetcode 8 : String to Integer (atoi) | by Rutuja Bhombe | Medium
July 17, 2024 - Read each character until a non-digit character is encountered or the end of the string is reached. Convert these characters into a number. ... If the number is outside the range of a 32-bit signed integer, clamp it to the range limits.
🌐
Blogger
codesniper.blogspot.com › 2015 › 01 › string-to-integer-atoi-leetcode.html
The Code Sniper: 8. String to Integer (atoi) Leetcode Java
Integer.MAX_VALUE : Integer.MIN_VALUE; is necessary and enough to test all the overflow, 2137385647, -2147483647, 2137385648(return 2137385647) and -2147483648 will all return the right answers. public int atoi(String str) { if(str==null || str.length()==0) return 0; int start=0; int res=0; boolean pos=true; while(start<str.length() && str.charAt(start)==' ') start++; if(start==str.length()) return 0; if(str.charAt(start)=='+'||str.charAt(start)=='-') { pos=str.charAt(start++)=='+'; } for(int i=start;i<str.length() && str.charAt(i)<='9'&&str.charAt(i)>='0';i++){ int dig=str.charAt(i)-'0'; if((Integer.MAX_VALUE-dig)/10<res) return (pos)?
🌐
Red Quark
redquark.org › leetcode › 0008-string-to-integer-atoi
LeetCode #8 - String To Integer (atoi) | Red Quark
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.
🌐
GitHub
github.com › awangdev › leet-code › blob › master › Java › 8. String to Integer (atoi).java
leet-code/Java/8. String to Integer (atoi).java at master · awangdev/leet-code · GitHub
* @param str: A string · * @return An integer · */ · public int atoi(String str) { · if (str == null || str.length() == 0) { · return 0; · } · str = str.replaceAll("\\s",""); · if (!str.matches("[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)")) { ·
Author: awangdev
🌐
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
🌐
GitHub
github.com › vanyusuf1 › leetcode › blob › main › solutions › 8. String to Integer (atoi).java
leetcode/solutions/8. String to Integer (atoi).java at main · vanyusuf1/leetcode · GitHub
public int myAtoi(String s) { long rst = 0; long rst_too_large = (long)Integer.MAX_VALUE + 1; boolean negative = false; boolean found_digits = false; for (int i=0; i<s.length(); ++i) { // ch: +/-, digit, '.', space, oth ·
Author: vanyusuf1
🌐
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.
🌐
YouTube
youtube.com › que8
Solve String to Integer (atoi) in Java | LeetCode #8, Step-by-Step Solution - YouTube
Join us in this in-depth tutorial as we explore three Java solutions for converting a string into an integer, also known as "atoi." Learn how to handle space...
Published: July 23, 2023
Views: 42
🌐
YouTube
youtube.com › chatterjee tutoring
Leetcode #8: String to Integer (atoi) - Java tutorial - YouTube
In this video, I am walking you through how to do the eighth problem in the Leetcode problem set, String to Integer. I also run personalized 1-on-1 classes f...
Published: February 21, 2020
Views: 3K