LeetCode 2269. 找到一个数字的 K 美丽值

解题思路

每次截取一段长度为k的字符串,然后不断地验证。

相关代码

复制代码
class Solution {
    public int divisorSubstrings(int num, int k) {
        String s = "" + num;
        int res=0;
        for(int i=0;i<=s.length()-k;i++){
            String temp = s.substring(i,i+k);
            int t = Integer.parseInt(temp);
            if(t==0) continue;
            if(num%t==0) res++;
        }
        return res;
    }
}
相关推荐
liulilittle4 小时前
认识麻将 —— 流水及对账
算法·游戏·lua·对账·流水·资金·玩法
郝学胜-神的一滴8 小时前
Effective Python 条款44:善用属性注解
开发语言·c++·vscode·python·算法·stl
青少儿编程课堂1 天前
第十八届蓝桥杯青少组图形化真题:校园分形雪花绘制解析(全国青少年信息素养大赛·电子学会图形化考级冲刺)
c++·python·算法·bfs·信息学竞赛
geovindu1 天前
python: KNeighborsClassifier K
开发语言·后端·python·算法
让我们一起加油好吗1 天前
【数据结构】线段树详解
数据结构·c++·算法·线段树·洛谷
凌冰_1 天前
数据结构 - 队列(五)
数据结构·算法·软件工程
让我们一起加油好吗1 天前
【数据结构】ST 表
数据结构·c++·算法·动态规划·洛谷·st表
让我们一起加油好吗1 天前
【算法刷题】LeetCode 力扣 Hot 100 刷题记录
数据结构·c++·算法·leetcode·面试·笔试
lisw052 天前
稀疏算法概述!
算法·机器人·无人机