From f98922a4f263101c37a6f79f289a5248f2a7fb10 Mon Sep 17 00:00:00 2001 From: Anubha13kumari Date: Fri, 1 Oct 2021 22:11:51 +0530 Subject: [PATCH 1/7] added code for string to integer --- stringtointeger.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 stringtointeger.py diff --git a/stringtointeger.py b/stringtointeger.py new file mode 100644 index 0000000..4f85ba1 --- /dev/null +++ b/stringtointeger.py @@ -0,0 +1,24 @@ +class Solution: + def myAtoi(self, s: str) -> int: + + ans = 0 + sign = 1 + index = 0 + + s = s.strip() # deleting all leading spaces + + if len(s) == 0: + return 0 + + if s[0] == '-': + sign = -1 + index += 1 + elif s[0] == '+': + index += 1 + + while index < len(s) and s[index].isdigit(): + ans = ans * 10 + int(s[index]) + index += 1 + + ans = min(max(sign*ans, -2**31), 2**31-1) + return ans \ No newline at end of file From 4b226d53d1ec9915530a63dd07b8e4cf8f5453a6 Mon Sep 17 00:00:00 2001 From: Anubha13kumari Date: Fri, 1 Oct 2021 22:50:07 +0530 Subject: [PATCH 2/7] created folder 0008 --- stringtointeger.py => 0008/stringtointeger.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename stringtointeger.py => 0008/stringtointeger.py (100%) diff --git a/stringtointeger.py b/0008/stringtointeger.py similarity index 100% rename from stringtointeger.py rename to 0008/stringtointeger.py From f14f3ba5a3d5948e2d1247a94e9a991a141e3828 Mon Sep 17 00:00:00 2001 From: Anubha13kumari Date: Fri, 1 Oct 2021 22:56:33 +0530 Subject: [PATCH 3/7] fixed linting issue --- 0008/stringtointeger.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/0008/stringtointeger.py b/0008/stringtointeger.py index 4f85ba1..0ca1437 100644 --- a/0008/stringtointeger.py +++ b/0008/stringtointeger.py @@ -1,24 +1,18 @@ class Solution: def myAtoi(self, s: str) -> int: - ans = 0 sign = 1 index = 0 - s = s.strip() # deleting all leading spaces - if len(s) == 0: return 0 - if s[0] == '-': sign = -1 index += 1 elif s[0] == '+': index += 1 - while index < len(s) and s[index].isdigit(): ans = ans * 10 + int(s[index]) index += 1 - ans = min(max(sign*ans, -2**31), 2**31-1) return ans \ No newline at end of file From 90815182292e0b86c39e80c9dc040a5f02921558 Mon Sep 17 00:00:00 2001 From: Anubha13kumari Date: Fri, 1 Oct 2021 23:04:15 +0530 Subject: [PATCH 4/7] fixed linting issue --- 0008/stringtointeger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/0008/stringtointeger.py b/0008/stringtointeger.py index 0ca1437..12543d4 100644 --- a/0008/stringtointeger.py +++ b/0008/stringtointeger.py @@ -3,7 +3,7 @@ def myAtoi(self, s: str) -> int: ans = 0 sign = 1 index = 0 - s = s.strip() # deleting all leading spaces + s = s.strip() # deleting all leading spaces if len(s) == 0: return 0 if s[0] == '-': @@ -14,5 +14,5 @@ def myAtoi(self, s: str) -> int: while index < len(s) and s[index].isdigit(): ans = ans * 10 + int(s[index]) index += 1 - ans = min(max(sign*ans, -2**31), 2**31-1) + ans = min(max(sign * ans, - 2 ** 31), 2 ** 31 - 1) return ans \ No newline at end of file From 1d8fd6e3992ecbedf9174659bcb429cb8ccfd8f4 Mon Sep 17 00:00:00 2001 From: Anubha13kumari Date: Fri, 1 Oct 2021 23:10:49 +0530 Subject: [PATCH 5/7] fixed linting issue --- 0008/stringtointeger.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/0008/stringtointeger.py b/0008/stringtointeger.py index 12543d4..07adec0 100644 --- a/0008/stringtointeger.py +++ b/0008/stringtointeger.py @@ -3,7 +3,7 @@ def myAtoi(self, s: str) -> int: ans = 0 sign = 1 index = 0 - s = s.strip() # deleting all leading spaces + s = s.strip() # deleting all leading spaces if len(s) == 0: return 0 if s[0] == '-': @@ -15,4 +15,5 @@ def myAtoi(self, s: str) -> int: ans = ans * 10 + int(s[index]) index += 1 ans = min(max(sign * ans, - 2 ** 31), 2 ** 31 - 1) - return ans \ No newline at end of file + return ans + \ No newline at end of file From 07b25796cc7d6cee4a2e56307c8f491a0fead2a9 Mon Sep 17 00:00:00 2001 From: Anubha13kumari Date: Fri, 1 Oct 2021 23:12:54 +0530 Subject: [PATCH 6/7] fixed linting issue --- 0008/stringtointeger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/0008/stringtointeger.py b/0008/stringtointeger.py index 07adec0..99f25b4 100644 --- a/0008/stringtointeger.py +++ b/0008/stringtointeger.py @@ -16,4 +16,4 @@ def myAtoi(self, s: str) -> int: index += 1 ans = min(max(sign * ans, - 2 ** 31), 2 ** 31 - 1) return ans - \ No newline at end of file + \ No newline at end of file From 2bf29966c6f3b0e2b07ae25c3c19d23e41038d09 Mon Sep 17 00:00:00 2001 From: Anubha13kumari Date: Sat, 2 Oct 2021 13:17:32 +0530 Subject: [PATCH 7/7] fixed linting issue --- 0008/stringtointeger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/0008/stringtointeger.py b/0008/stringtointeger.py index 99f25b4..ccb4695 100644 --- a/0008/stringtointeger.py +++ b/0008/stringtointeger.py @@ -16,4 +16,4 @@ def myAtoi(self, s: str) -> int: index += 1 ans = min(max(sign * ans, - 2 ** 31), 2 ** 31 - 1) return ans - \ No newline at end of file + \ No newline at end of file