码迷,mamicode.com
首页 > 其他好文 > 详细

Valid Number

时间:2014-12-03 12:20:43      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   for   on   div   

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.

 

class Solution:
    # @param s, a string
    # @return a boolean
    def isNumber(self, s):
        try:
            float(s)                 
            return True                
        except:
            return False

 

Valid Number

标签:style   blog   io   ar   color   sp   for   on   div   

原文地址:http://www.cnblogs.com/code-swan/p/4139438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!