LeetCode第8题:String to Integer (atoi)总结
题目: Implement atoi to convert a string to an integer. 大意:就是手动实现C语言里常用的atoi函数。。。 思路和吐槽: 我最讨厌这种了,完全的信息不对称。。要讨论的情况只有不断提交才知道出题人什么意思,我怎么知道你要求的是什么,况且这是算法题又不是工程题。。。。幸亏这道题比较简单,多试几次也不太费时。 代码 Python class Solution(object): def myAtoi(self, str): “”” :type str: str :rtype: int “”” str = str.strip() if not str: return 0 ans = [] neg = “-” pos = “+” ch = str[0] if ch == neg: c = -1 elif […]