Problem link
https://leetcode.com/problems/valid-number/
Problem Summary
문자열이 valid 한 수인지 판단하는 문제.
Solution
딱 보니 정규식으로 풀린다...
https://regex101.com/
디버깅 시 위 사이트를 이용함.
문제에 나온 그대로 정규식으로 만들어주면 된다.
Source Code
import re
class Solution:
def isNumber(self, s: str) -> bool:
return bool(re.match(r'^[+-]?(\d+\.\d+|\d+\.|\.\d+|\d+)([eE][+-]?\d+)?$', s))