当前位置:网站首页><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)))
边栏推荐
- 111.网络安全渗透测试—[权限提升篇9]—[Windows 2008 R2内核溢出提权]
- MATLAB實現Huffman編碼譯碼含GUI界面
- Sonar:Cognitive Complexity认知复杂度
- Matlab implementation of Huffman coding and decoding with GUI interface
- 软件内部的定时炸弹:0-Day Log4Shell只是冰山一角
- 消息队列消息丢失和消息重复发送的处理策略
- Solve the problem that vscode can only open two tabs
- wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
- VIM command mode and input mode switching
- Nuclear boat (I): when "male mothers" come into reality, can the biotechnology revolution liberate women?
猜你喜欢
Introduction and application of smoothstep in unity: optimization of dissolution effect
Completion report of communication software development and Application
111.网络安全渗透测试—[权限提升篇9]—[Windows 2008 R2内核溢出提权]
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
[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]
人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》
千人規模互聯網公司研發效能成功之路
30. Few-shot Named Entity Recognition with Self-describing Networks 阅读笔记
相机标定(2): 单目相机标定总结
Tsinghua Yaoban programmers, online marriage was scolded?
随机推荐
Completion report of communication software development and Application
《通信软件开发与应用》课程结业报告
111.网络安全渗透测试—[权限提升篇9]—[Windows 2008 R2内核溢出提权]
Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on SPI)
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
Review and arrangement of HCIA
源代码防泄密中的技术区别再哪里
110.网络安全渗透测试—[权限提升篇8]—[Windows SqlServer xp_cmdshell存储过程提权]
SwiftUI Swift 内功之 Swift 中使用不透明类型的 5 个技巧
Visual Studio 2019 (LocalDB)\MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782版及更低版本
问下flinkcdc2.2.0的版本,支持并发,这个并发是指多并行度吗,现在发现,mysqlcdc全
@Bean与@Component用在同一个类上,会怎么样?
Basic introduction to the 16 tabs tab control in the fleet tutorial (the tutorial includes source code)
从工具升级为解决方案,有赞的新站位指向新价值
Complete collection of common error handling in MySQL installation
STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于SPI)
千人规模互联网公司研发效能成功之路
顶级域名有哪些?是如何分类的?
Flet教程之 14 ListTile 基础入门(教程含源码)
人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》