Python easy solution o(n)


#1

`class Solution:
# @param A : string
# @return an integer
def atoi(self, A):
A= A.strip()
isNegative = False
num = 0
digitStart = False
signCount = 0
for i in range(len(A)):
if ord(A[i]) not in range(48,58) and A[i] != ‘-’ and A[i] != ‘+’:

            break
        elif (A[i] == '-' or A[i] == '+') and i != 0:
            
            break
        elif (A[i] == '-' or A[i] == '+') and digitStart:
            
            break
        elif (A[i] == '-' or A[i] == '+') and signCount == 1:
            
            break
        else:
            if A[i] == '-' or A[i] == '+':
                
                if A[i] == '-' :
                    isNegative = True
                signCount += 1
            elif ord(A[i]) in range(48,58):
                
                num = (num*10)+ int(A[i])
        
        
    
    if isNegative:
        if num > 2147483648:
            return -2147483648
        else:
            return -num
    else:
        if num > 2147483647:
            return 2147483647
        else:
            return num`