当前位置:网站首页>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();
}
};
边栏推荐
猜你喜欢
中缀表达式转后缀表达式详细思路及代码实现
谷粒商城--分布式高级篇P129~P339(完结)
Hudi vs Delta vs Iceberg
在解决了 2961 个用户反馈后,我做出了这样的改变...
Hudi vs Delta vs Iceberg
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
Blue Bridge Cup microbial proliferation C language
安装Mysql报错:Could not create or access the registry key needed for the...
时钟轮在 RPC 中的应用
随机推荐
Yyds dry goods inventory leetcode question set 751 - 760
Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
反射及在运用过程中出现的IllegalAccessException异常
In 50W, what have I done right?
Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!
MySQL information Schema Learning (i) - - General table
short i =1; i=i+1与short i=1; i+=1的区别
[translation] supply chain security project in toto moved to CNCF incubator
Spark foundation -scala
学习探索-函数防抖
Excel 中VBA脚本的简单应用
在解决了 2961 个用户反馈后,我做出了这样的改变...
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
An error occurs when installing MySQL: could not create or access the registry key needed for the
GCC【7】- 编译检查的是函数的声明,链接检查的是函数的定义bug
Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe
Documents to be used in IC design process
10 schemes to ensure interface data security
Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
三面蚂蚁金服成功拿到offer,Android开发社招面试经验