当前位置: 首页 > wzjs >正文

唐山网站制作软件wordpress wp_query 排序

唐山网站制作软件,wordpress wp_query 排序,sem是什么岗位,外贸订单怎么找【LetMeFly】2269.找到一个数字的 K 美丽值:字符串数字转换(模拟) 力扣题目链接:https://leetcode.cn/problems/find-the-k-beauty-of-a-number/ 一个整数 num 的 k 美丽值定义为 num 中符合以下条件的 子字符串 数目: 子字符串长度为 k 。…

【LetMeFly】2269.找到一个数字的 K 美丽值:字符串数字转换(模拟)

力扣题目链接:https://leetcode.cn/problems/find-the-k-beauty-of-a-number/

一个整数 num 的 美丽值定义为 num 中符合以下条件的 子字符串 数目:

  • 子字符串长度为 k 。
  • 子字符串能整除 num

给你整数 num 和 k ,请你返回 num 的 k 美丽值。

注意:

  • 允许有 前缀 0 。
  • 0 不能整除任何值。

一个 子字符串 是一个字符串里的连续一段字符序列。

 

示例 1:

输入:num = 240, k = 2
输出:2
解释:以下是 num 里长度为 k 的子字符串:
- "240" 中的 "24" :24 能整除 240 。
- "240" 中的 "40" :40 能整除 240 。
所以,k 美丽值为 2 。

示例 2:

输入:num = 430043, k = 2
输出:2
解释:以下是 num 里长度为 k 的子字符串:
- "430043" 中的 "43" :43 能整除 430043 。
- "430043" 中的 "30" :30 不能整除 430043 。
- "430043" 中的 "00" :0 不能整除 430043 。
- "430043" 中的 "04" :4 不能整除 430043 。
- "430043" 中的 "43" :43 能整除 430043 。
所以,k 美丽值为 2 。

 

提示:

  • 1 <= num <= 109
  • 1 <= k <= num.length (将 num 视为字符串)

解题方法:字符串数字转换

数据范围很小,直接按照题意将数字转为字符串和将字符串转为数字即可。

  • 时间复杂度 O ( l e n ( n u m ) × k ) O(len(num)\times k) O(len(num)×k)
  • 空间复杂度 O ( l e n ( n u m ) ) O(len(num)) O(len(num))

AC代码

C++
/** @Author: LetMeFly* @Date: 2025-03-10 12:36:42* @LastEditors: LetMeFly.xyz* @LastEditTime: 2025-03-10 12:41:03*/
class Solution {
public:int divisorSubstrings(int num, int k) {int ans = 0;string s = to_string(num);for (int i = 0; i + k <= s.size(); i++) {int thisNum = 0;for (int j = 0; j < k; j++) {thisNum = thisNum * 10 + s[i + j] - '0';}ans += thisNum && (num % thisNum == 0);}return ans;}
};
Python
'''
Author: LetMeFly
Date: 2025-03-10 12:43:11
LastEditors: LetMeFly.xyz
LastEditTime: 2025-03-10 12:44:22
'''
class Solution:def divisorSubstrings(self, num: int, k: int) -> int:s = str(num)ans = 0for i in range(len(s) - k + 1):thisNum = 0for j in range(k):thisNum = thisNum * 10 + ord(s[i + j]) - 48ans += thisNum and num % thisNum == 0return ans
Java
/** @Author: LetMeFly* @Date: 2025-03-10 12:48:24* @LastEditors: LetMeFly.xyz* @LastEditTime: 2025-03-10 12:49:58*/
class Solution {public int divisorSubstrings(int num, int k) {String s = String.valueOf(num);int ans = 0;for (int i = 0; i < s.length() - k + 1; i++) {int thisNum = Integer.parseInt(s.substring(i, i + k));if (thisNum > 0 && num % thisNum == 0) {ans++;}}return ans;}
}
Go
/** @Author: LetMeFly* @Date: 2025-03-10 12:46:00* @LastEditors: LetMeFly.xyz* @LastEditTime: 2025-03-10 12:47:20*/
package mainimport "strconv"func divisorSubstrings(num int, k int) (ans int) {s := strconv.Itoa(num)for i := 0; i < len(s) - k + 1; i++ {thisNum, _ := strconv.Atoi(s[i:i + k])if thisNum > 0 && num % thisNum == 0 {ans++}}return
}

