新浪算法笔试

选择和问答题第一道都不难,第二道没时间整,编程题第一题不知道为什么卡30%
# 魔法森林 30%
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
# @param animals int整型二维数组 
# @return int整型
#
class Solution:
    def aliveDays(self , animals ):
        # write code here
        out = []
        animals.sort(reverse=True)
        for i in range(len(animals)-1):
            ans = 1
            while animals[i][1] > animals[i+1][1]:
                i += 1
                ans += 1
                if i+1 == len(animals):
                    break
            out.append(ans)
        return max(out)
# 数组移位 100%
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
# 在nums原数组上进行操作,返回修改后的nums
# @param nums int整型一维数组 
# @return int整型一维数组
#
class Solution:
    def moveZeros(self , nums ):
        # write code here
        a = []
        for i,num in enumerate(nums):
            if num != 0:
                a.append(i)
        for j in range(len(nums)):
            if j < len(a):
                nums[j] = nums[a[j]]
            else:
                nums[j] = 0
        return nums

#新浪微博笔试##笔经##新浪#
全部评论
楼主后端?
点赞 回复
分享
发布于 2021-08-18 20:42
第一个只有30的话可能超时了?
点赞 回复
分享
发布于 2021-08-18 20:51
联想
校招火热招聘中
官网直投
第一题,比如今天的猎物是[10,10],剩余的猎物有[9,8]和[8,9],那这两个其实都要考虑才行……我也是漏掉了这种情况,只通过40%
点赞 回复
分享
发布于 2021-08-18 22:34
第一题其实就是合并矩形,用dp做就可以ac了
点赞 回复
分享
发布于 2021-08-18 23:00
第一题leetcode上俄罗斯套娃
点赞 回复
分享
发布于 2021-08-18 23:44
第一题感觉排序加最大子序列
点赞 回复
分享
发布于 2021-08-19 07:22
俄罗斯套娃 我和你一样也是 30 100
点赞 回复
分享
发布于 2021-08-20 15:25

相关推荐

2 5 评论
分享
牛客网
牛客企业服务