Implementation of atoi

O(N) solution.