
leetcode
x1074972500
这个作者很懒,什么都没留下…
展开
-
167. 两数之和 II - 输入有序数组
一开始使用暴力破解class Solution: def twoSum(self, numbers: 'List[int]', target: 'int') -> 'List[int]': res=[] for i,v in enumerate(numbers): if v<=target: ...原创 2019-02-24 16:23:03 · 123 阅读 · 0 评论 -
168. Excel表列名称(奇葩的时间排名)
在写leetcode的时候,发现有时候时间相差一点点,排名就有巨大变化68ms的战胜3.22%的人,40ms的就战胜99.77%的人,代码分别是class Solution: def convertToTitle(self, n: 'int') -> 'str': conv='ABCDEFGHIJKLMNOPQRSTUVWXYZ' s="...原创 2019-02-24 16:59:06 · 263 阅读 · 0 评论 -
172. 阶乘后的零
这道题都能看出来需要求的就是n!=1*2*3*4……*n中所有因子(1,2,3,4……n)的因式分解的结果里5的个数class Solution: def trailingZeroes(self, n: 'int') -> 'int': m=n//5 a=2 while True: if 5**a<=...原创 2019-02-24 18:15:51 · 155 阅读 · 0 评论 -
189. 旋转数组(简单的python的指针机制)
给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。尽可能想出更多的解决方案,至少有三种不同的方法可以解决这个问题。 要求使用空间复杂度为 O(1) 的原地算法考虑到空间复杂度为1,只有一个额外存储空间,一开始的想法是这样的class Solution: def rotate(self, nums: 'List[int]', k: 'int') -> ...原创 2019-02-24 21:42:57 · 261 阅读 · 0 评论