当前位置:网站首页>1805. Number of different integers in the string
1805. Number of different integers in the string
2022-07-06 19:37:00 【Drag is me】
leetcode Force button to brush questions and punch in
subject :1805. The number of different integers in a string
describe : 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 .
Their thinking
1、 Although the title requires that the number of integers be returned , But there is no need to convert strings into integers , Only need statistics to be significant figures ( Don't to 0 The whole number at the beginning ) The number of strings is good ;
2、 Number of different integers , Then set duplicate removal .
Source code ##
class Solution {
public:
int numDifferentIntegers(string word) {
set<string>set;
int flag = 0;
string temp = "";
for (int i = 0; i < word.size(); ++i) {
if (word[i] >= '0' && word[i] <= '9') {
flag = 1;
if (temp == "" && word[i] == '0') continue;
temp += word[i];
} else {
if (flag) {
flag = 0;
set.insert(temp);
temp = "";
}
}
}
if (flag) {
set.insert(temp);
}
return set.size();
}
};
边栏推荐
- MySQL information schema learning (II) -- InnoDB table
- 凤凰架构3——事务处理
- Hudi vs Delta vs Iceberg
- 快速幂模板求逆元,逆元的作用以及例题【第20届上海大学程序设计联赛夏季赛】排列计数
- DaGAN论文解读
- An error occurs when installing MySQL: could not create or access the registry key needed for the
- C language daily practice - day 22: Zero foundation learning dynamic planning
- 【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
- Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
- PMP practice once a day | don't get lost in the exam -7.6
猜你喜欢
Solution of intelligent management platform for suppliers in hardware and electromechanical industry: optimize supply chain management and drive enterprise performance growth
How to do smoke test
学习探索-使用伪元素清除浮动元素造成的高度坍塌
Computer network: sorting out common network interview questions (I)
Blue Bridge Cup microbial proliferation C language
Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
Documents to be used in IC design process
通俗的讲解,带你入门协程
安装Mysql报错:Could not create or access the registry key needed for the...
随机推荐
快速幂模板求逆元,逆元的作用以及例题【第20届上海大学程序设计联赛夏季赛】排列计数
Leetcode topic [array] - 119 Yang Hui triangle II
short i =1; i=i+1与short i=1; i+=1的区别
深入分析,Android面试真题解析火爆全网
Interpretation of Dagan paper
利用 clip-path 绘制不规则的图形
Use of map (the data of the list is assigned to the form, and the JSON comma separated display assignment)
ZABBIX proxy server and ZABBIX SNMP monitoring
凤凰架构3——事务处理
The slave i/o thread stops because master and slave have equal MySQL serv
关于图像的读取及处理等
Analysis of rainwater connection
Dark horse -- redis
全套教学资料,阿里快手拼多多等7家大厂Android面试真题
Hudi vs Delta vs Iceberg
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
凤凰架构2——访问远程服务
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
CPU负载很低,loadavg很高处理方法
Intelligent supply chain management system solution for hardware and electromechanical industry: digital intelligent supply chain "creates new blood" for traditional industries