当前位置:网站首页>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();
}
};
边栏推荐
- 面试突击63:MySQL 中如何去重?
- [translation] supply chain security project in toto moved to CNCF incubator
- Tensorflow2.0 自定义训练的方式求解函数系数
- [translation] Digital insider. Selection process of kubecon + cloudnativecon in Europe in 2022
- 从sparse.csc.csr_matrix生成邻接矩阵
- 时钟轮在 RPC 中的应用
- Analysis of rainwater connection
- Mysql Information Schema 學習(一)--通用錶
- 深入分析,Android面试真题解析火爆全网
- 【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
猜你喜欢
How to access localhost:8000 by mobile phone
凤凰架构3——事务处理
全套教学资料,阿里快手拼多多等7家大厂Android面试真题
Help improve the professional quality of safety talents | the first stage of personal ability certification and assessment has been successfully completed!
Mysql Information Schema 学习(一)--通用表
安装Mysql报错:Could not create or access the registry key needed for the...
Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry
零基础入门PolarDB-X:搭建高可用系统并联动数据大屏
Computer network: sorting out common network interview questions (I)
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
随机推荐
在解决了 2961 个用户反馈后,我做出了这样的改变...
Blue Bridge Cup microbial proliferation C language
时钟轮在 RPC 中的应用
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
350. 两个数组的交集 II
Tensorflow2.0 self defined training method to solve function coefficients
Translation D28 (with AC code POJ 26:the nearest number)
Unbalance balance (dynamic programming, DP)
Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease
Synchronous development of business and application: strategic suggestions for application modernization
Help improve the professional quality of safety talents | the first stage of personal ability certification and assessment has been successfully completed!
MRO industrial products enterprise procurement system: how to refine procurement collaborative management? Industrial products enterprises that want to upgrade must see!
Elastic search indexes are often deleted [closed] - elastic search indexes gets deleted frequently [closed]
How to access localhost:8000 by mobile phone
Phoenix Architecture 2 - accessing remote services
史上超级详细,想找工作的你还不看这份资料就晚了
蓝桥杯 微生物增殖 C语言
LeetCode-1279. 红绿灯路口
思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理
LeetCode_ Double pointer_ Medium_ 61. rotating linked list