@SomeBottleLeetcode每日一题 —— 3622. 判断整除性 中发帖

思路
纯模拟题,答案就在题面上。 

代码
class Solution {
public:
    bool checkDivisibility(int n) {
        // 纯模拟
        int dSum = 0, dProd = 1;
        int tmp = n;
        while (tmp > 0) {
            int d = tmp % 10;
            dSum += d;
            dProd *= d;
            tmp /= 10;
        }
        return n % (dSum + dProd) == 0;
    }
};


昨天那道题最多只能想到二分了,看了看题解发现涉及容斥原理、最小公倍数、位掩码,真的是挺有难度的一道题。 
整了道中等...
 
 
Back to Top