Topic: 2644. Find the integer with the highest divisibility score

​​The source of the topic

        Leetcode topic, website: 2644. Find the integer with the largest divisibility score - LeetCode

Problem-solving ideas:

       Just traverse the calculation.

Problem-solving code:

class Solution {
    public int maxDivScore(int[] nums, int[] divisors) {
        int score=0;
        int res=divisors[0];
        for(int divisor:divisors){
            int thisScore=0;
            for(int num:nums){
                if(num%divisor==0){
                    thisScore++;
                }
            }
            if(thisScore>score || (thisScore==score && divisor<res)){
                score=thisScore;
                res=divisor;
            }
        }
        return res;
    }
}
 
 

Summarize:

        No official solution.


Guess you like

Origin blog.csdn.net/2301_76145947/article/details/132693197