当前位置:网站首页><No. 9> 1805. Number of different integers in the string (simple)
<No. 9> 1805. Number of different integers in the string (simple)
2022-07-07 12:07:00 【Smoked Luoting purple Pavilion】
Catalog
Title source :
Title Description :
Give you a string word , The string consists of numbers and lowercase letters .
Please replace each character that is not a number with a space . for example ,"a123bc34d8ef34" Will become " 123 34 8 34" . Be careful , The remaining integers are ( Adjacent to each other with at least one space ):"123"、"34"、"8" and "34" .
Return to right word Formed after replacement Different The number of integers .
Only if two integers Without leading zeros The decimal representation of is different , I think these two integers are also different .
Python Realization :
class Solution(object):
def numDifferentIntegers(self, word):
"""
:type word: str
:rtype: int
"""
rm_word = re.findall("\d+", word) # "\d+": Match the Numbers , Can be continuous
rm_word2 = [a.lstrip('0') for a in rm_word] # Use lstrip() Function removes the leading 0
set_word = set(rm_word2) #set The assembly can automatically de weight
# list_word = list(set_word) This line can have , But there is no , It doesn't affect the result return len(list_word)
return len(set_word)
Python In one line :
class Solution(object):
def numDifferentIntegers(self, word):
"""
:type word: str
:rtype: int
"""
return len(set(x.lstrip('0') for x in re.findall("\d+", word)))
边栏推荐
- 108.网络安全渗透测试—[权限提升篇6]—[Windows内核溢出提权]
- Baidu digital person Du Xiaoxiao responded to netizens' shouts online to meet the Shanghai college entrance examination English composition
- Hi3516全系统类型烧录教程
- Let digital manage inventory
- 千人规模互联网公司研发效能成功之路
- Sonar:Cognitive Complexity认知复杂度
- Cmu15445 (fall 2019) project 2 - hash table details
- Camera calibration (1): basic principles of monocular camera calibration and Zhang Zhengyou calibration
- 110.网络安全渗透测试—[权限提升篇8]—[Windows SqlServer xp_cmdshell存储过程提权]
- [shortest circuit] acwing1128 Messenger: Floyd shortest circuit
猜你喜欢
zero-shot, one-shot和few-shot
Camera calibration (2): summary of monocular camera calibration
Completion report of communication software development and Application
In SQL, I want to set foreign keys. Why is this problem
Summed up 200 Classic machine learning interview questions (with reference answers)
In my limited software testing experience, a full-time summary of automation testing experience
一起探索云服务之云数据库
总结了200道经典的机器学习面试题(附参考答案)
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
18 basic introduction to divider separator component of fleet tutorial (tutorial includes source code)
随机推荐
[data clustering] realize data clustering analysis based on multiverse optimization DBSCAN with matlab code
Unity中SmoothStep介绍和应用: 溶解特效优化
Time bomb inside the software: 0-day log4shell is just the tip of the iceberg
Summed up 200 Classic machine learning interview questions (with reference answers)
[extraction des caractéristiques de texture] extraction des caractéristiques de texture de l'image LBP basée sur le mode binaire local de Matlab [y compris le code source de Matlab 1931]
Have you ever met flick Oracle CDC, read a table without update operation, and read it repeatedly every ten seconds
How to connect 5V serial port to 3.3V MCU serial port?
《看完就懂系列》天哪!搞懂节流与防抖竟简单如斯~
【最短路】ACwing 1127. 香甜的黄油(堆优化的dijsktra或spfa)
Unity 贴图自动匹配材质工具 贴图自动添加到材质球工具 材质球匹配贴图工具 Substance Painter制作的贴图自动匹配材质球工具
110. Network security penetration test - [privilege promotion 8] - [windows sqlserver xp_cmdshell stored procedure authorization]
本地navicat连接liunx下的oracle报权限不足
Some opinions and code implementation of Siou loss: more powerful learning for bounding box regression zhora gevorgyan
Software design - "high cohesion and low coupling"
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
Swiftui swift internal skill: five skills of using opaque type in swift
顶级域名有哪些?是如何分类的?
108.网络安全渗透测试—[权限提升篇6]—[Windows内核溢出提权]
数据库系统原理与应用教程(011)—— 关系数据库
NPC Jincang was invited to participate in the "aerospace 706" I have an appointment with aerospace computer "national Partner Conference