Created
March 25, 2024 14:08
-
-
Save mlivingston40/d10a51677eb41bc7f107798817929a56 to your computer and use it in GitHub Desktop.
String to Int
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def __init__(self): | |
self.numeric_set = [str(i) for i in range(10)] | |
self.allowed_set = self.numeric_set | |
self.allowed_set.append("-") | |
def myAtoi(self, s: str) -> int: | |
s_list = list(s) | |
out_str_list = [] | |
for e in s_list: | |
if e in self.allowed_set: | |
out_str_list.append(str(e)) | |
out_str = ''.join(str(i) for i in out_str_list) | |
return int(out_str) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment