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 ...
随机推荐
- java基础知识拾遗(二)
1.finally public static int func (){ try{ return 1; }catch (Exception e){ return 2; }finally { retur ...
- python基础语言以及if/while语句结构
接下来学会了变量:用简单的变量来代替复杂的字符串 变量首字母不能是数字或者特殊符号~!@#¥等. 字符集的发展: ASCII 255个 1个占1bytes------>1980年 GB2312 ...
- unity3D学习序幕
目前,我所在的公司不适合我长久发展,在一好友的提示下,我决定以unity3D程序员的身份,返回我2013年工作过的那家公司.关于unity3D,除了几年前一点模糊的记忆,其他都是一篇空白.今年年初我买 ...
- .NET 基础 一步步 一幕幕[面向对象之堆、栈、引用类型、值类型]
堆.栈.引用类型.值类型 内存分为堆和栈(PS:还有一种是静态存储区域 [内存分为这三种]),值类型的数据存储在栈中,引用类型的数据存储在堆中. 堆.栈: 堆和栈的区别: 栈是编译期间就分配好的内存空 ...
- Access一些常用的SQL语句
您可以将 Microsoft Office Access 2013 用作创建.修改数据库以及处理数据的工具,还可将 Office Access 2013 用作服务器数据库管理系统(如 Microsof ...
- php 语言特点
PS:绝大多数用php的企业/ 项目 活不到雇佣得起月薪35k以上的php程序员那一天,也是php码农在10年经验的时候普遍不如java程序员的原因之一. PS2: 由于薪资提升太快,很多php码农跳 ...
- leetcode medium
419. Battleships in a Board --No iven an 2D board, count how many different battleships are in it. T ...
- BitMap - leetcode [位运算]
136. Single Number 因为A XOR A = 0,且XOR运算是可交换的,于是,对于实例{2,1,4,5,2,4,1}就会有这样的结果: (2^1^4^5^2^4^1) => ( ...
- 使用canvas实现超绚丽的旋转正方形
自己无意中的一个小"bug",却让动画变得超绚丽= = 所以,不要害怕出bug,谁知道bug不会开出一朵绚丽的花呢? <!DOCTYPE html> <html ...
- Apache 关于 mod_rewrite 遇到 %2F或%5C (正反斜杠)等特殊符号导致URL重写失效出现404的问题
.htaccess 文件 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d Rew ...