Content-Length: 510024 | pFad | http://github.com/BigEggStudy/LeetCode-CS/commit/e99d8f1b88a454d91d709c6d540c7b8f4571c496

EF Add solution for problem 165 · BigEggStudy/LeetCode-CS@e99d8f1 · GitHub
Skip to content

Commit e99d8f1

Browse files
committed
Add solution for problem 165
1 parent 564210a commit e99d8f1

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace LeetCode.Test
4+
{
5+
[TestClass]
6+
public class _0165_CompareVersionNumbers_Test
7+
{
8+
[TestMethod]
9+
public void CompareVersion_1()
10+
{
11+
var solution = new _0165_CompareVersionNumbers();
12+
var result = solution.CompareVersion("1.01", "1.001");
13+
Assert.AreEqual(0, result);
14+
}
15+
16+
[TestMethod]
17+
public void CompareVersion_2()
18+
{
19+
var solution = new _0165_CompareVersionNumbers();
20+
var result = solution.CompareVersion("1.0", "1.0.0");
21+
Assert.AreEqual(0, result);
22+
}
23+
24+
[TestMethod]
25+
public void CompareVersion_3()
26+
{
27+
var solution = new _0165_CompareVersionNumbers();
28+
var result = solution.CompareVersion("0.1", "1.1");
29+
Assert.AreEqual(-1, result);
30+
}
31+
32+
[TestMethod]
33+
public void CompareVersion_4()
34+
{
35+
var solution = new _0165_CompareVersionNumbers();
36+
var result = solution.CompareVersion("1.0.1", "1");
37+
Assert.AreEqual(1, result);
38+
}
39+
40+
[TestMethod]
41+
public void CompareVersion_5()
42+
{
43+
var solution = new _0165_CompareVersionNumbers();
44+
var result = solution.CompareVersion("7.5.2.4", "7.5.3");
45+
Assert.AreEqual(-1, result);
46+
}
47+
}
48+
}

LeetCode.Test/LeetCode.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
<Compile Include="0151-0200\0159-LongestSubstringWithAtMostTwoDistinctCharacters-Test.cs" />
206206
<Compile Include="0151-0200\0160-IntersectionOfTwoLinkedLists-Test.cs" />
207207
<Compile Include="0151-0200\0162-FindPeakElement-Test.cs" />
208+
<Compile Include="0151-0200\0165-CompareVersionNumbers-Test.cs" />
208209
<Compile Include="0151-0200\0166-FractionToRecurringDecimal-Test.cs" />
209210
<Compile Include="0151-0200\0167-TwoSumII-Test.cs" />
210211
<Compile Include="0151-0200\0168-ExcelSheetColumnTitle-Test.cs" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//-----------------------------------------------------------------------------
2+
// Runtime: 72ms
3+
// Memory Usage: 22.6 MB
4+
// Link: https://leetcode.com/submissions/detail/393499359/
5+
//-----------------------------------------------------------------------------
6+
7+
using System;
8+
9+
namespace LeetCode
10+
{
11+
public class _0165_CompareVersionNumbers
12+
{
13+
public int CompareVersion(string version1, string version2)
14+
{
15+
var nums1 = version1.Split(new char[] { '.' });
16+
var nums2 = version2.Split(new char[] { '.' });
17+
18+
var length1 = nums1.Length;
19+
var length2 = nums2.Length;
20+
21+
for (int i = 0; i < Math.Max(length1, length2); i++)
22+
{
23+
var current1 = i < length1 ? int.Parse(nums1[i]) : 0;
24+
var current2 = i < length2 ? int.Parse(nums2[i]) : 0;
25+
if (current1 != current2)
26+
return current1 > current2 ? 1 : -1;
27+
}
28+
29+
return 0;
30+
}
31+
}
32+
}

LeetCode/LeetCode.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
<Compile Include="0151-0200\0159-LongestSubstringWithAtMostTwoDistinctCharacters.cs" />
196196
<Compile Include="0151-0200\0160-IntersectionOfTwoLinkedLists.cs" />
197197
<Compile Include="0151-0200\0162-FindPeakElement.cs" />
198+
<Compile Include="0151-0200\0165-CompareVersionNumbers.cs" />
198199
<Compile Include="0151-0200\0166-FractionToRecurringDecimal.cs" />
199200
<Compile Include="0151-0200\0167-TwoSumII.cs" />
200201
<Compile Include="0151-0200\0168-ExcelSheetColumnTitle.cs" />

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![AppVeyor Build Status](https://img.shields.io/appveyor/build/bigegg/leetcode-cs?label=Windows%20Build%20Status&logo=AppVeyor&style=flat-square)](https://ci.appveyor.com/project/BigEgg/leetcode-cs)
2-
[![Solved Problems](https://img.shields.io/badge/Solved%20Problems-810-blue.svg?style=flat-square)](https://github.com/BigEggStudy/LeetCode-CS)
2+
[![Solved Problems](https://img.shields.io/badge/Solved%20Problems-811-blue.svg?style=flat-square)](https://github.com/BigEggStudy/LeetCode-CS)
33

44
# LeetCode
55
The C# solutions for LeetCode problems.
@@ -214,6 +214,7 @@ The C# solutions for LeetCode problems.
214214
| 159 | Longest Substring with At Most Two Distinct Characters | [C#](./LeetCode/0151-0200/0159-LongestSubstringWithAtMostTwoDistinctCharacters.cs)(72ms) | O(N) | O(1) | |
215215
| 160 | Intersection of Two Linked Lists | [C#](./LeetCode/0151-0200/0160-IntersectionOfTwoLinkedLists.cs)(116ms) | O(N+M) | O(1) | |
216216
| 162 | Find Peak Element | [C#](./LeetCode/0151-0200/0162-FindPeakElement.cs)(92ms) | O(LogN) | O(1) | |
217+
| 165 | Compare Version Numbers | [C#](./LeetCode/0151-0200/0165-CompareVersionNumbers.cs)(72ms) | O(N+M) | O(N+M) | |
217218
| 166 | Fraction to Recurring Decimal | [C#](./LeetCode/0151-0200/0166-FractionToRecurringDecimal.cs)(76ms) | O(N) | O(N) | |
218219
| 167 | Two Sum II - Input array is sorted | [C#](./LeetCode/0151-0200/0167-TwoSumII.cs)(244ms) | O(N) | O(1) | |
219220
| 168 | Excel Sheet Column Title | [C#](./LeetCode/0151-0200/0168-ExcelSheetColumnTitle.cs)(68ms) | O(logN) | O(1) | |

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/BigEggStudy/LeetCode-CS/commit/e99d8f1b88a454d91d709c6d540c7b8f4571c496

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy