|
6 | 6 |
|
7 | 7 | ## Description
|
8 | 8 |
|
9 |
| -<p>Given two version numbers, <code>version1</code> and <code>version2</code>, compare them.</p> |
| 9 | +<p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.</p> |
10 | 10 |
|
11 |
| -<ul> |
12 |
| -</ul> |
13 |
| - |
14 |
| -<p>Version numbers consist of <strong>one or more revisions</strong> joined by a dot <code>'.'</code>. Each revision consists of <strong>digits</strong> and may contain leading <strong>zeros</strong>. Every revision contains <strong>at least one character</strong>. Revisions are <strong>0-indexed from left to right</strong>, with the leftmost revision being revision 0, the next revision being revision 1, and so on. For example <code>2.5.33</code> and <code>0.1</code> are valid version numbers.</p> |
15 |
| - |
16 |
| -<p>To compare version numbers, compare their revisions in <strong>left-to-right order</strong>. Revisions are compared using their <strong>integer value ignoring any leading zeros</strong>. This means that revisions <code>1</code> and <code>001</code> are considered <strong>equal</strong>. If a version number does not specify a revision at an index, then <strong>treat the revision as <code>0</code></strong>. For example, version <code>1.0</code> is less than version <code>1.1</code> because their revision 0s are the same, but their revision 1s are <code>0</code> and <code>1</code> respectively, and <code>0 < 1</code>.</p> |
| 11 | +<p>To compare version strings, compare their revision values in <strong>left-to-right order</strong>. If one of the version strings has fewer revisions, treat the missing revision values as <code>0</code>.</p> |
17 | 12 |
|
18 | 13 | <p><em>Return the following:</em></p>
|
19 | 14 |
|
|
26 | 21 | <p> </p>
|
27 | 22 | <p><strong class="example">Example 1:</strong></p>
|
28 | 23 |
|
29 |
| -<pre> |
30 |
| -<strong>Input:</strong> version1 = "1.01", version2 = "1.001" |
31 |
| -<strong>Output:</strong> 0 |
32 |
| -<strong>Explanation:</strong> Ignoring leading zeroes, both "01" and "001" represent the same integer "1". |
33 |
| -</pre> |
| 24 | +<div class="example-block"> |
| 25 | +<p><strong>Input:</strong> <span class="example-io">version1 = "1.2", version2 = "1.10"</span></p> |
| 26 | + |
| 27 | +<p><strong>Output:</strong> <span class="example-io">-1</span></p> |
| 28 | + |
| 29 | +<p><strong>Explanation:</strong></p> |
| 30 | + |
| 31 | +<p>version1's second revision is "2" and version2's second revision is "10": 2 < 10, so version1 < version2.</p> |
| 32 | +</div> |
34 | 33 |
|
35 | 34 | <p><strong class="example">Example 2:</strong></p>
|
36 | 35 |
|
37 |
| -<pre> |
38 |
| -<strong>Input:</strong> version1 = "1.0", version2 = "1.0.0" |
39 |
| -<strong>Output:</strong> 0 |
40 |
| -<strong>Explanation:</strong> version1 does not specify revision 2, which means it is treated as "0". |
41 |
| -</pre> |
| 36 | +<div class="example-block"> |
| 37 | +<p><strong>Input:</strong> <span class="example-io">version1 = "1.01", version2 = "1.001"</span></p> |
| 38 | + |
| 39 | +<p><strong>Output:</strong> <span class="example-io">0</span></p> |
| 40 | + |
| 41 | +<p><strong>Explanation:</strong></p> |
| 42 | + |
| 43 | +<p>Ignoring leading zeroes, both "01" and "001" represent the same integer "1".</p> |
| 44 | +</div> |
42 | 45 |
|
43 | 46 | <p><strong class="example">Example 3:</strong></p>
|
44 | 47 |
|
45 |
| -<pre> |
46 |
| -<strong>Input:</strong> version1 = "0.1", version2 = "1.1" |
47 |
| -<strong>Output:</strong> -1 |
48 |
| -<strong>Explanation:</strong> version1's revision 0 is "0", while version2's revision 0 is "1". 0 < 1, so version1 < version2. |
49 |
| -</pre> |
| 48 | +<div class="example-block"> |
| 49 | +<p><strong>Input:</strong> <span class="example-io">version1 = "1.0", version2 = "1.0.0.0"</span></p> |
| 50 | + |
| 51 | +<p><strong>Output:</strong> <span class="example-io">0</span></p> |
| 52 | + |
| 53 | +<p><strong>Explanation:</strong></p> |
| 54 | + |
| 55 | +<p>version1 has less revisions, which means every missing revision are treated as "0".</p> |
| 56 | +</div> |
50 | 57 |
|
51 | 58 | <p> </p>
|
52 | 59 | <p><strong>Constraints:</strong></p>
|
|
0 commit comments