MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / myAtoi

Method myAtoi

8-String-to-Integer/string-to-integer.cpp:6–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4class Solution {
5public:
6 int myAtoi(string s) {
7 int f=1, i=0, n=s.size();
8 long long num=0;
9 while(i<n && s[i]==' '){
10 i++;
11 }
12 if(s[i] == '-'){
13 f = f*-1;
14 i++;
15 }
16 else if(s[i] == '+'){
17 i++;
18 }
19 while(isdigit(s[i])){
20 num = num*10 + (s[i]-'0');
21 if(num>INT_MAX && f==-1)
22 return INT_MIN;
23 else if(num>INT_MAX && f==1)
24 return INT_MAX;
25 i++;
26 }
27 return num*f;
28 }
29};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected