diff --git a/src/stringToInt.py b/src/stringToInt.py index f5dbef9..b053202 100644 --- a/src/stringToInt.py +++ b/src/stringToInt.py @@ -1,3 +1,11 @@ # return the int representation of string s def stringToInt(s): - pass \ No newline at end of file + result = 0 + power = 1 + sign = 1 - 2*('-' == s[0]) + if sign == -1: + s = s[1:] + for c in reversed(s): + result += (ord(c)-ord('0'))*power + power *= 10 + return result*sign