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
全部评论

相关推荐

06-26 19:47
中南大学 Java
点赞 评论 收藏
分享
球Offer上岸👑:可能是大环境太差了 太卷了 学历也很重要 hc也不是很多 所以很难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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