剑指offer python版 表示数值的字符串

class Solution:
    def aa(self,s):
        isAllowdot=True
        isAllowE=True
        
        for i in range(len(s)):
            if (s[i] in"+-" and i==0) or (s[i-1] in "eE" and i<len(s)-1):
                continue
            elif isAllowdot and s[i]==".":
                isAllowdot=False
                if i >=len(s)-1 or s[i+1] not in "0123456789":
                    return False
            elif isAllowE and s[i] in"eE":
                isAllowdot=False
                isAllowE=False
                if i>=len(s)-1 or s[i+1] not in "0123456789+1":
                    return False
            elif s[i] not in "0123456789":
                return False
        return True

 

posted @ 2018-10-25 15:53  findtruth123  阅读(366)  评论(0编辑  收藏  举报