Trains the technique from
LeetCode 65Valid NumberThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A field logger writes one token per line and you are asked to sieve out the malformed ones. A token is a valid reading exactly when it can be cut into a body, optionally followed by a scale part, with nothing left over.
A body is an optional single + or -, followed by one of these three shapes:
., then zero or more digits;., then one or more digits.A scale part is the letter e or E, then an optional single + or -, then one or more
digits.
Any other letter, a second ., a second e or E, a sign that is neither at the very
start nor directly after e or E, or a . sitting inside the scale part all make the
token invalid. Decide it by inspecting the characters; do not hand the token to a built-in
numeric conversion.
Given token, return true when it is a valid reading and false otherwise.
Example 1
The body is +3, which is a sign followed by one digit, and the scale part is e-2, which is the marker, a sign and one digit.
Example 2
The body 46. is digits followed by a dot with no digits after it, which the second shape allows, and e3 is a well-formed scale part.
Example 3
The dot falls inside the scale part, where only a sign and digits may appear.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def is_valid_reading(token: str) -> bool:public boolean isValidReading(String token)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.