当前位置:网站首页>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();
}
};
边栏推荐
- [translation] a GPU approach to particle physics
- 蓝桥杯 微生物增殖 C语言
- Zero foundation entry polardb-x: build a highly available system and link the big data screen
- CCNP Part 11 BGP (III) (essence)
- C # - realize serialization with Marshall class
- A popular explanation will help you get started
- 【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
- 黑马--Redis篇
- About image reading and processing, etc
- 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
猜你喜欢
IC设计流程中需要使用到的文件
蓝桥杯 微生物增殖 C语言
Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
学习探索-无缝轮播图
Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!
spark基础-scala
Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
Hudi vs Delta vs Iceberg
MySQL information schema learning (I) -- general table
手把手教你学会js的原型与原型链,猴子都能看懂的教程
随机推荐
深度剖析原理,看完这一篇就够了
[pytorch] yolov5 train your own data set
Swagger2 reports an error illegal DefaultValue null for parameter type integer
蓝桥杯 微生物增殖 C语言
IC设计流程中需要使用到的文件
1805. 字符串中不同整数的数目
LeetCode_双指针_中等_61. 旋转链表
Druid database connection pool details
PMP每日一练 | 考试不迷路-7.6
学习探索-使用伪元素清除浮动元素造成的高度坍塌
学习探索-无缝轮播图
Use of map (the data of the list is assigned to the form, and the JSON comma separated display assignment)
Spark foundation -scala
Learning and Exploration - Seamless rotation map
凤凰架构2——访问远程服务
Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
C # use Marshall to manually create unmanaged memory in the heap and use
黑馬--Redis篇
RT-Thread 组件 FinSH 使用时遇到的问题
受益匪浅,安卓面试问题