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

 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. SAP ABAP 日期,时间 相关函数

    获的两个日期之间的分钟数 data min TYPE i. CALL FUNCTION 'DELTA_TIME_DAY_HOUR' EXPORTING T1 = ' T2 = ' D1 = ' D2 ...

  2. 使用Cygwin在WIN系统下处理文本常用命令

    1.打开Cygwin,把需要处理的文本复制你的安装目录例如:D:\cygwin\home\Administrator 使用 ls命令查看根目录文件 2.现在我们就可以对1.txt文本进行操作, 3.我 ...

  3. Python接受流式输入

    随笔记录——Python接受终端入若干行输入 Python接受终端的若干行输入时,比较常用的input()不再好用. 1. 导入sys模块: import sys 2. for循环接受输入: for ...

  4. 使用SQLite删除Mac OS X 中launchpad里的快捷方式

    一般情况下,从App Store安装的应用程序,如果应用删除,那么launchpad里对应的图标会一起删除了. 而对于不是通过App Store安装的应用程序,删除应用程序,Launchpad中很可能 ...

  5. python3 练习题100例 (二十五)打印一个n层金字塔

    题目内容: 打印一个n层(1<n<20)金字塔,金字塔由“+”构成,塔尖是1个“+”,下一层是3个“+”,居中排列,以此类推. 注意:每一行的+号之后均无空格,最后一行没有空格. 输入格式 ...

  6. python学习之字符串常用方法和格式化字符串

    Python中的字符串同样适用标准的序列操作(索引,分片,乘法,成员判断,求长度,取最小值和最大值),但因为字符串是不可变的,因此字符串不支持分片赋值. s='http://www.baidu.com ...

  7. Python3 使用基本循环实现多级目录(思路)

    一.多级目录设计: 1. 通过循环的方式显示菜单和进入菜单 2. 设置标志位以提供回退上一层菜单 2. 设置标志位以提供退出程序 二.注意要点: 1. 菜单样式,层次关系不要弄混乱 2. 当输入错误时 ...

  8. 【Leetcode】413. Arithmetic Slices

    Description A sequence of number is called arithmetic if it consists of at least three elements and ...

  9. Hibernate-ORM:11.Hibernate中的关联查询

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客将讲述Hibernate中的关联查询,及其级联(cascade)操作,以及指定哪一方维护关联关系的(i ...

  10. 【PHP】进一法取整、四舍五入取整、忽略小数等的取整数方法大全

    PHP取整数函数常用的四种方法,下面收集了四个函数:经常用到取整的函数,今天小小的总结一下!其实很简单,就是几个函数而已--主要是:ceil,floor,round,intval PHP取整数函数常用 ...