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

相关推荐

今年秋招到底是谁在拿offer:七院电话面的时候问我有没有女朋友,一听异地说你赶紧分。我:???
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务