首页 > 其他 > 详细

LeetCode——Valid Number

时间:2017-07-03 13:07:52      阅读:242      评论:0      收藏:0      [点我收藏+]

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.

原题链接:https://oj.leetcode.com/problems/valid-number/

推断字符串是否是数字。

规则:出现+, - 则必须是第一个。或前一个是e;有. 则是小数,之前不可有.e;有e。则前面要有.,不能有e,而且后面要有.

可用正則表達式来解答。

	public static boolean isNumber(String s) {
		String reg = "[+-]?(\\d+\\.?|\\.\\d+)\\d*(e[+-]?\\d+)?

"; return s.trim().matches(reg); }






LeetCode——Valid Number

原文:http://www.cnblogs.com/wzjhoutai/p/7110277.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!