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;
    }
};
相关推荐
risc-v@cn5 分钟前
【在ubuntu下使用vscode打开c++的make项目及编译调试】
c++·vscode·ubuntu
让我们一起加油好吗11 分钟前
【C++】多态(详解)
c++·visualstudio·多态·虚函数
草莓熊Lotso15 分钟前
【C++】--函数参数传递:传值与传引用的深度解析
c语言·开发语言·c++·其他·算法
不知名。。。。。。。。22 分钟前
算法 ----- 链式
算法
网易独家音乐人Mike Zhou24 分钟前
【Python】圆柱体内部3D点云仿真及ply文件生成,圆形3D点云检测及拟合算法
stm32·单片机·mcu·物联网·算法·点云·iot
zylyehuo36 分钟前
C++提高编程
c++
scx201310041 小时前
20250822 组题总结
c++·算法
智驱力人工智能1 小时前
智慧工厂烟雾检测:全场景覆盖与精准防控
人工智能·算法·安全·智慧城市·烟雾检测·明火检测·安全生产
困鲲鲲2 小时前
CMake2: CMakeLists.txt的常用命令
c++·cmake·常用命令
云边有个稻草人2 小时前
【C++】第二十五节—C++11 (上) | 详解列表初始化+右值引用和移动语义
c++·c++11·右值引用·移动语义·列表初始化·移动构造·移动赋值