Python解决方案:
def myAtoi(self, s): """ :type str: s :rtype: int """ s = s.lstrip() if not s: return 0 header = s[0] length = len(s) if header.isnumeric(): out = "" i = 0 while i < len(s) and s[i].isnumeric(): out += s[i] i += 1 return int(out) elif header in ["+","-"]: if length == 1: return 0 else: if not s[1].isnumeric(): return 0 out = header i = 1 while i < len(s) and s[i].isnumeric(): out += s[i] i += 1 return int(out) else: return 0