当前位置:网站首页>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();
}
};
边栏推荐
- 数学知识——高斯消元(初等行变换解方程组)代码实现
- Unbalance balance (dynamic programming, DP)
- About image reading and processing, etc
- Modulenotfounderror: no module named 'PIL' solution
- Hudi vs Delta vs Iceberg
- Leetcode 30. 串联所有单词的子串
- Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
- [translation] supply chain security project in toto moved to CNCF incubator
- IC设计流程中需要使用到的文件
- A popular explanation will help you get started
猜你喜欢

Low CPU load and high loadavg processing method
![Looting iii[post sequence traversal and backtracking + dynamic planning]](/img/9b/e9eeed138e46afdeed340bf2629ee1.png)
Looting iii[post sequence traversal and backtracking + dynamic planning]

ZABBIX proxy server and ZABBIX SNMP monitoring

全套教学资料,阿里快手拼多多等7家大厂Android面试真题
![Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting](/img/dd/c3f4a9c38b156e3a9b9adfd6253773.gif)
Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting

利用 clip-path 绘制不规则的图形

手把手教你学会js的原型与原型链,猴子都能看懂的教程

接雨水问题解析

冒烟测试怎么做

Blue Bridge Cup microbial proliferation C language
随机推荐
How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
谷粒商城--分布式高级篇P129~P339(完结)
Druid 数据库连接池 详解
How to type multiple spaces when editing CSDN articles
企业精益管理体系介绍
关于图像的读取及处理等
swagger2报错Illegal DefaultValue null for parameter type integer
JDBC详解
Analysis of rainwater connection
[translation] a GPU approach to particle physics
蓝桥杯 微生物增殖 C语言
How to customize animation avatars? These six free online cartoon avatar generators are exciting at a glance!
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
C # - realize serialization with Marshall class
主从搭建报错:The slave I/O thread stops because master and slave have equal MySQL serv
Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
In 50W, what have I done right?
腾讯Android面试必问,10年Android开发经验
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
Spark foundation -scala