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;
    }
};
相关推荐
MadPrinter1 分钟前
FindQC 实战 (一):基于 SerpApi 的电商高质量图片自动化筛选算法初探
运维·python·算法·自动化
小毅&Nora3 分钟前
【人工智能】【深度学习】 ③ DDPM核心算法介绍:从噪声到图像的魔法
人工智能·深度学习·算法
freedom_1024_3 分钟前
C++运算符重载:从本质到实践
开发语言·c++
h***01544 分钟前
图解缓存淘汰算法 LRU、LFU | 最近最少使用、最不经常使用算法 | go语言实现
算法·缓存·golang
sheeta19984 分钟前
LeetCode 每日一题笔记 日期:2025.12.01 题目:2141.同时运行 N 台电脑的最长时间
笔记·leetcode·电脑
moonquakeTT5 分钟前
雷达信号处理中的CFAR检测关键要点
人工智能·算法·目标跟踪·fmcw毫米波
元亓亓亓6 分钟前
LeetCode热题100--34. 在排序数组中查找元素的第一个和最后一个位置--中等
数据结构·算法·leetcode
郝学胜-神的一滴7 分钟前
Linux信号的概念与机制
linux·服务器·开发语言·c++·程序人生
ComputerInBook10 分钟前
理解数学概念——素数(质数)(prime)
算法·数论·质数·素数
编程小Y10 分钟前
C++ ODB ORM 从入门到实战应用
开发语言·c++