当前位置:网站首页>Sword finger offer 20 String representing numeric value
Sword finger offer 20 String representing numeric value
2022-07-01 17:02:00 【anieoo】
Original link : The finger of the sword Offer 20. String representing the value
solution:
class Solution {
public:
bool isNumber(string s) {
// String empty direct return
if(s.empty()) return false;
int i = 0,j = s.size() - 1;
while(s[i] == ' ' && i < j) i++;
while(s[j] == ' ' && i < j) j--;
s = s.substr(i, j - i + 1); // Remove the head and tail 0
bool numFlag = false;
bool dotFlag = false;
bool eFlag = false;
for(int i = 0;i < s.size();i++) {
if(s[i] >= '0' && s[i] <= '9') { // It's a number , Mark numFlag
numFlag = true;
} else if(s[i] == '.' && !dotFlag && !eFlag) { // Judged as . There is no need before . and e, Mark dotFlag
dotFlag = true;
} else if((s[i] == 'e' || s[i] == 'E') && !eFlag && numFlag) { // determine e or E Appearance , Need not appear before e And numbers have appeared
eFlag = true;
numFlag = false;
} else if((s[i] == '+' || s[i] == '-') && (i == 0 || s[i - 1] == 'e' || s[i - 1] == 'E')) { // determine + or - Appearance , Can only appear in the first place or e Behind
} else return false;
}
return numFlag;
}
};边栏推荐
- 可迭代对象与迭代器、生成器的区别与联系
- 阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
- [pyg] document summary and project experience (continuously updated
- How to restore the system of Sony laptop
- (1) CNN network structure
- Object. fromEntries()
- FRP intranet penetration, reverse proxy
- Flux d'entrées / sorties et opérations de fichiers en langage C
- Are you still using charged document management tools? I have a better choice! Completely free
- sql刷题1050. 合作过至少三次的演员和导演
猜你喜欢

Computed property “xxx“ was assigned to but it has no setter.

Rhcsa Road

如何写出好代码 — 防御式编程指南

SQL question brushing 586 Customers with the most orders

Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!

C language input / output stream and file operation

重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标
![[live broadcast appointment] database obcp certification comprehensive upgrade open class](/img/50/83a533f4e8a60f90e03b991385c08d.jpg)
[live broadcast appointment] database obcp certification comprehensive upgrade open class

How to restore the system with one click on Lenovo laptop

sql刷题586. 订单最多的客户
随机推荐
[mathematical modeling] [matlab] implementation of two-dimensional rectangular packing code
中国茂金属聚乙烯(mPE)行业研究报告(2022版)
China nylon 11 industry research and future forecast report (2022 Edition)
Sword finger offer II 015 All modifiers in the string
想做软件测试的女孩子看这里
Redis 分布式鎖
Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
mysql -- explain性能优化
SystemVerilog-结构体(二)
How to use F1 to F12 correctly on laptop keyboard
C语言输入/输出流和文件操作
Redis 分布式锁
Iommu/smmuv3 code analysis (10) page table operation
Shenyu gateway development: enable and run locally
Research and investment strategy report of China's sodium sulfate industry (2022 Edition)
libcurl下载文件的代码示例
Girls who want to do software testing look here
String的trim()和substring()详解
模板引擎Velocity 基礎
[wrung Ba wrung Ba is 20] [essay] why should I learn this in college?