Skip to content

Instantly share code, notes, and snippets.

@mlivingston40
Created March 25, 2024 14:08
Show Gist options
  • Save mlivingston40/d10a51677eb41bc7f107798817929a56 to your computer and use it in GitHub Desktop.
Save mlivingston40/d10a51677eb41bc7f107798817929a56 to your computer and use it in GitHub Desktop.
String to Int
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