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;
    }
};
相关推荐
云析赢指标公式网413 小时前
通达信ATAN均线角度公式源码笔记:四周期角度计算与DRAWBAND色带实现
笔记·算法
01二进制代码漫游日记13 小时前
[C++]之内存管理(一)
jvm·c++·学习
21岁被迫秃头13 小时前
SVT-AV1 Mini-Gop决策算法详解+源码分析.md
算法·av1·svt-av1·源码详解·mini-gop决策
Kobebryant-Manba13 小时前
IEKT向量矩阵流程&评估
人工智能·算法·矩阵
codebolt13 小时前
C++程序crash分析和内存检测
开发语言·c++
Js.Tx13 小时前
【具体数学 Concrete Mathematics】2.1.7 无限和式
算法·具体数学
ShineWinsu13 小时前
对于Qt:QLabel常见属性的解析
c++·qt·面试·笔试·gui·标签·qlabel
FPGA信号处理13 小时前
【 凸优化】第六讲:求解器与支持向量机
算法·机器学习·支持向量机
专注仿真13 小时前
支持向量机(SVM)算法详解与代码实例
算法·机器学习·支持向量机
Pniubi13 小时前
力扣42接雨水(动态规划法)
算法·leetcode·职场和发展