Leetcode 8. String to Integer (atoi)

Input: s = "42"
Output: 42
Explanation: The underlined characters are what is read in, the caret is the current reader position.
Step 1: "42" (no characters read because there is no leading whitespace)
^
Step 2: "42" (no characters read because there is neither a '-' nor '+')
^
Step 3: "42" ("42" is read in)
^
The parsed integer is 42.
Since 42 is in the range [-231, 231 - 1], the final result is 42.
Input: s = "   -42"
Output: -42
Explanation:
Step 1: " -42" (leading whitespace is read and ignored)
^
Step 2: " -42" ('-' is read, so the result should be negative)
^
Step 3: " -42" ("42" is read in)
^
The parsed integer is -42.
Since -42 is in the range [-231, 231 - 1], the final result is -42.
Input: s = "4193 with words"
Output: 4193
Explanation:
Step 1: "4193 with words" (no characters read because there is no leading whitespace)
^
Step 2: "4193 with words" (no characters read because there is neither a '-' nor '+')
^
Step 3: "4193 with words" ("4193" is read in; reading stops because the next character is a non-digit)
^
The parsed integer is 4193.
Since 4193 is in the range [-231, 231 - 1], the final result is 4193.

--

--

--

CS new grad, 6 years experience related to supply chain management. Located in Bay area

Love podcasts or audiobooks? Learn on the go with our new app.

Migrate RDBMS or On-Premise data to S3 using AWS EMR — Sqoop in 10 minutes

9 Reasons to learn PHP in 2019.

Protocol Buffers

Host your website using Github Pages

Archway testnet Torii-1. Post Genesis Validator launch guide.

Grammar in Natural Language

Skipping Class is Worse Than I Thought

Explore Struct and Classes in Swift :-

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gary Chiang

Gary Chiang

CS new grad, 6 years experience related to supply chain management. Located in Bay area

More from Medium

[Leet Code] Maximum Number of Words Found in Sentences

What is a Stack?

All Possible Full Binary Trees Solution | LeetCode-894: Medium | JavaScript Implementation

Sum of Subarray Ranges