当前位置:网站首页>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))])

边栏推荐
- 2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
- 2022 welder (elementary) judgment questions and online simulation examination
- Binary tree and heap building in C language
- Who has docker to install MySQL locally?
- 【踩坑系列】uniapp之h5 跨域的问题
- Linux server development, detailed explanation of redis related commands and their principles
- Pytorch(六) —— 模型调优tricks
- Qt学习28 主窗口中的工具栏
- Zsh shell adds automatic completion and syntax highlighting
- Complex network modeling (III)
猜你喜欢

The charm of SQL optimization! From 30248s to 0.001s

Jmeter 的使用

Avatary的LiveDriver试用体验

uniapp 移动端强制更新功能
![[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)](/img/39/cac2b5492d374da393569e2ab467a4.png)
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)

Codeforce c.strange test and acwing

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

Myabtis_ Plus

Linux server development, SQL statements, indexes, views, stored procedures, triggers

Niu Mei's mathematical problem --- combinatorial number
随机推荐
【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
Record a stroke skin bone error of the skirt
Who has docker to install MySQL locally?
Topic not received? Try this
Leetcode 40: combined sum II
Leetcode 90: subset II
Introduction to basic components of wechat applet
Linux Installation MySQL 8.0 configuration
芯片 设计资料下载
C language communication travel card background system
Linux server development, MySQL stored procedures, functions and triggers
青龙面板--整理能用脚本
太真实了,原来自己一直没有富裕起来是有原因的
JSON data flattening pd json_ normalize
Network learning (III) -- highly concurrent socket programming (epoll)
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
It took "7" years to build the robot framework into a micro service
Es FAQ summary
Content of string