4.2蝦皮筆試

選擇題一如既往的不會。編程題第一題ac了,第二題60%,第三題0。
三道編程題是核心代碼模式,比當(dāng)初美團的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#筆試##投票#