Skip to content

Commit 577317f

Browse files
author
Bogdan Hladiuc
committed
Q Missing Plus Two
1 parent ce0ce9f commit 577317f

File tree

8 files changed

+172
-3
lines changed

8 files changed

+172
-3
lines changed

LeetcodeNew.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Q189_Rotate_Array", "Q189_R
7575
EndProject
7676
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Q387_First_Unique_Character_In_a_String", "Q387_First_Unique_Character_In_a_String\Q387_First_Unique_Character_In_a_String.csproj", "{9082807A-83D9-4756-9A20-307EBF21D6E1}"
7777
EndProject
78+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Q_Missing_Plus_Two", "Q_Missing_Plus_Two\Q_Missing_Plus_Two.csproj", "{E9A1A414-3117-41D9-990E-ABA5D910B19C}"
79+
EndProject
7880
Global
7981
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8082
Debug|Any CPU = Debug|Any CPU
@@ -520,5 +522,17 @@ Global
520522
{9082807A-83D9-4756-9A20-307EBF21D6E1}.Release|x64.Build.0 = Release|Any CPU
521523
{9082807A-83D9-4756-9A20-307EBF21D6E1}.Release|x86.ActiveCfg = Release|Any CPU
522524
{9082807A-83D9-4756-9A20-307EBF21D6E1}.Release|x86.Build.0 = Release|Any CPU
525+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
526+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Debug|Any CPU.Build.0 = Debug|Any CPU
527+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Debug|x64.ActiveCfg = Debug|Any CPU
528+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Debug|x64.Build.0 = Debug|Any CPU
529+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Debug|x86.ActiveCfg = Debug|Any CPU
530+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Debug|x86.Build.0 = Debug|Any CPU
531+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Release|Any CPU.ActiveCfg = Release|Any CPU
532+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Release|Any CPU.Build.0 = Release|Any CPU
533+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Release|x64.ActiveCfg = Release|Any CPU
534+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Release|x64.Build.0 = Release|Any CPU
535+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Release|x86.ActiveCfg = Release|Any CPU
536+
{E9A1A414-3117-41D9-990E-ABA5D910B19C}.Release|x86.Build.0 = Release|Any CPU
523537
EndGlobalSection
524538
EndGlobal
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#nullable disable warnings
2+
// Complete the body of the function shown below
3+
// The input of the function accepts one argument
4+
// a: Array of type integer of size between 2 and 2^31
5+
// the array contains a sequence starting from 0 and the following progression
6+
// [0,2,4,6,8,10 ... ]
7+
// The array contains one missing number for example: [0,2,4,6,10,12] is missing 8
8+
// Write a function that returns the missing number.
9+
//
10+
// Examples:
11+
// a = [0,2,4,8,10], result = 6
12+
// a = [0,2,4,6,10], result = 8
13+
// a = [2,4,6], result = 0
14+
15+
using System.Diagnostics;
16+
17+
namespace Q_Missing_Plus_Two {
18+
19+
public class Q_Missing_Plus_Two {
20+
public static void Run() {
21+
var tests = new List<Test> {
22+
new Test {
23+
Id = 1,
24+
Array = new int[] { 0, 2, 4, 8, 10 },
25+
Expected = 6
26+
},
27+
new Test {
28+
Id = 2,
29+
Array = new int[] { 0, 2, 4, 6, 10 },
30+
Expected = 8
31+
},
32+
new Test {
33+
Id = 3,
34+
Array = new int[] { 2, 4, 6 },
35+
Expected = 0
36+
}
37+
};
38+
39+
foreach (var test in tests) {
40+
var num = Solution(test.Array);
41+
test.Verify(num);
42+
}
43+
}
44+
45+
private static int Solution(int[] a) {
46+
int result = 0;
47+
48+
foreach (var num in a) {
49+
if (num != result) {
50+
break;
51+
}
52+
53+
result += 2;
54+
}
55+
56+
return result;
57+
}
58+
}
59+
60+
internal class Test {
61+
public int[] Array { get; set; }
62+
public int Expected { get; set; }
63+
public int Id { get; set; }
64+
65+
public void Verify(int num) {
66+
Debug.Assert(num == Expected, $"Test {Id} failed. {num} != {Expected}");
67+
}
68+
}
69+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

Run/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
namespace Run {
22
class Program {
33
static void Main(string[] args) {
4+
Q_Missing_Plus_Two.Q_Missing_Plus_Two.Run();
5+
46
// Q10_Regular_Expression_Matching.Q10_Regular_Expression_Matching.Run();
57
// Q23_Merge_K_Sorted_Lists.Q23_Merge_K_Sorted_Lists.Run();
68
// Q29_Divide_Two_Integers.Q29_Divide_Two_Integers.Run();
@@ -22,7 +24,7 @@ static void Main(string[] args) {
2224
// Q297_Serialize_Deserialize_Binary_Tree.Q297_Serialize_Deserialize_Binary_Tree.Run();
2325
// Q316_Remove_Duplicate_Letters.Q316_Remove_Duplocate_Letters.Run();
2426
// Q383_Ransom_Note.Ransom_Note.Run();
25-
Q387_First_Unique_Character_In_a_String.Q387_First_Unique_Character_In_a_String.Run();
27+
// Q387_First_Unique_Character_In_a_String.Q387_First_Unique_Character_In_a_String.Run();
2628
// Q523_Continuous_Subarray_Sum.Q523_Continuous_Subarray_Sum.Run();
2729
// Q528_Random_Pick_with_Weight.Q528_Random_Pick_with_Weight.Run();
2830
// Q621_Task_Scheduler.Q621_Task_Scheduler.Run();

Run/Run.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<ProjectReference Include="..\Q211_Design_Add_Search_Words_Data_Structure\Q211_Design_Add_Search_Words_Data_Structure.csproj" />
3838
<ProjectReference Include="..\Q189_Rotate_Array\Q189_Rotate_Array.csproj" />
3939
<ProjectReference Include="..\Q387_First_Unique_Character_In_a_String\Q387_First_Unique_Character_In_a_String.csproj" />
40+
<ProjectReference Include="..\Q_Missing_Plus_Two\Q_Missing_Plus_Two.csproj" />
4041
</ItemGroup>
4142

4243
<PropertyGroup>

Run/obj/Run.csproj.nuget.dgspec.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,58 @@
19641964
}
19651965
}
19661966
},
1967+
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q_Missing_Plus_Two/Q_Missing_Plus_Two.csproj": {
1968+
"version": "1.0.0",
1969+
"restore": {
1970+
"projectUniqueName": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q_Missing_Plus_Two/Q_Missing_Plus_Two.csproj",
1971+
"projectName": "Q_Missing_Plus_Two",
1972+
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q_Missing_Plus_Two/Q_Missing_Plus_Two.csproj",
1973+
"packagesPath": "/Users/Bogdan/.nuget/packages/",
1974+
"outputPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q_Missing_Plus_Two/obj/",
1975+
"projectStyle": "PackageReference",
1976+
"configFilePaths": [
1977+
"/Users/Bogdan/.nuget/NuGet/NuGet.Config"
1978+
],
1979+
"originalTargetFrameworks": [
1980+
"net6.0"
1981+
],
1982+
"sources": {
1983+
"https://api.nuget.org/v3/index.json": {}
1984+
},
1985+
"frameworks": {
1986+
"net6.0": {
1987+
"targetAlias": "net6.0",
1988+
"projectReferences": {}
1989+
}
1990+
},
1991+
"warningProperties": {
1992+
"warnAsError": [
1993+
"NU1605"
1994+
]
1995+
}
1996+
},
1997+
"frameworks": {
1998+
"net6.0": {
1999+
"targetAlias": "net6.0",
2000+
"imports": [
2001+
"net461",
2002+
"net462",
2003+
"net47",
2004+
"net471",
2005+
"net472",
2006+
"net48"
2007+
],
2008+
"assetTargetFallback": true,
2009+
"warn": true,
2010+
"frameworkReferences": {
2011+
"Microsoft.NETCore.App": {
2012+
"privateAssets": "all"
2013+
}
2014+
},
2015+
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/6.0.202/RuntimeIdentifierGraph.json"
2016+
}
2017+
}
2018+
},
19672019
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Run/Run.csproj": {
19682020
"version": "1.0.0",
19692021
"restore": {
@@ -2093,6 +2145,9 @@
20932145
},
20942146
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q986_Interval_List_Intersections/Q986_Interval_List_Intersections.csproj": {
20952147
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q986_Interval_List_Intersections/Q986_Interval_List_Intersections.csproj"
2148+
},
2149+
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q_Missing_Plus_Two/Q_Missing_Plus_Two.csproj": {
2150+
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q_Missing_Plus_Two/Q_Missing_Plus_Two.csproj"
20962151
}
20972152
}
20982153
}

