From aaf90cdb3871e36ad128d2d8a7656099b697758e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:22:54 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/string_is_valid_number.py | 58 ++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/strings/string_is_valid_number.py b/strings/string_is_valid_number.py index 9e2ac663f..696fb78c5 100644 --- a/strings/string_is_valid_number.py +++ b/strings/string_is_valid_number.py @@ -6,32 +6,50 @@ Input: s = -90E3 Output: True Leetcode link: https://leetcode.com/problems/valid-number/description/ """ + from enum import Enum from typing import Dict + class CharType(Enum): - NUMERIC = 'NUMERIC' - SIGN = 'SIGN' - EXPONENT = 'EXPONENT' - DECIMAL = 'DECIMAL' + NUMERIC = "NUMERIC" + SIGN = "SIGN" + EXPONENT = "EXPONENT" + DECIMAL = "DECIMAL" + class State(Enum): - INITIAL = 'INITIAL' - SIGNED = 'SIGNED' - WHOLE = 'WHOLE' - FRACTIONAL = 'FRACTIONAL' - FRACTION = 'FRACTION' - EXPONENTIAL = 'EXPONENTIAL' - EXP_SIGN = 'EXP_SIGN' - EXP_NUMBER = 'EXP_NUMBER' + INITIAL = "INITIAL" + SIGNED = "SIGNED" + WHOLE = "WHOLE" + FRACTIONAL = "FRACTIONAL" + FRACTION = "FRACTION" + EXPONENTIAL = "EXPONENTIAL" + EXP_SIGN = "EXP_SIGN" + EXP_NUMBER = "EXP_NUMBER" -state_machine : Dict[State, Dict[CharType, State]] = { - State.INITIAL: {CharType.NUMERIC: State.WHOLE, CharType.SIGN: State.SIGNED, CharType.DECIMAL: State.FRACTIONAL}, + +state_machine: Dict[State, Dict[CharType, State]] = { + 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.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.FRACTION: {CharType.NUMERIC: State.FRACTION, CharType.EXPONENT: State.EXPONENTIAL}, - State.EXPONENTIAL: {CharType.NUMERIC: State.EXP_NUMBER, CharType.SIGN: State.EXP_SIGN}, + State.FRACTION: { + 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_NUMBER: {CharType.NUMERIC: State.EXP_NUMBER}, } @@ -154,6 +172,12 @@ def classify_char(char: str) -> CharType | None: >>> classify_char('e') >>> classify_char('.') + + >>> classify_char('') + + >>> classify_char('0') + + >>> classify_char('01') 'decimal' >>> classify_char('r')