#165
Compare Version Numbers
specialist · 995 · lc medium +32 · 46.2% accepted · 3,163 likes · top 30%
Description
Compare two version strings version1 and version2. Each is a sequence of integer revisions separated by dots '.'; leading zeros within each revision are ignored.
Compare revision values left to right. Treat any missing revision as 0.
Return the following:
- -1 if version1 < version2.
- 1 if version1 > version2.
- 0 if they are equal.
Code
1
2
3