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. 制作类似ThinkPHP框架中的PATHINFO模式功能(二)

    距离上一次发布的<制作类似ThinkPHP框架中的PATHINFO模式功能>(文章地址:http://www.cnblogs.com/phpstudy2015-6/p/6242700.ht ...

  2. java基础练习 8

    public class Eighth { /*判断101-200之间有多少个素数,并输出所有素数.素数又叫质数,就是除了1和它本身之外,再也没有整数能被它整除的数.也就是素数只有两个因子.*/ pu ...

  3. [HMLY]7.iOS MVVM+RAC 从框架到实战

    1.MVVM浅析 MVC是构建iOS App的标准模式,是苹果推荐的一个用来组织代码的权威范式,市面上大部分App都是这样构建的,具体组织模式不细说,iOS入门者都比较了解(虽然不一定能完全去遵守), ...

  4. (二)Harbor WEB的使用

    接上一篇<安装Harbor>,安装好之后,接下来我们就进行Harbor  web界面的操作吧! 转载请标明出处:http://www.cnblogs.com/huangjc/p/62704 ...

  5. 自定义连接池java.lang.ClassCastException: com.sun.proxy.$Proxy4 cannot be cast to java.sql.Connection

    原因:Connection.getInterfaces() 与数据库驱动有关,数据库驱动不同 Connection.getInterfaces() 的结果也就不同,Connection.getInte ...

  6. D3.js

    html代码: <div id="id"> <p>Apple</p> <p id="aa">Pear</p ...

  7. Mac OS 上 CRT 的终端设置

    这种设置完全是个人习惯, 切勿效仿!!!   整个终端是 白底黑字 显示方式(奇葩中的奇葩) 1) ANSI Color & Use color scheme 同时勾选 2) Characte ...

  8. [转]学好Mac常用命令,助力iOS开发

    转自:http://www.jianshu.com/p/d9ec00d28237   序言 在iOS开发的过程中,更多地注重iOS开发的效率,熟练使用Mac终端操作的常用命令,可以让你更好的游刃于iO ...

  9. DotNetZip 压缩下载

    var fs = Response.OutputStream; using (ZipFile zip = new ZipFile(System.Text.Encoding.UTF8)) //编码是解决 ...

  10. 一个App从创意到最终上架到App Store里的整个过程是怎样的?

    一个App从创意到最终上架到App Store里的整个过程是怎样的? 制作App需要什么软件?应该看什么书?需要哪些设备?推到App Store里,需要注册什么网站?是否需要付费?需要什么证书之类的? ...