当前位置:网站首页><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)))
边栏推荐
- Superscalar processor design yaoyongbin Chapter 8 instruction emission excerpt
- Hi3516全系统类型烧录教程
- [filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]
- 本地navicat连接liunx下的oracle报权限不足
- 千人規模互聯網公司研發效能成功之路
- 112.网络安全渗透测试—[权限提升篇10]—[Windows 2003 LPK.DDL劫持提权&msf本地提权]
- [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]
- 2022年在启牛开华泰的账户安全吗?
- SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
- When sink is consumed in mysql, the self incrementing primary key has been set in the database table. How to operate in Flink?
猜你喜欢
<No. 8> 1816. 截断句子 (简单)
2022 年第八届“认证杯”中国高校风险管理与控制能力挑战赛
5V串口接3.3V单片机串口怎么搞?
【神经网络】卷积神经网络CNN【含Matlab源码 1932期】
[filter tracking] comparison between EKF and UKF based on MATLAB extended Kalman filter [including Matlab source code 1933]
The road to success in R & D efficiency of 1000 person Internet companies
核舟记(一):当“男妈妈”走进现实,生物科技革命能解放女性吗?
30. Few-shot Named Entity Recognition with Self-describing Networks 阅读笔记
Explore cloud database of cloud services together
消息队列消息丢失和消息重复发送的处理策略
随机推荐
PowerShell cs-utf-16le code goes online
Upgrade from a tool to a solution, and the new site with praise points to new value
Internet Protocol
NPC Jincang was invited to participate in the "aerospace 706" I have an appointment with aerospace computer "national Partner Conference
Camera calibration (2): summary of monocular camera calibration
110. Network security penetration test - [privilege promotion 8] - [windows sqlserver xp_cmdshell stored procedure authorization]
Introduction to three methods of anti red domain name generation
Is it safe to open Huatai's account in kainiu in 2022?
[shortest circuit] acwing 1127 Sweet butter (heap optimized dijsktra or SPFA)
Suggestions on one-stop development of testing life
Tsinghua Yaoban programmers, online marriage was scolded?
Sonar:cognitive complexity
VIM command mode and input mode switching
核舟记(一):当“男妈妈”走进现实,生物科技革命能解放女性吗?
@What happens if bean and @component are used on the same class?
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
Xiaohongshu microservice framework and governance and other cloud native business architecture evolution cases
Zero shot, one shot and few shot
超标量处理器设计 姚永斌 第8章 指令发射 摘录
顶级域名有哪些?是如何分类的?