LeetCode每日一题——2520. Count the Digits That Divide a Number

文章目录

一、题目

2520. Count the Digits That Divide a Number

Given an integer num, return the number of digits in num that divide num.

An integer val divides nums if nums % val == 0.

Example 1:

Input: num = 7

Output: 1

Explanation: 7 divides itself, hence the answer is 1.

Example 2:

Input: num = 121

Output: 2

Explanation: 121 is divisible by 1, but not 2. Since 1 occurs twice as a digit, we return 2.

Example 3:

Input: num = 1248

Output: 4

Explanation: 1248 is divisible by all of its digits, hence the answer is 4.

Constraints:

1 <= num <= 109

num does not contain 0 as one of its digits.

二、题解

cpp 复制代码
class Solution {
public:
    int countDigits(int num) {
        int tmp = num;
        int res = 0;
        while(tmp){
            int mod = tmp % 10;
            if(num % mod == 0) res++;
            tmp = tmp / 10;
        }
        return res;
    }
};
相关推荐
人道领域3 分钟前
【LeetCode刷题日记】51.N皇后
数据结构·算法
古城小栈9 小时前
为啥说:训练用BF16,推理用FP16
人工智能·算法·机器学习
KaMeidebaby9 小时前
卡梅德生物技术快报|蛋白 N 端测序在重组贻贝融合蛋白表征中的应用,解决原核表达序列偏移工艺难题
前端·人工智能·物联网·算法·百度
浆果02079 小时前
NanoTrack C++ — RK3588 实时目标跟踪
c++·目标跟踪·rk3588
Turbo正则10 小时前
群论在AI中的应用概述
人工智能·算法·抽象代数
ysa05103010 小时前
【并查集】判环
c++·笔记·算法
持力行10 小时前
C/C++ 中的 char*:它标识数组吗?为什么能用下标访问?
c语言·c++
Jerry10 小时前
KeetCode 44. 开发商购买土地
算法
Jerry10 小时前
KeetCode 58. 区间和
算法
Jerry11 小时前
LeetCode 209. 长度最小的子数组
算法