LeetCode
leetcode.com › problems › string-to-integer-atoi
String to Integer (atoi) - LeetCode
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: ...
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
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.
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.
AlgoMonster
algo.monster › home › 8. string to integer (atoi)
8. String to Integer (atoi) - In-Depth Explanation
The problem asks you to implement a function myAtoi(string s) that converts a string to a 32-bit signed integer, similar to C/C++'s atoi function.
After 3 hours of pain and misery, my solution to “String to Integer” on LeetCode
Your approach to taking screenshots is deeply disturbing. More on reddit.com
How is this test case valid?
Rule number 1: If the like to dislike ratio is less than 1, don’t solve it
More on reddit.com06:22
String to Integer (atoi) LeetCode 8 | Easy & Clear Explanation ...
12:28
String to Integer (atoi) | Leetcode 8 - YouTube
11:40
String to Integer atoi | Leetcode 8 | Implement atoi | Amazon ...
09:36
LeetCode String to Integer (atoi) | Java - YouTube
16:59
String to Integer atoi 🔥| Leetcode 8 | String - YouTube
07:47
String To Integer (atoi) - 8. LeetCode - Java - YouTube
WalkCCC
walkccc.me › LeetCode › problems › 8
8. String to Integer (atoi) - LeetCode Solutions
LeetCode Solutions in C++23, Java, Python, MySQL, and TypeScript.
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 · class Solution: def myAtoi(self, s: str) -> int: s = s.strip() if not s: return 0 sign = -1 if s[0] == '-' else 1 if s[0] in {'-', '+'}: s = s[1:] num = 0 for c in s: if not c.isdigit(): break num = num * 10 + int(c) if sign * num <= -2**31: return -2**31 if sign * num >= 2**31 - 1: return 2**31 - 1 return sign * num #code by PROGIEZ · Explore all Leetcode problems solutions at Progiez here
Red Quark
redquark.org › leetcode › 0008-string-to-integer-atoi
LeetCode #8 - String To Integer (atoi) | Red Quark
fun myAtoi(s: String): Int { var str = s // Base condition if (str.isEmpty()) { return 0 } // MAX and MIN values for integers val max = 2147483647 val min = -2147483648 // Trimmed string str = str.replace("^\\s+".toRegex(), "") // Counter var i = 0 // Flag to indicate if the number is negative val isNegative: Boolean = str.startsWith("-") // Flag to indicate if the number is positive val isPositive: Boolean = str.startsWith("+") if (isNegative) { i++ } else if (isPositive) { i++ } // This will store the converted number var number = 0.0 // Loop for each numeric character in the string iff nume
Reddit
reddit.com › r/programminghorror › after 3 hours of pain and misery, my solution to “string to integer” on leetcode
r/programminghorror on Reddit: After 3 hours of pain and misery, my solution to “String to Integer” on LeetCode
January 4, 2024 -
I kept getting stupid test cases and the description was incredibly unspecific, so even though I switched over to python my code ended up a giant, mangled, unreadable monstrosity due to adding so many parameters
Top answer 1 of 5
898
Your approach to taking screenshots is deeply disturbing.
2 of 5
634
I don't think this should be that hard. EDIT: This is what I would have done: Remove leading and trailing whitespace Check first symbol for + or - to know integer sign, and remove that symbol (not if it is a digit) Assign accumulator acc = 0 Start from leftmost digit, convert it to integer ("9" -> 9) then add into an accumulator variable like acc = acc*10 + digit, loop till all digits Make accumulator negative if negative sign was present Return accumulator
Doocs
leetcode.doocs.org › en › lc › 8
8. String to Integer (atoi) - LeetCode Wiki
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer.
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
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).
Gitlab
memorylimitexceeded.gitlab.io › leetcode › problems › 0008-string-to-integer-atoi.html
8. String to Integer (atoi) | Leetcode Solutions
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.
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.