[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-08-07 12:22:54 +00:00 committed by reniz-shah
parent 42c24d6f3c
commit aaf90cdb38

View File

@ -6,32 +6,50 @@ Input: s = -90E3
Output: True Output: True
Leetcode link: https://leetcode.com/problems/valid-number/description/ Leetcode link: https://leetcode.com/problems/valid-number/description/
""" """
from enum import Enum from enum import Enum
from typing import Dict from typing import Dict
class CharType(Enum): class CharType(Enum):
NUMERIC = 'NUMERIC' NUMERIC = "NUMERIC"
SIGN = 'SIGN' SIGN = "SIGN"
EXPONENT = 'EXPONENT' EXPONENT = "EXPONENT"
DECIMAL = 'DECIMAL' DECIMAL = "DECIMAL"
class State(Enum): class State(Enum):
INITIAL = 'INITIAL' INITIAL = "INITIAL"
SIGNED = 'SIGNED' SIGNED = "SIGNED"
WHOLE = 'WHOLE' WHOLE = "WHOLE"
FRACTIONAL = 'FRACTIONAL' FRACTIONAL = "FRACTIONAL"
FRACTION = 'FRACTION' FRACTION = "FRACTION"
EXPONENTIAL = 'EXPONENTIAL' EXPONENTIAL = "EXPONENTIAL"
EXP_SIGN = 'EXP_SIGN' EXP_SIGN = "EXP_SIGN"
EXP_NUMBER = 'EXP_NUMBER' EXP_NUMBER = "EXP_NUMBER"
state_machine: Dict[State, Dict[CharType, State]] = { state_machine: Dict[State, Dict[CharType, State]] = {
State.INITIAL: {CharType.NUMERIC: State.WHOLE, CharType.SIGN: State.SIGNED, CharType.DECIMAL: State.FRACTIONAL}, State.INITIAL: {
CharType.NUMERIC: State.WHOLE,
CharType.SIGN: State.SIGNED,
CharType.DECIMAL: State.FRACTIONAL,
},
State.SIGNED: {CharType.NUMERIC: State.WHOLE, CharType.DECIMAL: State.FRACTIONAL}, State.SIGNED: {CharType.NUMERIC: State.WHOLE, CharType.DECIMAL: State.FRACTIONAL},
State.WHOLE: {CharType.NUMERIC: State.WHOLE, CharType.DECIMAL: State.FRACTION, CharType.EXPONENT: State.EXPONENTIAL}, State.WHOLE: {
CharType.NUMERIC: State.WHOLE,
CharType.DECIMAL: State.FRACTION,
CharType.EXPONENT: State.EXPONENTIAL,
},
State.FRACTIONAL: {CharType.NUMERIC: State.FRACTION}, State.FRACTIONAL: {CharType.NUMERIC: State.FRACTION},
State.FRACTION: {CharType.NUMERIC: State.FRACTION, CharType.EXPONENT: State.EXPONENTIAL}, State.FRACTION: {
State.EXPONENTIAL: {CharType.NUMERIC: State.EXP_NUMBER, CharType.SIGN: State.EXP_SIGN}, CharType.NUMERIC: State.FRACTION,
CharType.EXPONENT: State.EXPONENTIAL,
},
State.EXPONENTIAL: {
CharType.NUMERIC: State.EXP_NUMBER,
CharType.SIGN: State.EXP_SIGN,
},
State.EXP_SIGN: {CharType.NUMERIC: State.EXP_NUMBER}, State.EXP_SIGN: {CharType.NUMERIC: State.EXP_NUMBER},
State.EXP_NUMBER: {CharType.NUMERIC: State.EXP_NUMBER}, State.EXP_NUMBER: {CharType.NUMERIC: State.EXP_NUMBER},
} }
@ -154,6 +172,12 @@ def classify_char(char: str) -> CharType | None:
>>> classify_char('e') >>> classify_char('e')
<CharType.EXPONENT: 'EXPONENT'> <CharType.EXPONENT: 'EXPONENT'>
>>> classify_char('.') >>> classify_char('.')
<CharType.DECIMAL: 'DECIMAL'>
>>> classify_char('')
>>> classify_char('0')
<CharType.NUMERIC: 'NUMERIC'>
>>> classify_char('01')
'decimal' 'decimal'
>>> classify_char('r') >>> classify_char('r')