-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy path0165-CompareVersionNumbers.cs
More file actions
32 lines (27 loc) · 1003 Bytes
/
0165-CompareVersionNumbers.cs
File metadata and controls
32 lines (27 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//-----------------------------------------------------------------------------
// Runtime: 72ms
// Memory Usage: 22.6 MB
// Link: https://leetcode.com/submissions/detail/393499359/
//-----------------------------------------------------------------------------
using System;
namespace LeetCode
{
public class _0165_CompareVersionNumbers
{
public int CompareVersion(string version1, string version2)
{
var nums1 = version1.Split(new char[] { '.' });
var nums2 = version2.Split(new char[] { '.' });
var length1 = nums1.Length;
var length2 = nums2.Length;
for (int i = 0; i < Math.Max(length1, length2); i++)
{
var current1 = i < length1 ? int.Parse(nums1[i]) : 0;
var current2 = i < length2 ? int.Parse(nums2[i]) : 0;
if (current1 != current2)
return current1 > current2 ? 1 : -1;
}
return 0;
}
}
}