From 3479ba3870da2d83f74c2fa84380897891ff4536 Mon Sep 17 00:00:00 2001 From: ujnomw Date: Sat, 10 Mar 2018 15:02:18 +0300 Subject: [PATCH] stringToInt implemented --- src/stringToInt.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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