swaaaay
swaaaay
全部文章
题解
未归档(36)
归档
标签
去牛客网
登录
/
注册
swaaaay的博客
全部文章
/ 题解
(共47篇)
题解 | #统计每个月兔子的总数#
来自专栏
python实现斐波那契数列 def get_ans(s): ans=[0,1,1] if s<=2: return ans[s] for i in range(3,s+1): ans.append(ans[i-1]+ans[i-2]) ...
Python3
2021-11-11
0
313
题解 | #求最大连续bit数#
来自专栏
非常暴力的解法,每遇到一个1则res+1,每遇到一个0则res=0,列表记录res的值,最后返回max(列表) def get_ans(s): ans=[] res=0 mark=str(bin(int(s))) for i in mark: if i...
Python3
2021-11-09
1
480
题解 | #二叉树中和为某一值的路径(一)#
来自专栏
python递归 class Solution: def hasPathSum(self , root: TreeNode, sum: int) -> bool: # write code here if not root: return False ...
Python3
二叉树
递归
2021-11-08
0
349
题解 | #把二叉树打印成多行#
来自专栏
二叉树好难。。。 class Solution: # 返回二维列表[[1,2],[4,5]] def Print(self, pRoot): # write code here if not pRoot:return [] result...
Python3
二叉树
2021-11-08
0
418
题解 | #合并两个排序的链表#
来自专栏
class Solution: def Merge(self, pHead1, pHead2): # write code here cur1,cur2=pHead1,pHead2 '''极端情况''' if not cur1:...
Python3
2021-11-05
1
398
题解 | #构建乘积数组#
来自专栏
每次循环浅拷贝A数组切片,结果数组对应索引位置进行乘积赋值操作 class Solution: def multiply(self , A: List[int]) -> List[int]: # write code here ans=[1 for _ ...
Python3
数组
2021-11-05
2
441
题解 | #在排序数组中查找数字 I#
来自专栏
暴力解法可以做,这个题解给出另一种方法:二分法找左边界的思路 class Solution: def search(self , nums: List[int], target: int) -> int: # write code here """极端情...
Python3
数组
2021-11-05
0
569
题解 | #和为S的两个数字#
来自专栏
class Solution: def FindNumbersWithSum(self , array: List[int], sum: int) -> List[int]: # write code here left,right=0,len(arra...
Python3
2021-11-02
0
492
题解 | #斐波那契数列#
来自专栏
第0项置0,若n>=3,向列表尾部追加n-2次倒数第1,2项之和,最后返回列表最后一项 class Solution: def Fibonacci(self , n: int) -> int: # write code here ans=[0,1,...
Python3
2021-11-02
0
421
题解 | #旋转数组的最小数字#
来自专栏
# -*- coding:utf-8 -*- class Solution: def minNumberInRotateArray(self, rotateArray): # write code here if not rotateArray:return ...
Python3
双指针
2021-10-28
1
536
首页
上一页
1
2
3
4
5
下一页
末页