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;
    }
};
相关推荐
念恒123063 分钟前
Linux初识
linux·服务器·c++
2301_822703209 分钟前
光影进度条:鸿蒙Flutter实现动态光影效果的进度条
算法·flutter·华为·信息可视化·开源·harmonyos
人道领域9 分钟前
【LeetCode刷题日记】383 赎金信
算法·leetcode·职场和发展
炽烈小老头17 分钟前
【每天学习一点算法 2026/04/11】Pow(x, n)
学习·算法
旖-旎19 分钟前
哈希表(存在重复元素)(3)
数据结构·c++·学习·算法·leetcode·散列表
明月醉窗台20 分钟前
[jetson] AGX Xavier 安装Ubuntu18.04及jetpack4.5
人工智能·算法·nvidia·cuda·jetson
计算机安禾21 分钟前
【数据结构与算法】第39篇:图论(三):最小生成树——Prim算法与Kruskal算法
开发语言·数据结构·c++·算法·排序算法·图论·visual studio code
weixin_5134499624 分钟前
walk_these_ways项目学习记录第九篇(通过行为多样性 (MoB) 实现地形泛化)--学习算法
学习·算法·机器学习
fish_xk25 分钟前
c++内存管理
开发语言·c++·算法
Tisfy30 分钟前
LeetCode 3740.三个相等元素之间的最小距离 I:今日先暴力,“明日“再哈希
算法·leetcode·哈希算法·题解·模拟·遍历·暴力