编程题 第一题斐波拉契数列 据说是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]    所以第二题到底咋写嘛 
点赞 1
评论 2
全部评论

相关推荐

不愿透露姓名的神秘牛友
01-07 00:20
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务