Skip to content

Commit

Permalink
Update valid-number.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed May 27, 2015
1 parent 725582e commit 60677a2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Python/valid-number.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InputType:
DOT = 4
EXPONENT = 5

# regular expression: "^\s*[\+\-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?\d+)?\s*$"
# regular expression: "^\s*[+-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?\d+)?\s*$"
# automata: http://images.cnitblog.com/i/627993/201405/012016243309923.png
class Solution:
# @param s, a string
Expand Down Expand Up @@ -63,11 +63,11 @@ class Solution2:
# @return a boolean
def isNumber(self, s):
import re
return bool(re.match("^\s*[\+\-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?\d+)?\s*$", s))
return bool(re.match("^\s*[+-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?\d+)?\s*$", s))

if __name__ == "__main__":
print Solution().isNumber(" 0.1 ")
print Solution().isNumber("abc")
print Solution().isNumber("1 a")
print Solution().isNumber("2e10")


0 comments on commit 60677a2

Please sign in to comment.