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. mongodb两次被黑后......

    先说说事情的经过...... 2017年1月8号星期天,在家翻头条无意中看到一条新闻说很多用户的mongodb被黑了,数据都被删了.当时想着公司的爬虫用的也是mongodb做存储,应该不会被黑吧,不可 ...

  2. abstract class与interface的区别与联系

    1.相同点:A. 两者都是抽象类,都不能实例化.B. interface实现类及abstract class的子类都必须要实现已经声明的抽象方法. 2. 不同点:A. interface需要实现,要用 ...

  3. 关于JavaMail

    一.概述 1.邮件协议: SMTP:(Simple Mail Transfer Protocol,简单邮件传输协议)发邮件协议: POP3:(Post Office Protocol Version ...

  4. dubbo学习笔记

    一.zookeeper在Dubbo中扮演角色 流程:1.服务提供者启动时向/dubbo/com.foo.BarService/providers目录下写入URL2.服务消费者启动时订阅/dubbo/c ...

  5. ruby web性能响应时间

    可以统计单个web页面加载时间. require 'watir-webdriver' require 'watir-webdriver-performance' b = Watir::Browser. ...

  6. android 音频播放总结 soundlPool,MediaPlay

    soundlPool 用于小音频的播放多个同时播放. 使用步骤: 步骤一: 首先下载音频文件可以将其放入assets文件夹下或者res下的raw文件夹下,区别在于assets下可以再新建文件夹二raw ...

  7. Linux中一些简单命令(一)

    1.查看当前用户:who 2.显示当前目录:pwd 3.查看当前服务器的时间:date 4.查看日历:cal+year; 例如:cal 2016 5.计算器:bc  退出计算器:quit或者ctrl+ ...

  8. Kmplayer播放器 绿色免安装版 2016 中文版

    软件名称: Kmplayer播放器 绿色免安装版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 42.8MB 图片预览: 软件简介: Kmplayer播放 ...

  9. Winform DataGridView直接导出Excel

    /// <summary> /// 导出excel /// </summary> /// <param name="fileName">导出文件 ...

  10. 设计模式 -- 代理模式 (Proxy Pattern)

    定义: 为其他对象提供一种代理以控制对这个对象的访问: 角色: 1,抽象主题类,(接口或者抽象类),抽象真实主题和代理的共有方法(如下Subject类): 2,具体实现的主题类,继承或者实现抽象主题类 ...