Validate if a given string is numeric.

Some examples:
"0" => true
" 0.1 " => true
"abc" => false
"1 a" => false
"2e10" => true

Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.

bool isNumber(string s) {
int l = s.length(), i;
bool flag=, point[]={,}, num[]={,};
for(i=; s[i] == ' '; i++);
for(; i<l; i++)
{
if(s[i] == ' ')
break;
if(s[i] == '-' || s[i] == '+')
{
if(num[flag] == true || point[flag] == true)
return false;
}
else if(isdigit(s[i]))
num[flag] = true;
else if(s[i] == '.')
{
if(point[flag] || flag == true)
return false;
point[flag] = true;
}
else if(s[i] == 'e')
{
if(flag == )
return false;
if(num[] == false)
return false;
flag = ;
}
else
return false;
}
for(;i<l;i++)
{
if(s[i]!=' ')
return false;
}
if(!num[] && !num[])
return false;
if(flag && !num[])
return false;
return true;
}

测试用例:

"0e" -- false

". 1" -- false

"-1." -- true

".-4" -- false

"+.8" -- true

"6e6.5" -- false

65. Valid Number *HARD*的更多相关文章

  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

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

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

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

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

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

  5. Leetcode 65 Valid Number 字符串处理

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

  6. LeetCode 65 Valid Number

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

  7. 65. 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. 65. Valid Number 判断字符串是不是数字

    [抄题]: Validate if a given string is numeric. Some examples:"0" => true" 0.1 " ...

随机推荐

  1. 如何使用Unity制作虚拟导览(一)

    https://www.cnblogs.com/yangyisen/p/5108289.html Unity用来制作游戏已经是目前市场上的一个发展趋势,而且有越来越多的公司与开发者不断的加入,那么Un ...

  2. JavaScript 方法扩展

    一.String全部替换方法 String.prototype.replaceAll = function(s1, s2){ return this.replace(new RegExp(s1, &q ...

  3. Python入门之Python中的logging模块

    基本用法 下面的代码展示了logging最基本的用法. import logging import sys # 获取logger实例,如果参数为空则返回root logger logger = log ...

  4. 20145225唐振远《网络对抗》Exp4 恶意代码分析

    20145225唐振远<网络对抗>Exp4 恶意代码分析 基础问题回答 如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作有哪 ...

  5. Python3基础 list 索引查看元素

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. Python数据分析入门之pandas基础总结

    Pandas--"大熊猫"基础 Series Series: pandas的长枪(数据表中的一列或一行,观测向量,一维数组...) Series1 = pd.Series(np.r ...

  7. CSS3 动画的一些属性

    定义式 @keyframes 动画名称{ from{ } to{ } } 调用式 动画类似函数,只定义不调用是没效果的,所以要配合调用式使用. animation: 动画名称 动画时间 延时 时间曲线 ...

  8. java自学入门心得体会 从环境配置开始

    java —— 一种可以撰写跨平台应用软件的面向对象的程序设计语言. 很多教程里都要概述java语言的诞生发明.其实像图灵的”图灵机“和”图灵测试“一样,当初的java并不是这样. 是用来操控一些电冰 ...

  9. java web项目配置https访问

      转载: tomcat6配置:  1.单向认证,就是传输的数据加密过了,但是不会校验客户端的来源  2.双向认证,如果客户端浏览器没有导入客户端证书,是访问不了web系统的,找不到地址  如果只是加 ...

  10. NS3 实验脚本的编写步骤

    第一步:配置主机,安装模块 (1)创建N个节点: NodeContainer nodes; nodes.Creat(N); 比如我目前接触到的PointToPoint,N就是2 (2)利用拓扑助手He ...