首页 > 代码库 > [leetcode]Valid Number
[leetcode]Valid Number
问题描述:
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.
考虑:93.3f, 23.43D , 2341234L等数字均为无效数字,数字中包含的字母只能是e
代码:
public class Valid_Number { //java public boolean isNumber(String s) { if(s == null || s.trim().isEmpty()) return false; s = s.trim().toLowerCase(); char ch = s.charAt(s.length()-1); if(ch =='f' || ch =='l' || ch =='d') return false; try{ Double.valueOf(s); return true; }catch(Exception e){ return false; } } }
[leetcode]Valid Number
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。