classSolution: defmaxDivScore(self, nums: List[int], divisors: List[int]) -> int: mx, ans = -1, 0 for d in divisors: cur = 0# count of numbers divisible by d for x in nums: if x % d == 0: cur += 1 if cur > mx or (cur == mx and d < ans): # update answer mx, ans = cur, d return ans
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
classSolution { public: intmaxDivScore(vector<int>& nums, vector<int>& divisors){ int mx = -1, ans = 0; for (int d : divisors) { int cur = 0; for (int x : nums) if (x % d ==0) cur++; if (cur > mx || cur == mx && d < ans) { mx = cur; ans = d; } } return ans; } };
寫在最後
Cover photo is generated by @たろたろ, thanks for their work!