作业帮算法笔试python

编程题
第一题斐波拉契数列 据说是leetcode873原题
class Solution(object):
def lenLongestFibSubseq(self, A):
"""
:type A: List[int]
:rtype: int
"""
s = set(A)
n = len(A)
res = 0
for i in range(n - 1):
for j in range(i 1, n):
a, b = A[i], A[j]
count = 2
while a b in s:
a, b = b, a b
count = 1
res = max(res, count)
return res if res > 2 else 0

第二题 给一链表和pivot,按左边小于pivot,中间等于pivot,右边大于pivot的顺序排序,且保证原有顺序不变。
这题不知道怎么输入,要求时间O(n),空间O(1),不知道咋做。
第三题 约塞夫环问题,牛客剑指offer原题
def LastRemaining_Solution(self, n, m):
if not n and not m :
return -1
res = range(n)
i = 0
while len(res)>1:
i = (m i-1)%len(res)
res.pop(i)
return res[0]
所以第二题到底咋写嘛
#作业帮##笔试题目##算法工程师##Python#
全部评论
第二题leetcode好像有
点赞 回复
分享
发布于 2019-09-05 23:46
第二题可以设置三个引用(小于,等于,大于),遍历链表依次填值,每次小等大都填一个,继续遍历链表,填没有出现过的值,最后三个引用连上就好了。
点赞 回复
分享
发布于 2019-09-06 03:46
小红书
校招火热招聘中
官网直投

相关推荐

点赞 13 评论
分享
牛客网
牛客企业服务