【思路】该题题干不是很明确,只能根据用例来理解什么样的字符串才是符合题意的,本题关键在于几个标志位的设立,将字符串分为几个部分,代码如下:

 class Solution
{
public:
string trim(string s)
{
int i=;
while(s[i]==' ') i ++; //开头处为空格或者Tab,则跳过
s=s.substr(i);
i=s.size()-;
while(s[i]==' ') i --; //结尾处为空格或者Tab,则跳过
s=s.substr(,i+);
return s;
}
bool isNumber(string s)
{
s = trim(s); bool pointSeen = false;
bool eSeen = false;
bool partOne = false;
bool partTwo = false; for(int i = ; i < s.length(); i ++)
{
if(s[i] >= '' && s[i] <= '')
{
if(!eSeen)
partOne = true;
else
partTwo = true;
}
else if(s[i] == '.')
{
if(pointSeen || eSeen)
return false;
pointSeen = true;
}
else if(s[i] == 'e')
{
if(eSeen || !partOne)
return false;
eSeen = true;
}
else if(s[i] == '+' || s[i] == '-')
{
if(i != && s[i - ] != 'e')
return false;
}
else return false;
}
if(!partOne)
return false;
else if(eSeen && !partTwo)
return false;
else
return true;
}
};

[LeetCode] 65. Valid Number(多个标志位)的更多相关文章

  1. [leetcode]65. Valid Number 有效数值

    Validate if a given string can be interpreted as a decimal number. Some examples:"0" => ...

  2. leetCode 65.Valid Number (有效数字)

    Valid Number  Validate if a given string is numeric. Some examples: "0" => true " ...

  3. [LeetCode] 65. Valid Number 验证数字

    Validate if a given string can be interpreted as a decimal number. Some examples:"0" => ...

  4. LeetCode 65 Valid Number

    (在队友怂恿下写了LeetCode上的一个水题) 传送门 Validate if a given string is numeric. Some examples: "0" =&g ...

  5. Leetcode 65 Valid Number 字符串处理

    由于老是更新简单题,我已经醉了,所以今天直接上一道通过率最低的题. 题意:判断字符串是否是一个合法的数字 定义有符号的数字是(n),无符号的数字是(un),有符号的兼容无符号的 合法的数字只有下列几种 ...

  6. 【LeetCode】65. Valid Number

    Difficulty: Hard  More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...

  7. 【leetcode】Valid Number

    Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 ...

  8. 【一天一道LeetCode】#65. Valid Number

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Validat ...

  9. LeetCode - 136. Single Number - ( C++ ) - 解题报告 - 位运算思路 xor

    1.题目大意 Given an array of integers, every element appears twice except for one. Find that single one. ...

随机推荐

  1. 【原创】从 列表的重复 到 用sum展开二层嵌套列表将子元素合并

      转载请注明出处:https://www.cnblogs.com/oceanicstar/p/9517159.html     ★像R语言里头有rep函数可以让向量的值重复,在python里面可以直 ...

  2. 转:Spring Boot应用中的异常处理

    引自:https://www.cnblogs.com/yangfanexp/p/7616570.html 楼主前几天写了一篇“Java子线程中的异常处理(通用)”文章,介绍了在多线程环境下3种通用的异 ...

  3. Struts2的动态方法,及result跳转方式,全局结果以及默认的action的配置

    Action动态方法的调用 首先我们需要在struts.xml中去配置一个常量值如下 那么去哪找呢?找到Struts-core.jar并打开 method属性 <action name=&quo ...

  4. canvas实现半圆环形进度条

    html部分 <canvas id="canvas" width="150" height="150"> <p>抱歉 ...

  5. phpredis命令

    <?php //redis //检查一个扩展是否已经加载.大小写不敏感. if (!function_exists('redis')) { echo '不支持 redis'; return ; ...

  6. 关于Linux中mysql中文乱码

    1.SHOW VARIABLES LIKE 'character_set_%';查看编码集 2.编辑/etc/my.cnf文件 加入这个设置 default-character-set=utf8 (这 ...

  7. JAVA 基础编程练习题

    1 [程序 1 不死神兔] 题目:古典问题:有一对兔子,从出生后第 3 个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子对数为多少?程序分析: 兔子的规 ...

  8. HyperLedger Fabric 1.4 超级账本简介(5.2)

    超级账本(Hyperledger)是推动区块链跨行业应用的开源项目的总称,组织成员可以发起新的区块链项目,加入到超级账本项目(Hyperledger)中,但需要遵循Hyperledger的生命周期.  ...

  9. 集成运放输入电压范围指标参数Uicmax,Uidmax

    图中Uicmax最大共模输入电压:是运放能正常工作下的最大输入电压: Uidmax最大差模输入电压:是运放要损坏的最大输入电压

  10. 【MySql】mysql 慢日志查询工具之mysqldumpslow

      当使用--log-slow-queries[=file_name]选项启动时,mysqld写一个包含所有执行时间超过long_query_time秒的SQL语句的日志文件.获得初使表锁定的时间不算 ...