20. 表示数值的字符串

表示数值的字符串

http://www.nowcoder.com/questionTerminal/6f8c901d091949a5837e24bb82a731f2

class Solution:
    # s字符串
    def isNumeric(self, s):
        # write code here
        pointmark = False
        exponentmark = False
        signmark = False
        for i in range(len(s)):
            if s[i] == '.' and not pointmark:
                pointmark = True
            elif s[i] == 'e' or s[i] == 'E' : 
                if not exponentmark and i < (len(s) - 1):
                    exponentmark = True
                    pointmark = True
                    signmark = False
                else:
                    return False
            elif s[i] == '+' or s[i] == '-' :
                if not signmark:
                    signmark = True
                else:
                    return False
            elif s[i] < '0' or s[i] > '9':
                return False
            elif '0' < s[i] < '9':
                signmark = True 
        return True
全部评论

相关推荐

09-22 15:45
门头沟学院 Java
谁给娃offer我给...:我也遇到了,我说只要我通过面试我就去,实际上我根本就不会去😁
点赞 评论 收藏
分享
脾气小祖宗:这简历摸到都得狠狠地消毒液洗手😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务