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;
    }
};
相关推荐
有只小白叫岳飒1 分钟前
c++智能指针 unique_ptr与函数调用
c++
Shaoshing2 分钟前
BHU 润石工作室 251019自建赛题解
算法
Leo.yuan6 分钟前
Kafka+Flink拼凑,还是FineDataLink 5.0一体化?实时数据处理的两种思路
c++·mfc
玩AI的奶茶20 分钟前
24GB 显存能跑多大的模型?参数量、精度与显存占用对照表
人工智能·python·算法·ai·aigc·gpu算力·算力租赁
java_nnnn32 分钟前
LeetCode刷题双指针(有效三角形的个数+三数之和)Java
算法·leetcode·职场和发展
人工智能培训34 分钟前
智能博弈背景下中国AI国防建设的战略价值
大数据·人工智能·算法·重构·生活
flinn_small43 分钟前
三分算法:原理、实现与实战应用
数据结构·算法·三分
思茂信息1 小时前
CST软件UV Slice切片后可直接删除指定一侧实体
算法·uv·emc·emi·cst·仿真软件
INGNIGHT1 小时前
944 · 最大子矩阵(前缀和)
数据结构·c++·算法
All for pursuit.2 小时前
【动态规划-6】96.不同的二叉搜索树
数据结构·c++·算法·leetcode·动态规划