[LeetCode]Valid Number
来源:互联网 发布:中银淘宝校园卡没注销 编辑:程序博客网 时间:2024/05/02 14:13
Validate if a given string is numeric.
Some examples:"0"
=> true
" 0.1 "
=> true
"abc"
=> false
"1 a"
=> false
"2e10"
=> true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
6e6.5不是数,这里指数不能为小数,但是理论上应该是可以的, 3e3.0也不是数public class Solution { public boolean isNumber(String s) { String strim=s.trim(); if(strim.length()==0) return false; if(strim.charAt(0)=='e'||strim.charAt(strim.length()-1)=='e') return false; String strs[] = strim.split("e"); if(strs.length>2) return false; for(int i=0;i<strs.length;i++){ String string = strs[i]; int spot = 0; int num = 0; if(string.length()==1&&(string.charAt(0)=='+'||string.charAt(0)=='-')) return false; for(int j=0;j<string.length();j++){ char c = string.charAt(j); if(c=='.'){ if(i==1) return false; spot++; }else if(c>'9'||c<'0'){ if(j==0&&(c=='-'||c=='+')) continue; return false; }else{ num++; } } if(num==0||spot>1) return false; String li[] = string.split("\\."); if(li.length==0||li.length>2) return false; } return true; }}
0 0
- LeetCode: Valid Number
- LeetCode : Valid Number
- Leetcode: Valid Number
- [Leetcode] Valid Number
- leetcode 50: Valid Number
- [LeetCode] Valid Number
- 【leetcode】Valid Number
- [LeetCode]Valid Number
- [leetcode] Valid Number
- LeetCode | Valid Number
- LeetCode-Valid Number - 有限状态机
- leetcode Valid Number
- Leetcode: Valid Number
- 【leetcode】Valid Number
- Leetcode Valid Number
- LeetCode题解: Valid Number
- LeetCode Valid Number
- [Leetcode] Valid Number (Java)
- TopCoder SRM 646 Div2 Problem 500 - TheGridDivTwo (BFS + 优先队列)
- opencv入门
- shell遍历目录下所有文件
- Struts2中Action由自己与由Spring管理的区别(转)
- [Linux系统编程]Curses编程
- [LeetCode]Valid Number
- 个人web服务器的安装
- opengl shader 图片变灰及还原,使用自己的shader崩溃问题
- Android开机时间分析
- eclipse安装SVN插件
- dll和ocx的区别
- JStorm之Topology提交客户端
- Spring @Autowired,@Resource,@Required注解的用法和作用(转)
- 《Effective C++》设计与声明:条款18-条款19