当前位置:网站首页><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)))
边栏推荐
- 让数字管理好库存
- 112. Network security penetration test - [privilege promotion article 10] - [Windows 2003 lpk.ddl hijacking rights lifting & MSF local rights lifting]
- 盘点JS判断空对象的几大方法
- 相机标定(1): 单目相机标定及张正友标定基本原理
- 110. Network security penetration test - [privilege promotion 8] - [windows sqlserver xp_cmdshell stored procedure authorization]
- Complete collection of common error handling in MySQL installation
- Some opinions and code implementation of Siou loss: more powerful learning for bounding box regression zhora gevorgyan
- Internet Protocol
- Introduction and application of smoothstep in unity: optimization of dissolution effect
- Hi3516全系统类型烧录教程
猜你喜欢
人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》
2022 8th "certification Cup" China University risk management and control ability challenge
Sonar:cognitive complexity
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
【全栈计划 —— 编程语言之C#】基础入门知识一文懂
总结了200道经典的机器学习面试题(附参考答案)
【滤波跟踪】基于matlab捷联惯导仿真【含Matlab源码 1935期】
【滤波跟踪】捷联惯导纯惯导解算matlab实现
超标量处理器设计 姚永斌 第9章 指令执行 摘录
盘点JS判断空对象的几大方法
随机推荐
关于 Web Content-Security-Policy Directive 通过 meta 元素指定的一些测试用例
Present pod information to the container through environment variables
Flet教程之 15 GridView 基础入门(教程含源码)
Common locking table processing methods in Oracle
Tsinghua Yaoban programmers, online marriage was scolded?
即刻报名|飞桨黑客马拉松第三期盛夏登场,等你挑战
Sonar:cognitive complexity
数据库系统原理与应用教程(011)—— 关系数据库
Software design - "high cohesion and low coupling"
Use references
Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
Sonar:Cognitive Complexity认知复杂度
Internet Protocol
Swiftui swift internal skill how to perform automatic trigonometric function calculation in swift
What is high cohesion and low coupling?
人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》
Rationaldmis2022 advanced programming macro program
Superscalar processor design yaoyongbin Chapter 9 instruction execution excerpt
【滤波跟踪】捷联惯导纯惯导解算matlab实现
【紋理特征提取】基於matlab局部二值模式LBP圖像紋理特征提取【含Matlab源碼 1931期】