4.2虾皮笔试

选择题一如既往的不会。编程题第一题ac了,第二题60%,第三题0。

三道编程题是核心代码模式,比当初美团的ACM模式好一点。

第一题比较简单,用了个字典记录一下就过了。第二题感觉写的挺对,但只有60%(或许是超时?),第三题比较抽象,确实搞不出来。

#第一题
import collections
class Solution:
    def findBall(self, nums) :
        # write code here
        n,ans=len(nums),[]
        idx=collections.defaultdict(int)
        for i in range(n):
            idx[nums[i]]+=1
        for i in range(n):
            if idx[nums[i]]>=(n/4):
                if nums[i] not in ans:
                    ans.append(nums[i])
        return sorted(ans)
#第二题
import collections
class Solution:
    def homework(self, input) :
        N,m,seed=input
        ans=[]
        # write code here
        for i in range(m):
            a=(359*i+199*seed)%N+1
            b=(101*i+53*seed)%N+1
            n=(13*i+277*seed)%10+1
            ans.append([min(a,b),max(a,b),n])

        idx=collections.defaultdict(int)
        lans=len(ans)
        for i in range(lans):
            a1,b1,c1=ans[i]
            for j in range(a1,b1+1):
                idx[j]+=c1               
        res=0
        for i in range(N):
            res+=idx[i+1]*idx[i+1]         
        return res%10007
	  
#第三题
def findNum(self, N: int) -> int:
    # write code here
    i = 1
    while True:
        out = i * N
        out = str(out)
        if not Counter(out)['0'] + Counter(out)['1'] == len(out):
            i += 1
        else:
            return i

#笔试##投票#
全部评论
我是一题迷宫 一题二叉树层序遍历 一题分割等和子集
5 回复 分享
发布于 04-02 21:03 湖南
佬是啥岗
1 回复 分享
发布于 04-02 21:03 四川
跟我的题一样,前两道写出来了,第三道10%,第三道貌似要用离散化差分数组之类的,我属实搞不出来
点赞 回复 分享
发布于 04-03 01:40 河南

相关推荐

评论
1
3
分享

创作者周榜

更多
牛客网
牛客企业服务