import re class Solution(object): def isNumber(self, s): """ :type s: str :rtype: bool """ digit2 = re.compile("^[\ ]*[+-]?(\d+\.?\d*|\d*\.?\d+)(e[+-]?\d+)?[\ ]*$") return bool(digit2.match(s))
Last five lines are a pretty convoluted way to write
Thanks StefanPochmann, I am a green hand on writing Python and wasn't so familiar with the recent upgrade of this OJ, maybe several months later I will submit again :). I really appreciate your reply as well as your previous posts, they help a lot to me.
IMHO, using regular expressions to solve this problem defeats the entire purpose of the question. As an interviewer, I do not want to see if you know regex; I want to see if you know how to solve an intricate problem with lots of edge cases.
IMHO too, no means to affend you, I do think using regex is a simple way solve that problem and it's quite an ability to choose the tool. On the other hand, using regex doesn't mean you needn't deal with these edge cases, I did consider the edge cases and at last combined them into one. By the way, regardless the code effciency, as an employer, do you want to have millions of long dirty codes in your program which consider these edge cases or a few lines of clean codes which also consider these edge code? Any way, thank you for replying me and hope that there will be a further discussion.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.