lintcode 有效数字

来源:互联网 发布:手机淘宝店店招 编辑:程序博客网 时间:2024/04/30 20:05
class Solution:    """    @param: s: the string that represents a number    @return: whether the string is a valid number    """    def isNumber(self, s):        # write your code here        s=s.replace('.','')        s=s.replace(' ','')        s=s.replace('+','')        s=s.replace('-','')        if len(s)==0 or s[0]<'0' or s[0]>'9':            return False        s1="0"+s        try:            a=float(s1)            return True        except:            return False

原创粉丝点击