65. Valid Number
来源:互联网 发布:禅道 mysql数据库连接 编辑:程序博客网 时间:2024/06/07 00:46
Validate if a given string is numeric.
Some examples:"0"
=> true
" 0.1 "
=> true
"abc"
=> false
"1 a"
=> false
"2e10"
=> true
<span style="font-size:14px;">public class Solution { public boolean isNumber(String s) { s=s.trim(); boolean res; int n=s.length(); if(n==0) return false; //数字,小数点,e,数 boolean hasDigit=false,hasDot=false,hasE=false,hasS=false; char temp; for(int i=0;i<n;i++){ temp=s.charAt(i); if(temp>='0'&&temp<='9'){ hasDigit=hasS=true; continue; } switch(temp){ case '+': case '-': if(hasS) return false; hasS=true; continue; case '.': if(hasDot) return false; hasDot=hasS=true; continue; case 'e': if(!hasDigit||hasE)//have e or no digit return false; hasDigit=false; hasE=true; hasS=false; hasDot=true;//e后面的都是整数 continue; default: return false; } } return hasDigit; } }</span>
0 0
- LeetCode --- 65. Valid Number
- [Leetcode] 65. Valid Number
- [LeetCode]65.Valid Number
- 65. Valid Number
- Leetcode-65.Valid Number
- 65. Valid Number
- 【leetcode】65.Valid Number
- leetcode 65. Valid Number
- LeetCode 65. Valid Number
- Leetcode 65. Valid Number
- 65. Valid Number
- 65. Valid Number
- LeetCode 65. Valid Number
- LeetCode - 65. Valid Number
- 65. Valid Number
- [LeetCode] 65. Valid Number
- leetcode 65.Valid Number
- 65. Valid Number
- 设置textarea的默认显示的文字?
- 胡夫金字塔
- latex 大括号中公式换行,拆分公式,公式换行
- MVC分成架构
- 程序备忘_参数辨识_LV41
- 65. Valid Number
- Hard 211题 Add and Search Word - Data structure design
- 公私钥加解密问题汇总
- Java_Swing图形界面-1选项卡的创建-2使其靠左垂直对齐
- 【Visual Studio】VS2012中添加模板
- Zookeeper 错误 Will not attempt to authenticate using SASL (unknown error)
- Android中GridView以表格形式显示多张图片(仿桌面)
- 66. Plus One
- opengl学习第三课(点和线的处理)