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;
    }
};
相关推荐
进击的圆儿17 分钟前
高并发内存池项目开发记录 - 02
开发语言·c++·实战·项目·内存池
YXXY31320 分钟前
二叉树进阶
c++
Antonio91526 分钟前
【图像处理】常见图像插值算法与应用
图像处理·算法·计算机视觉
夜晚中的人海28 分钟前
【C++】使用双指针算法习题
开发语言·c++·算法
怀旧,30 分钟前
【Linux系统编程】3. Linux基本指令(下)
linux·开发语言·c++
艾莉丝努力练剑31 分钟前
【C++STL :stack && queue (三) 】优先级队列的使用以及底层实现
linux·开发语言·数据结构·c++·stl
im_AMBER2 小时前
数据结构 06 线性结构
数据结构·学习·算法
earthzhang20214 小时前
【1028】字符菱形
c语言·开发语言·数据结构·c++·算法·青少年编程
papership4 小时前
【入门级-算法-3、基础算法:二分法】
数据结构·算法
hjlgs4 小时前
Linux中双向链表介绍
数据结构·链表