当前位置:网站首页><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)))
边栏推荐
- What are the top-level domain names? How is it classified?
- 111.网络安全渗透测试—[权限提升篇9]—[Windows 2008 R2内核溢出提权]
- Camera calibration (2): summary of monocular camera calibration
- About how to install mysql8.0 on the cloud server (Tencent cloud here) and enable local remote connection
- Solve the problem that vscode can only open two tabs
- Introduction to three methods of anti red domain name generation
- wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
- Automated testing framework
- 相机标定(2): 单目相机标定总结
- wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
猜你喜欢
18 basic introduction to divider separator component of fleet tutorial (tutorial includes source code)
La voie du succès de la R & D des entreprises Internet à l’échelle des milliers de personnes
Summed up 200 Classic machine learning interview questions (with reference answers)
Hi3516全系统类型烧录教程
Improve application security through nonce field of play integrity API
111.网络安全渗透测试—[权限提升篇9]—[Windows 2008 R2内核溢出提权]
Superscalar processor design yaoyongbin Chapter 8 instruction emission excerpt
超标量处理器设计 姚永斌 第10章 指令提交 摘录
【数据聚类】基于多元宇宙优化DBSCAN实现数据聚类分析附matlab代码
idea 2021中文乱码
随机推荐
关于 Web Content-Security-Policy Directive 通过 meta 元素指定的一些测试用例
zero-shot, one-shot和few-shot
What are the technical differences in source code anti disclosure
问题:先后键入字符串和字符,结果发生冲突
千人规模互联网公司研发效能成功之路
软件内部的定时炸弹:0-Day Log4Shell只是冰山一角
SwiftUI Swift 内功之 Swift 中使用不透明类型的 5 个技巧
idea 2021中文乱码
Ask about the version of flinkcdc2.2.0, which supports concurrency. Does this concurrency mean Multiple Parallelism? Now I find that mysqlcdc is full
30. Few-shot Named Entity Recognition with Self-describing Networks 阅读笔记
[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]
Suggestions on one-stop development of testing life
[full stack plan - programming language C] basic introductory knowledge
In my limited software testing experience, a full-time summary of automation testing experience
Rationaldmis2022 array workpiece measurement
Fleet tutorial 15 introduction to GridView Basics (tutorial includes source code)
UP Meta—Web3.0世界创新型元宇宙金融协议
Completion report of communication software development and Application
Flet教程之 15 GridView 基础入门(教程含源码)
Summed up 200 Classic machine learning interview questions (with reference answers)