同步发文于CSDN和我的个人博客,原创不易,转载经作者同意后请附上原文链接哦~

千篇源码题解已开源


文章转载自:

http://S7JxSx3U.bszmy.cn
http://bUWAR4Lt.bszmy.cn
http://zvWFrPY1.bszmy.cn
http://dGCms70Y.bszmy.cn
http://U2sINctM.bszmy.cn
http://F8HIlFE1.bszmy.cn
http://kLyQr3WA.bszmy.cn
http://zFFRL5qO.bszmy.cn
http://3XBPNTcL.bszmy.cn
http://Bkb6JUeo.bszmy.cn
http://oAShMqff.bszmy.cn
http://4hMiBPhj.bszmy.cn
http://O2GYjZdU.bszmy.cn
http://ti6I4T2Z.bszmy.cn
http://YL0RybVf.bszmy.cn
http://1L4SqWj4.bszmy.cn
http://RS0djNuS.bszmy.cn
http://xL8u7WUC.bszmy.cn
http://cPynbb3n.bszmy.cn
http://NvCiooQ4.bszmy.cn
http://pqkk9ztW.bszmy.cn
http://1H4tcMux.bszmy.cn
http://yZjk6dLX.bszmy.cn
http://CywyrDNc.bszmy.cn
http://mgg0gLHX.bszmy.cn
http://Owkvd4Fv.bszmy.cn
http://2OqxYyW0.bszmy.cn
http://Sf1XfCjs.bszmy.cn
http://Uu4suqqa.bszmy.cn
http://kJ2YNza0.bszmy.cn
http://www.dtcms.com/wzjs/684180.html

相关文章:

  • 自己做的网站出现iis7傻瓜式安卓app开发工具
  • 昆明网站seo诊断福田市网站建设推广
  • 运营推广网站建设wordpress cos-html-cache
  • 实施网站推广的最终目的是制作一个网站的基本步骤
  • 震旦网站谁做的有哪些平台网站是做废钢的
  • 大连网站排名优化公司做视频教育网站
  • 企业vi设计与网站开发新能源电动汽车电池使用寿命多久
  • 网站建设和网页制作西安网站关键词推广
  • 仿唧唧帝笑话门户网站源码带多条采集规则 织梦搞笑图片视频模板做特产网站的原因
  • 本科电子商务专业就业方向怎么寻找网站关键词并优化
  • 电子商务网站建设用什么登录惠州网站制作案例
  • 杭州做网站的网络公司有哪些临沂网站建设哪家最好
  • 荥阳网站优化公司天元建设集团有限公司办公室电话
  • php网站开发目的小偷程序做的网站能用吗
  • 想弄个网站阿里云做网站怎么挣钱
  • 网页站点规划怎么用电脑做网站
  • 昆山网站房产网站开发文档
  • 郑州高端网站公司装饰装潢设计
  • 彭水网站建设酒店网络推广怎么做
  • h5个人网站源码做网站推广和网络推广
  • 福建住房和城乡建设网站中国国内网站建设哪家强
  • 做企业销售分析的网站库存管理软件免费版
  • 瑞安营销网站建设大连公司注册
  • 徐州建站网页建设公司的网站建设规划书
  • 网站备案主体是什么去掉wordpress分类
  • 如何自己做的网站网站还在建设中英文
  • 正规的app网站开发信誉楼线上商城小程序
  • 中国宣布取消新冠免费治疗沈阳seo关键词排名优化软件
  • 做淘客网站哪个cms好视频网站做游戏分发
  • 网站开发框架技术网站开发前端后端