当前位置:网站首页>Leetcode simple question: find the K beauty value of a number
Leetcode simple question: find the K beauty value of a number
2022-07-07 08:09:00 【·Starry Sea】
subject
An integer num Of k The beauty value is defined as num The following conditions are met in Substring number :
Substring length is k .
Substrings can be divided by num .
Give you an integer num and k , Please return num Of k Beauty is worth .
Be careful :
Allow Prefix 0 .
0 You can't divide any value .
One Substring Is a sequence of consecutive characters in a string .
Example 1:
Input :num = 240, k = 2
Output :2
explain : Here are num The inner length is k Substring of :
- “240” Medium “24” :24 aliquot 240 .
- “240” Medium “40” :40 aliquot 240 .
therefore ,k The beauty value is 2 .
Example 2:
Input :num = 430043, k = 2
Output :2
explain : Here are num The inner length is k Substring of :
- “430043” Medium “43” :43 aliquot 430043 .
- “430043” Medium “30” :30 Not divisible 430043 .
- “430043” Medium “00” :0 Not divisible 430043 .
- “430043” Medium “04” :4 Not divisible 430043 .
- “430043” Medium “43” :43 aliquot 430043 .
therefore ,k The beauty value is 2 .
Tips :
1 <= num <= 10^9
1 <= k <= num.length ( take num As a string )
source : Power button (LeetCode)
Their thinking
The simple way is , Will be given num It is transformed into a string and then traversed to determine whether each substring meets the conditions . Here we need to pay attention to dividing by 0 To deal with .
class Solution:
def divisorSubstrings(self, num: int, k: int) -> int:
n,count=str(num),0
for i in range(0,len(n)-k+1):
try:
if not num%int(n[i:i+k]):
count+=1
except:
pass
return count

边栏推荐
- Chip information website Yite Chuangxin
- Introduction à l'objet blob
- Custom class loader loads network class
- 快解析内网穿透为文档加密行业保驾护航
- 【无标题】
- 微信小程序基本组件使用介绍
- Find the mode in the binary search tree (use medium order traversal as an ordered array)
- 【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
- Visualization Document Feb 12 16:42
- ZCMU--1492: Problem D(C语言)
猜你喜欢

Quickly use Jacobo code coverage statistics

Cnopendata list data of Chinese colleges and Universities

Quick analysis of Intranet penetration helps the foreign trade management industry cope with a variety of challenges

【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)

互动送书-《Oracle DBA工作笔记》签名版

Network learning (I) -- basic model learning

船载雷达天线滑环的使用

The zblog plug-in supports the plug-in pushed by Baidu Sogou 360

Content of string

Li Kou interview question 04.01 Path between nodes
随机推荐
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
padavan手动安装php
快解析内网穿透助力外贸管理行业应对多种挑战
有 Docker 谁还在自己本地安装 Mysql ?
Leetcode 40: combined sum II
Téléchargement des données de conception des puces
Chip design data download
C language queue
Complex network modeling (II)
CDC (change data capture technology), a powerful tool for real-time database synchronization
快解析内网穿透为文档加密行业保驾护航
Real time monitoring of dog walking and rope pulling AI recognition helps smart city
Chip information website Yite Chuangxin
[quickstart to Digital IC Validation] 15. Basic syntax for SystemVerilog Learning 2 (operator, type conversion, loop, Task / Function... Including practical exercises)
青龙面板--整理能用脚本
探索干货篇!Apifox 建设思路
Merging binary trees by recursion
Padavan manually installs PHP
Find the mode in the binary search tree (use medium order traversal as an ordered array)
Linux server development, MySQL index principle and optimization