-
Notifications
You must be signed in to change notification settings - Fork 0
/
65.py
38 lines (35 loc) · 876 Bytes
/
65.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python2.7
import re
class Solution(object):
def __init__(self):
self.__matcher = re.compile("^[-+]?([0-9]+\.?[0-9]*|[0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?$")
def isNumber(self, s):
"""
:type s: str
:rtype: bool
>>> sol = Solution()
>>> sol.isNumber("0")
True
>>> sol.isNumber(" 0.1 ")
True
>>> sol.isNumber("abc")
False
>>> sol.isNumber("1 a")
False
>>> sol.isNumber("2e10")
True
>>> sol.isNumber("3.")
True
>>> sol.isNumber(".")
False
>>> sol.isNumber(" ")
False
>>> sol.isNumber("e9")
False
>>> sol.isNumber(".1")
True
"""
s = s.strip()
if len(s) == 0:
return False
return self.__matcher.match(s) is not None