Trains the technique from
LeetCode 165Compare Version NumbersThis 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 device reports its firmware revision as a string: one or more chunks of
decimal digits joined by single dots, for example "4.11.0".
A chunk is read as a plain decimal integer, so leading zeros inside a chunk carry
no meaning and "3.04" names the same revision as "3.4".
Compare the revisions left and right. Line their chunks up starting from the
leftmost one. When one revision runs out of chunks before the other, treat each
of its missing chunks as 0.
Return -1 when left is the earlier revision, 1 when right is the earlier
revision, and 0 when the two strings name the same revision.
Example 1
The first chunks tie at 2. The second chunks read as 9 and 10, and 9 is the smaller integer, so left is the earlier revision.
Example 2
The chunk "012" reads as the integer 12, matching "12", and the first chunks both read as 7, so the two strings name the same revision.
Example 3
Padding the right-hand revision gives chunks 5, 0 and 0. The first two pairs tie and the third pair is 1 against 0, so right is the earlier revision.
Example 4
The missing chunk on the right counts as 0, which matches the 0 on the left, so the revisions are the same.
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 compare_version(left: str, right: str) -> int:public int compareVersion(String left, String right)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.