class Solution {
public:
bool isNumber(string s) {
if(s == " ") return false;
int i = ;
int j = s.size()-;
while(s[i] == ' ') ++i;
while(s[j] == ' ') --j;
++j; if(s[i] == '+' || s[i] == '-') ++i; if(i == j) return false; bool numberic = true;
bool flag = false; int k = scanDigits(s,i,j);
if (k != i)
{
flag = true;
} i = k; if(i < j){
if(s[i] == '.'){
++i;
if(i == j && !flag) return false;
else
{
k = scanDigits(s,i,j);
if (k != i)
{
flag = true;
}
i = k;
if(i < j && (s[i] == 'E'||s[i] == 'e'))
numberic = flag && isExponential(s, (++i),j);
} }
else if(i < j && (s[i] == 'E'||s[i] == 'e'))
numberic = flag && isExponential(s, ++i,j);
else numberic = false;
} return numberic && i == j; } int scanDigits(string str, int i,int j){
while(i < j && str[i] >= ''&& str[i] <= '') ++i;
return i;
} bool isExponential(string str, int& i, int j){
if(i == j) return false;
if(str[i] == '+' || str[i] == '-') ++i; if(i == j) return false;
i = scanDigits(str,i,j);
return i==j?true:false;
}
};

测试了好多次才过了 太不容易 所以贴个上来做下纪念

".9e1","+.1"  "1."都正确

Valid Number--LeetCode的更多相关文章

  1. Valid Number leetcode java

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

  2. 【LeetCode】65. Valid Number

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

  3. 【leetcode】Valid Number

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

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

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

  5. LeetCode: Valid Number 解题报告

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

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

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

  7. [LintCode] Valid Number 验证数字

    Validate if a given string is numeric. Have you met this question in a real interview? Yes Example & ...

  8. [Swift]LeetCode65. 有效数字 | Valid Number

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

  9. Valid Number @python

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

  10. 配置域名服务器报错named[822]: dns_rdata_fromtext /etc/bind/db.asertest.com mail not a valid number

    问题描述: 为了配置邮件服务器,更改了相关域名,改完后,重启bind9报错 Mar 17 14:39:39 DnsServer2 named[822]: dns_rdata_fromtext: /et ...

随机推荐

  1. ssm框架中css被拦截

    最近用springmvc spring mybatis框架写程序,请求成功并获得数据,唯独css样式不能加载,但路径正确,css文件编码也是utf-8,用火狐debug总是显示未请求到(都快怀疑自己写 ...

  2. 四、spark常用函数说明学习

    1.parallelize       并行集合,切片数.默认为这个程序所分配到的资源的cpu核的个数.       查看大小:rdd.partitions.size      sc.paraliel ...

  3. Factory Pattern(工厂模式)

    1.工厂模式简介 工厂模式,专门负责将大量有共同接口的类实例化(用来生产对象).其定义为定义一个用于创建对象的接口,让子类决定实例化那一个类.工厂方法使一个类的实例化延迟到其子类. 工厂模式拥有以下几 ...

  4. Jquery datepicker 时间插件使用 js 时间相加,相减

    $(document).ready(function(){ //输入框事件 $('#probation').bind('input propertychange', function() { var ...

  5. 通过file文件选择图片预览功能

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. NOIP2016游记(非题解)

    去年的比赛现在来发是不是晚了. -------------------------------- Day1-白天 出发啦, 动车购票处一群丧病的又在玩售票机 动车上看到胡神打苍蝇 苍蝇打苍蝇 在车上颓 ...

  7. 在ueditor编辑器的光标停留处插入内容

    业务场景: 首先在ueditor编辑器中插入一段文本,然后我想在文本的某个位置(光标停留处)插入一个字符串,这个字符串是从页面的其他地方选择得来的. 注意,当我们点击ueditor编辑器以外的地方,编 ...

  8. USACO 3.3 TEXT Eulerian Tour中的Cows on Parade一点理解

    Cows on Parade Farmer John has two types of cows: black Angus and white Jerseys. While marching 19 o ...

  9. css2和CSS3的background属性简写

    1.css2:background:background-color || url("") || no-repeat || scroll || 0 0;  css3:  backg ...

  10. CentOS python升级到3.5时yum报错

    File except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax 解决步骤: #vi /usr/bin/yum 将#!/usr/bin/p ...