Valid Number--LeetCode
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的更多相关文章
- Valid Number leetcode java
题目: Validate if a given string is numeric. Some examples: "0" => true " 0.1 " ...
- 【LeetCode】65. Valid Number
Difficulty: Hard More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...
- 【leetcode】Valid Number
Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 ...
- [leetcode]65. Valid Number 有效数值
Validate if a given string can be interpreted as a decimal number. Some examples:"0" => ...
- LeetCode: Valid Number 解题报告
Valid NumberValidate if a given string is numeric. Some examples:"0" => true" 0.1 ...
- leetCode 65.Valid Number (有效数字)
Valid Number Validate if a given string is numeric. Some examples: "0" => true " ...
- [LintCode] Valid Number 验证数字
Validate if a given string is numeric. Have you met this question in a real interview? Yes Example & ...
- [Swift]LeetCode65. 有效数字 | Valid Number
Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...
- Valid Number @python
Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 ...
- 配置域名服务器报错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 ...
随机推荐
- ssm框架中css被拦截
最近用springmvc spring mybatis框架写程序,请求成功并获得数据,唯独css样式不能加载,但路径正确,css文件编码也是utf-8,用火狐debug总是显示未请求到(都快怀疑自己写 ...
- 四、spark常用函数说明学习
1.parallelize 并行集合,切片数.默认为这个程序所分配到的资源的cpu核的个数. 查看大小:rdd.partitions.size sc.paraliel ...
- Factory Pattern(工厂模式)
1.工厂模式简介 工厂模式,专门负责将大量有共同接口的类实例化(用来生产对象).其定义为定义一个用于创建对象的接口,让子类决定实例化那一个类.工厂方法使一个类的实例化延迟到其子类. 工厂模式拥有以下几 ...
- Jquery datepicker 时间插件使用 js 时间相加,相减
$(document).ready(function(){ //输入框事件 $('#probation').bind('input propertychange', function() { var ...
- 通过file文件选择图片预览功能
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- NOIP2016游记(非题解)
去年的比赛现在来发是不是晚了. -------------------------------- Day1-白天 出发啦, 动车购票处一群丧病的又在玩售票机 动车上看到胡神打苍蝇 苍蝇打苍蝇 在车上颓 ...
- 在ueditor编辑器的光标停留处插入内容
业务场景: 首先在ueditor编辑器中插入一段文本,然后我想在文本的某个位置(光标停留处)插入一个字符串,这个字符串是从页面的其他地方选择得来的. 注意,当我们点击ueditor编辑器以外的地方,编 ...
- 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 ...
- css2和CSS3的background属性简写
1.css2:background:background-color || url("") || no-repeat || scroll || 0 0; css3: backg ...
- CentOS python升级到3.5时yum报错
File except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax 解决步骤: #vi /usr/bin/yum 将#!/usr/bin/p ...