Skip to content

Commit aaf90cd

Browse files
pre-commit-ci[bot]reniz-shah
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 42c24d6 commit aaf90cd

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

strings/string_is_valid_number.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,50 @@
66
Output: True
77
Leetcode link: https://leetcode.com/problems/valid-number/description/
88
"""
9+
910
from enum import Enum
1011
from typing import Dict
1112

13+
1214
class CharType(Enum):
13-
NUMERIC = 'NUMERIC'
14-
SIGN = 'SIGN'
15-
EXPONENT = 'EXPONENT'
16-
DECIMAL = 'DECIMAL'
15+
NUMERIC = "NUMERIC"
16+
SIGN = "SIGN"
17+
EXPONENT = "EXPONENT"
18+
DECIMAL = "DECIMAL"
19+
1720

1821
class State(Enum):
19-
INITIAL = 'INITIAL'
20-
SIGNED = 'SIGNED'
21-
WHOLE = 'WHOLE'
22-
FRACTIONAL = 'FRACTIONAL'
23-
FRACTION = 'FRACTION'
24-
EXPONENTIAL = 'EXPONENTIAL'
25-
EXP_SIGN = 'EXP_SIGN'
26-
EXP_NUMBER = 'EXP_NUMBER'
27-
28-
state_machine : Dict[State, Dict[CharType, State]] = {
29-
State.INITIAL: {CharType.NUMERIC: State.WHOLE, CharType.SIGN: State.SIGNED, CharType.DECIMAL: State.FRACTIONAL},
22+
INITIAL = "INITIAL"
23+
SIGNED = "SIGNED"
24+
WHOLE = "WHOLE"
25+
FRACTIONAL = "FRACTIONAL"
26+
FRACTION = "FRACTION"
27+
EXPONENTIAL = "EXPONENTIAL"
28+
EXP_SIGN = "EXP_SIGN"
29+
EXP_NUMBER = "EXP_NUMBER"
30+
31+
32+
state_machine: Dict[State, Dict[CharType, State]] = {
33+
State.INITIAL: {
34+
CharType.NUMERIC: State.WHOLE,
35+
CharType.SIGN: State.SIGNED,
36+
CharType.DECIMAL: State.FRACTIONAL,
37+
},
3038
State.SIGNED: {CharType.NUMERIC: State.WHOLE, CharType.DECIMAL: State.FRACTIONAL},
31-
State.WHOLE: {CharType.NUMERIC: State.WHOLE, CharType.DECIMAL: State.FRACTION, CharType.EXPONENT: State.EXPONENTIAL},
39+
State.WHOLE: {
40+
CharType.NUMERIC: State.WHOLE,
41+
CharType.DECIMAL: State.FRACTION,
42+
CharType.EXPONENT: State.EXPONENTIAL,
43+
},
3244
State.FRACTIONAL: {CharType.NUMERIC: State.FRACTION},
33-
State.FRACTION: {CharType.NUMERIC: State.FRACTION, CharType.EXPONENT: State.EXPONENTIAL},
34-
State.EXPONENTIAL: {CharType.NUMERIC: State.EXP_NUMBER, CharType.SIGN: State.EXP_SIGN},
45+
State.FRACTION: {
46+
CharType.NUMERIC: State.FRACTION,
47+
CharType.EXPONENT: State.EXPONENTIAL,
48+
},
49+
State.EXPONENTIAL: {
50+
CharType.NUMERIC: State.EXP_NUMBER,
51+
CharType.SIGN: State.EXP_SIGN,
52+
},
3553
State.EXP_SIGN: {CharType.NUMERIC: State.EXP_NUMBER},
3654
State.EXP_NUMBER: {CharType.NUMERIC: State.EXP_NUMBER},
3755
}
@@ -154,6 +172,12 @@ def classify_char(char: str) -> CharType | None:
154172
>>> classify_char('e')
155173
<CharType.EXPONENT: 'EXPONENT'>
156174
>>> classify_char('.')
175+
<CharType.DECIMAL: 'DECIMAL'>
176+
>>> classify_char('')
177+
178+
>>> classify_char('0')
179+
<CharType.NUMERIC: 'NUMERIC'>
180+
>>> classify_char('01')
157181
'decimal'
158182
>>> classify_char('r')
159183

0 commit comments

Comments
 (0)