当前位置:网站首页><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)))边栏推荐
- Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
- Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
- 百度数字人度晓晓在线回应网友喊话 应战上海高考英语作文
- 111.网络安全渗透测试—[权限提升篇9]—[Windows 2008 R2内核溢出提权]
- 让数字管理好库存
- 关于 Web Content-Security-Policy Directive 通过 meta 元素指定的一些测试用例
- Let digital manage inventory
- Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on SPI)
- Unity map auto match material tool map auto add to shader tool shader match map tool map made by substance painter auto match shader tool
- sink 消费 到 MySQL, 数据库表里面已经设置了 自增主键, flink 里面,如何 操作?
猜你喜欢

zero-shot, one-shot和few-shot
![[filter tracking] comparison between EKF and UKF based on MATLAB extended Kalman filter [including Matlab source code 1933]](/img/90/ef2400754cbf3771535196f6822992.jpg)
[filter tracking] comparison between EKF and UKF based on MATLAB extended Kalman filter [including Matlab source code 1933]

相机标定(1): 单目相机标定及张正友标定基本原理

Mastering the new functions of swiftui 4 weatherkit and swift charts

Complete collection of common error handling in MySQL installation

千人規模互聯網公司研發效能成功之路

<No. 9> 1805. 字符串中不同整数的数目 (简单)

Fleet tutorial 14 basic introduction to listtile (tutorial includes source code)

Rationaldmis2022 advanced programming macro program

SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
随机推荐
Unity 贴图自动匹配材质工具 贴图自动添加到材质球工具 材质球匹配贴图工具 Substance Painter制作的贴图自动匹配材质球工具
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]
Reasons for the failure of web side automation test
总结了200道经典的机器学习面试题(附参考答案)
Mastering the new functions of swiftui 4 weatherkit and swift charts
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
<No. 9> 1805. 字符串中不同整数的数目 (简单)
关于 Web Content-Security-Policy Directive 通过 meta 元素指定的一些测试用例
<No. 8> 1816. 截断句子 (简单)
问题:先后键入字符串和字符,结果发生冲突
MATLAB实现Huffman编码译码含GUI界面
30. Few-shot Named Entity Recognition with Self-describing Networks 阅读笔记
Unity map auto match material tool map auto add to shader tool shader match map tool map made by substance painter auto match shader tool
18 basic introduction to divider separator component of fleet tutorial (tutorial includes source code)
Automated testing framework
Ask about the version of flinkcdc2.2.0, which supports concurrency. Does this concurrency mean Multiple Parallelism? Now I find that mysqlcdc is full
[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]
MySQL安装常见报错处理大全
消息队列消息丢失和消息重复发送的处理策略
2022年在启牛开华泰的账户安全吗?