lee≤e
lee≤e
全部文章
分类
题解(22)
归档
标签
去牛客网
登录
/
注册
leebobo
全部文章
(共25篇)
题解 | #数组里面没有出现过的数字#
#生成1-len(nums)的区间,再讲区间内元素与nums内元素比较,nums内没有该元素就把他添加进列表l2,set(nums)主要是为了去重,加快查找速度(nums去重前ac 790ms 5832kb,去重后56ms 6392kb)拿空间换时间 class Solution: def ...
Python3
2022-04-18
0
378
题解 | #调整数组顺序使奇数位于偶数前面(二)#
#用两个列表分别用来存奇数和偶数,最后奇数列表和偶数列表连接起来就行,时间复杂度满足,就是空间浪费了挺多 class Solution: def reOrderArrayTwo(self , array: List[int]) -> List[int]: # write...
Python3
2022-04-18
0
271
题解 | #平方升序数组#
#遍历数组nums,把每一个元素(nums[i])全部平方再赋值给nums[i] class Solution: def sortedArray(self , nums: List[int]) -> List[int]: # write code here ...
Python3
2022-04-18
0
440
题解 | #斐波那契数列#
#用递归会方便一点,这写法太cao了,三个变量轮流存 class Solution: def Fibonacci(self , n: int) -> int: # write code here f1,f2,sun=1,1,0 if n=...
Python3
2022-04-18
0
313
题解 | #最大公约数#
#辗转相除法 class Solution: def gcd(self , a: int, b: int) -> int: # write code here mini=max(a, b) mini1=min(a, b) ...
Python3
2022-04-18
0
264
题解 | #判断是否为回文字符串#
#和NC103一样,切片,[开始:结束:步长]直接反转看是否相等 class Solution: def judge(self , str: str) -> bool: # write code here res=str[::-1] if...
Python3
2022-04-18
0
245
题解 | #反转字符串#
#切片可太好用了,[开始:结束:步长] class Solution: def solve(self , str: str) -> str: # write code here if str=="": return "" ...
Python3
2022-04-18
0
260
题解 | #旋转字符串#
#切片然后连接看连接后的字符串是不是和字符串B一样 class Solution: def solve(self , A: str, B: str) -> bool: # write code here if len(A)!=len(B): ...
Python3
2022-04-18
0
247
题解 | #移动 0#
#啊这啊这,直接遍历,遇到0 remove删除,后在列表尾append class Solution: def moveZeroes(self , nums: List[int]) -> List[int]: # write code here for...
Python3
2022-04-18
2
413
题解 | #懂二进制#
#想着把两个数字转为二进制字符串然后拿出长度最短的那个与最长的每一位做比较,最后加上长度差,但是只能a到6/10 数据 16807,282475249出错,GG # l1 = bin(m) # l2 = bin(n) # l3 = min(l1, l2...
Python3
2022-04-18
0
478
首页
上一页
1
2
3
下一页
末页