当前位置:网站首页>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;
}
};边栏推荐
- [kotlin] Introduction to higher-order functions
- Stegano in the world of attack and defense
- 【C语言补充】判断明天是哪一天(明天的日期)
- Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores
- 模板引擎Velocity 基础
- [Supplément linguistique c] déterminer quel jour est demain (date de demain)
- Template Engine Velocity Foundation
- 机器学习11-聚类,孤立点判别
- Shenyu gateway development: enable and run locally
- 挖财学堂班主任给的证券账户安全吗?能开户吗?
猜你喜欢
随机推荐
Babbitt | yuan universe daily must read: Naixue coin, Yuan universe paradise, virtual stock game Do you understand Naixue's tea's marketing campaign of "operation pull full"
Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
Redis Distributed Lock
SQL注入漏洞(Mysql与MSSQL特性)
Sword finger offer II 015 All modifiers in the string
Redis6.0 新功能
libcurl下载文件的代码示例
How wild are hackers' ways of making money? CTF reverse entry Guide
Are you still using charged document management tools? I have a better choice! Completely free
sql刷题1050. 合作过至少三次的演员和导演
【splishsplash】关于如何在GUI和json上接收/显示用户参数、MVC模式和GenParam
中国氮化硅陶瓷基板行业研究与投资前景报告(2022版)
在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
SQL question brushing 584 Looking for user references
Redis 分布式鎖
(12) About time-consuming printing
sql刷题584. 寻找用户推荐人
Redis6.0 new features
Jojogan practice








