摘要: 递归,但是用Python3递归时可以加装饰器:@functools.lru_cache() 这是一个缓存工具,可以把之前算过的一些函数保存下来,加速程序运行. 本题不加这个装饰器会超时. 其实加了这个装饰器以后,是O(n)的时间复杂度,不加的话就由于函数会重复调用,时间开销更大. 阅读全文
posted @ 2019-03-20 22:42 周洋 阅读(123) 评论(0) 推荐(0) 编辑
摘要: class Solution(object): def fib(self, N): """ :type N: int :rtype: int """ F=[0]*31 F[1]=1 for i in range(2,31): F[i]=F[i-1]+F[... 阅读全文
posted @ 2019-03-20 08:07 周洋 阅读(90) 评论(0) 推荐(0) 编辑
摘要: class Solution(object): def numJewelsInStones(self, J, S): """ :type J: str :type S: str :rtype: int """ count=collections.Counter(S) ans=0... 阅读全文
posted @ 2019-03-20 07:50 周洋 阅读(84) 评论(0) 推荐(0) 编辑
摘要: class Solution(object): def containsDuplicate(self, nums): """ :type nums: List[int] :rtype: bool """ count=collections.Counter(nums) for i in coun... 阅读全文
posted @ 2019-03-20 07:47 周洋 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 送分题 阅读全文
posted @ 2019-03-20 07:33 周洋 阅读(69) 评论(0) 推荐(0) 编辑
摘要: 送分题 阅读全文
posted @ 2019-03-20 07:28 周洋 阅读(104) 评论(0) 推荐(0) 编辑
摘要: chr():十进制或十六进制数(0-255)转成对应的ASCII字符. ord():ASCII字符转成对应的十进制数. 一个小性质:ASCII表中大写字母排在前面小写排在后面,相差32. 比如: 阅读全文
posted @ 2019-03-20 07:21 周洋 阅读(2194) 评论(0) 推荐(0) 编辑
摘要: #approach 1 class Solution: def toLowerCase(self, str): return "".join(chr(ord(c) + 32) if "A" <= c <= "Z" else c for c in str) #approach 2 class Solution: def toLowerCase(self, str)... 阅读全文
posted @ 2019-03-20 07:15 周洋 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 改写:(都不会改变原字符串) #大变小小变大 s.swapcase()Out[15]: 'HeLLO WoRLD' 判断: 阅读全文
posted @ 2019-03-20 07:04 周洋 阅读(3821) 评论(0) 推荐(0) 编辑