当前位置:网站首页>The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
2022-07-07 08:09:00 【·Starry Sea】
subject
I'll give you a subscript from 0 Start length is n String num , It contains only numbers .
If for Every 0 <= i < n The subscript i , All meet the digit i stay num In the num[i] Time , So please go back to true , Otherwise return to false .
Example 1:
Input :num = “1210”
Output :true
explain :
num[0] = ‘1’ . Numbers 0 stay num There's a time when .
num[1] = ‘2’ . Numbers 1 stay num There were two times in .
num[2] = ‘1’ . Numbers 2 stay num There's a time when .
num[3] = ‘0’ . Numbers 3 stay num There are zero occurrences in .
“1210” Meet the requirements of the topic , So back true .
Example 2:
Input :num = “030”
Output :false
explain :
num[0] = ‘0’ . Numbers 0 There should be 0 Time , But in num There's a time when .
num[1] = ‘3’ . Numbers 1 There should be 3 Time , But in num There are zero occurrences in .
num[2] = ‘0’ . Numbers 2 stay num In the 0 Time .
Subscript 0 and 1 Have violated the title requirements , So back false .
Tips :
n == num.length
1 <= n <= 10
num Numbers only .
source : Power button (LeetCode)
Their thinking
According to the meaning of the topic , First, you need to find the frequency of each number in the string , Then traverse the entire string to check whether each element meets the conditions .
class Solution:
def digitCount(self, num: str) -> bool:
return all([str(Counter(num)[str(i)])==num[i] for i in range(len(num))])

边栏推荐
- Recursive method constructs binary tree from middle order and post order traversal sequence
- Linux server development, redis protocol and asynchronous mode
- 2022 welder (elementary) judgment questions and online simulation examination
- UnityHub破解&Unity破解
- CDC (change data capture technology), a powerful tool for real-time database synchronization
- Complete linear regression manually based on pytoch framework
- 这5个摸鱼神器太火了!程序员:知道了快删!
- Explore dry goods! Apifox construction ideas
- Recursive construction of maximum binary tree
- Recursive method to verify whether a tree is a binary search tree (BST)
猜你喜欢

数据库实时同步利器——CDC(变化数据捕获技术)

Qt学习28 主窗口中的工具栏

Implementation of replacement function of shell script

快解析内网穿透为文档加密行业保驾护航
![[step on the pit series] H5 cross domain problem of uniapp](/img/53/bd836a5c5545f51be929d8d123b961.png)
[step on the pit series] H5 cross domain problem of uniapp

Explore dry goods! Apifox construction ideas

Network learning (III) -- highly concurrent socket programming (epoll)

Who has docker to install MySQL locally?

JSON data flattening pd json_ normalize

uniapp 移动端强制更新功能
随机推荐
Cnopendata list data of Chinese colleges and Universities
互动送书-《Oracle DBA工作笔记》签名版
Hisense TV starts the developer mode
Relevant data of current limiting
Linux server development, MySQL cache strategy
Search for an element in a binary search tree (BST)
Quickly use Jacobo code coverage statistics
Fast parsing intranet penetration escorts the document encryption industry
青龙面板--整理能用脚本
【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
让Livelink初始Pose与动捕演员一致
Uniapp mobile terminal forced update function
Roulette chart 2 - writing of roulette chart code
Paddlepaddle 29 dynamically modify the network structure without model definition code (relu changes to prelu, conv2d changes to conv3d, 2D semantic segmentation model changes to 3D semantic segmentat
复杂网络建模(一)
Network learning (II) -- Introduction to socket
ZCMU--1396: 队列问题(2)
太真实了,原来自己一直没有富裕起来是有原因的
Find the mode in the binary search tree (use medium order traversal as an ordered array)
这5个摸鱼神器太火了!程序员:知道了快删!