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 ...
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
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
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
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.
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
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