15% off all plans & roadmaps Use code
See plansLeetCode 8 · Solution & editorial
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer.
String to Integer (atoi) is a String Manipulation Patterns problem, in the Integer and Roman Conversion subpattern. The pattern covers palindrome checking, anagram detection, pattern matching, and string conversion
Learn to convert between integers and Roman numerals. Essential string manipulation problem.
The reference solution runs in O(n) time and O(1) space.
String to Integer (atoi) has been reported in interviews at Facebook, Amazon, Microsoft, Google, Goldman Sachs, Apple, Adobe, Bloomberg.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
String to Integer (atoi) is a String Manipulation Patterns problem, in the Integer and Roman Conversion subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.