题目: 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 […]

题目 Determine whether an integer is a palindrome. Do this without extra space. 大意:判断一个整数是不是回文的。。 吐槽: 同第7题:用Python简直就是作弊啊。。。。。 代码 Python class Solution(object): def isPalindrome(self, x): “”” :type x: int :rtype: bool “”” x = str(x) x = x.strip() if x[::1] == x[::-1]: return True else: return False