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;
    }
};
相关推荐
Wect2 分钟前
LeetCode 46. 全排列:深度解析+代码拆解
前端·算法·typescript
颜酱4 分钟前
Dijkstra 算法:从 BFS 到带权最短路径
javascript·后端·算法
xlp666hub1 小时前
C++ 链表修炼指南
数据结构·c++
木心月转码ing3 小时前
Hot100-Day24-T128最长连续序列
算法
小肥柴3 小时前
A2UI:面向 Agent 的声明式 UI 协议(三):相关概念和技术架构
算法
学高数就犯困6 小时前
性能优化:LRU缓存(清晰易懂带图解)
算法
xlp666hub8 小时前
Leetcode第七题:用C++解决接雨水问题
c++·leetcode
CoovallyAIHub8 小时前
CVPR 2026 | MixerCSeg:仅2.05 GFLOPs刷新四大裂缝分割基准!解耦Mamba隐式注意力,CNN+Transformer+Mamba三
深度学习·算法·计算机视觉
CoovallyAIHub9 小时前
YOLO26-Pose 深度解读:端到端架构重新设计,姿态估计凭什么跨代领先?
深度学习·算法·计算机视觉
CoovallyAIHub9 小时前
化工厂气体泄漏怎么用AI检测?30张图3D重建气体泄漏场景——美国国家实验室NeRF新研究
深度学习·算法·计算机视觉