Run/obj/project.assets.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,16 @@
427427
"runtime": {
428428
"bin/placeholder/Q986_Interval_List_Intersections.dll": {}
429429
}
430+
},
431+
"Q_Missing_Plus_Two/1.0.0": {
432+
"type": "project",
433+
"framework": ".NETCoreApp,Version=v6.0",
434+
"compile": {
435+
"bin/placeholder/Q_Missing_Plus_Two.dll": {}
436+
},
437+
"runtime": {
438+
"bin/placeholder/Q_Missing_Plus_Two.dll": {}
439+
}
430440
}
431441
}
432442
},
@@ -610,6 +620,11 @@
610620
"type": "project",
611621
"path": "../Q986_Interval_List_Intersections/Q986_Interval_List_Intersections.csproj",
612622
"msbuildProject": "../Q986_Interval_List_Intersections/Q986_Interval_List_Intersections.csproj"
623+
},
624+
"Q_Missing_Plus_Two/1.0.0": {
625+
"type": "project",
626+
"path": "../Q_Missing_Plus_Two/Q_Missing_Plus_Two.csproj",
627+
"msbuildProject": "../Q_Missing_Plus_Two/Q_Missing_Plus_Two.csproj"
613628
}
614629
},
615630
"projectFileDependencyGroups": {
@@ -649,7 +664,8 @@
649664
"Q71_Simplify_Path >= 1.0.0",
650665
"Q76_Minimum_WIndow_Substring >= 1.0.0",
651666
"Q973_K_Closest_Points_To_Origin >= 1.0.0",
652-
"Q986_Interval_List_Intersections >= 1.0.0"
667+
"Q986_Interval_List_Intersections >= 1.0.0",
668+
"Q_Missing_Plus_Two >= 1.0.0"
653669
]
654670
},
655671
"packageFolders": {
@@ -784,6 +800,9 @@
784800
},
785801
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q986_Interval_List_Intersections/Q986_Interval_List_Intersections.csproj": {
786802
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q986_Interval_List_Intersections/Q986_Interval_List_Intersections.csproj"
803+
},
804+
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q_Missing_Plus_Two/Q_Missing_Plus_Two.csproj": {
805+
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Q_Missing_Plus_Two/Q_Missing_Plus_Two.csproj"
787806
}
788807
}
789808
}

Run/obj/project.nuget.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": 2,
3-
"dgSpecHash": "kAR52NfcaOxBNgBTk7lVzcz7yMJ8tjQhvcBOEy7R3+DR7iAnJSBBIRFnyOSt7BMJRz5u+77RpMy8vvXZE7V2LQ==",
3+
"dgSpecHash": "KycI5MnNcIyTqGUw3BR7dywmtw3tvigXcCbFZzBnW0o3lc6shU6dJXOAxly3aMe+0OizAi/3Af5KJTywDehxoQ==",
44
"success": true,
55
"projectFilePath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Run/Run.csproj",
66
"expectedPackageFiles": [],

0 commit comments

Comments
 (0)