From 062e03bdbf0cc489b22925b9c0f642e868751438 Mon Sep 17 00:00:00 2001
From: Electrominch <64524860+Electrominch@users.noreply.github.com>
Date: Wed, 5 Oct 2022 00:44:15 +0300
Subject: [PATCH] Day3. Start Algorithm
---
1. Two Sum/Solution.cs | 10 +----
...21. Best Time to Buy and Sell Stock.csproj | 11 +++++
.../Program.cs | 10 +++++
.../Solution.cs | 27 ++++++++++++
1480. Running Sum of 1d Array/Solution.cs | 12 ++---
205. Isomorphic Strings/Program.cs | 2 +-
205. Isomorphic Strings/Solution.cs | 12 ++---
.../206. Reverse Linked List.csproj | 11 +++++
206. Reverse Linked List/ListNode.cs | 36 +++++++++++++++
206. Reverse Linked List/Program.cs | 11 +++++
206. Reverse Linked List/Solution.cs | 22 ++++++++++
.../21. Merge Two Sorted Lists.csproj | 11 +++++
21. Merge Two Sorted Lists/ListNode.cs | 37 ++++++++++++++++
21. Merge Two Sorted Lists/Program.cs | 12 +++++
21. Merge Two Sorted Lists/Solution.cs | 44 +++++++++++++++++++
.../278. First Bad Version.csproj | 11 +++++
278. First Bad Version/Program.cs | 10 +++++
278. First Bad Version/Solution.cs | 33 ++++++++++++++
.../35. Search Insert Position.csproj | 11 +++++
35. Search Insert Position/Program.cs | 10 +++++
35. Search Insert Position/Solution.cs | 19 ++++++++
.../Solution.cs | 18 ++++++++
392. Is Subsequence/Solution.cs | 10 +----
53. Maximum Subarray/Solution.cs | 2 +-
704. Binary Search/704. Binary Search.csproj | 11 +++++
704. Binary Search/Program.cs | 10 +++++
704. Binary Search/Solution.cs | 22 ++++++++++
724. Find Pivot Index/Program.cs | 2 +-
724. Find Pivot Index/Solution.cs | 10 +----
88. Merge Sorted Array/Program.cs | 4 +-
88. Merge Sorted Array/Solution.cs | 14 +++---
Leetcode.sln | 38 +++++++++++++++-
32 files changed, 446 insertions(+), 57 deletions(-)
create mode 100644 121. Best Time to Buy and Sell Stock/121. Best Time to Buy and Sell Stock.csproj
create mode 100644 121. Best Time to Buy and Sell Stock/Program.cs
create mode 100644 121. Best Time to Buy and Sell Stock/Solution.cs
create mode 100644 206. Reverse Linked List/206. Reverse Linked List.csproj
create mode 100644 206. Reverse Linked List/ListNode.cs
create mode 100644 206. Reverse Linked List/Program.cs
create mode 100644 206. Reverse Linked List/Solution.cs
create mode 100644 21. Merge Two Sorted Lists/21. Merge Two Sorted Lists.csproj
create mode 100644 21. Merge Two Sorted Lists/ListNode.cs
create mode 100644 21. Merge Two Sorted Lists/Program.cs
create mode 100644 21. Merge Two Sorted Lists/Solution.cs
create mode 100644 278. First Bad Version/278. First Bad Version.csproj
create mode 100644 278. First Bad Version/Program.cs
create mode 100644 278. First Bad Version/Solution.cs
create mode 100644 35. Search Insert Position/35. Search Insert Position.csproj
create mode 100644 35. Search Insert Position/Program.cs
create mode 100644 35. Search Insert Position/Solution.cs
create mode 100644 704. Binary Search/704. Binary Search.csproj
create mode 100644 704. Binary Search/Program.cs
create mode 100644 704. Binary Search/Solution.cs
diff --git a/1. Two Sum/Solution.cs b/1. Two Sum/Solution.cs
index 42ae8ed..eaf8570 100644
--- a/1. Two Sum/Solution.cs
+++ b/1. Two Sum/Solution.cs
@@ -1,17 +1,11 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace _1._Two_Sum;
+namespace _1._Two_Sum;
public class Solution
{
public int[]? TwoSum(int[] nums, int target)
{
for (int i = 0; i < nums.Length; i++)
- for (int j = i+1; j < nums.Length; j++)
+ for (int j = i + 1; j < nums.Length; j++)
if (nums[i] + nums[j] == target)
return new int[] { i, j };
return null;
diff --git a/121. Best Time to Buy and Sell Stock/121. Best Time to Buy and Sell Stock.csproj b/121. Best Time to Buy and Sell Stock/121. Best Time to Buy and Sell Stock.csproj
new file mode 100644
index 0000000..358c9bf
--- /dev/null
+++ b/121. Best Time to Buy and Sell Stock/121. Best Time to Buy and Sell Stock.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Exe
+ net6.0
+ _121._Best_Time_to_Buy_and_Sell_Stock
+ enable
+ enable
+
+
+
diff --git a/121. Best Time to Buy and Sell Stock/Program.cs b/121. Best Time to Buy and Sell Stock/Program.cs
new file mode 100644
index 0000000..497a3f9
--- /dev/null
+++ b/121. Best Time to Buy and Sell Stock/Program.cs
@@ -0,0 +1,10 @@
+namespace _121._Best_Time_to_Buy_and_Sell_Stock
+{
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine(new Solution().MaxProfit(new int[] { 7, 1, 5, 3, 6, 4 }));
+ }
+ }
+}
\ No newline at end of file
diff --git a/121. Best Time to Buy and Sell Stock/Solution.cs b/121. Best Time to Buy and Sell Stock/Solution.cs
new file mode 100644
index 0000000..cbf6325
--- /dev/null
+++ b/121. Best Time to Buy and Sell Stock/Solution.cs
@@ -0,0 +1,27 @@
+namespace _121._Best_Time_to_Buy_and_Sell_Stock;
+
+public class Solution
+{
+ public int MaxProfit(int[] prices)
+ {
+ int min = prices[0];
+ int max = prices[0];
+ bool hasMax = false;
+ int res = 0;
+ foreach (int price in prices)
+ {
+ if (price > max || hasMax == false)
+ {
+ max = price;
+ hasMax = true;
+ res = Math.Max(max - min, res);
+ }
+ if (price < min)
+ {
+ min = price;
+ hasMax = false;
+ }
+ }
+ return res > 0 ? res : 0;
+ }
+}
diff --git a/1480. Running Sum of 1d Array/Solution.cs b/1480. Running Sum of 1d Array/Solution.cs
index 3fb8162..e424fb9 100644
--- a/1480. Running Sum of 1d Array/Solution.cs
+++ b/1480. Running Sum of 1d Array/Solution.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace _1480._Running_Sum_of_1d_Array;
+namespace _1480._Running_Sum_of_1d_Array;
public class Solution
{
@@ -12,8 +6,8 @@ public class Solution
{
int[] result = new int[nums.Length];
result[0] = nums[0];
- for(int i = 1; i < nums.Length; i++)
- result[i] = nums[i] + result[i-1];
+ for (int i = 1; i < nums.Length; i++)
+ result[i] = nums[i] + result[i - 1];
return result;
}
}
diff --git a/205. Isomorphic Strings/Program.cs b/205. Isomorphic Strings/Program.cs
index 82fdd73..dae734d 100644
--- a/205. Isomorphic Strings/Program.cs
+++ b/205. Isomorphic Strings/Program.cs
@@ -4,7 +4,7 @@
{
static void Main(string[] args)
{
- Console.WriteLine(new Solution().IsIsomorphic("egg","foo"));
+ Console.WriteLine(new Solution().IsIsomorphic("egg", "foo"));
}
}
}
\ No newline at end of file
diff --git a/205. Isomorphic Strings/Solution.cs b/205. Isomorphic Strings/Solution.cs
index 5031c19..10e0341 100644
--- a/205. Isomorphic Strings/Solution.cs
+++ b/205. Isomorphic Strings/Solution.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace _205._Isomorphic_Strings;
+namespace _205._Isomorphic_Strings;
public class Solution
{
@@ -12,13 +6,13 @@ public class Solution
{
Dictionary table = new Dictionary();
Dictionary antiTable = new Dictionary();
- for(int i = 0; i < s.Length; i++)
+ for (int i = 0; i < s.Length; i++)
{
char source = s[i];
char to = t[i];
if (table.ContainsKey(source))
{
- if(table[source] != to)
+ if (table[source] != to)
return false;
}
else
diff --git a/206. Reverse Linked List/206. Reverse Linked List.csproj b/206. Reverse Linked List/206. Reverse Linked List.csproj
new file mode 100644
index 0000000..c24ea45
--- /dev/null
+++ b/206. Reverse Linked List/206. Reverse Linked List.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Exe
+ net6.0
+ _206._Reverse_Linked_List
+ enable
+ enable
+
+
+
diff --git a/206. Reverse Linked List/ListNode.cs b/206. Reverse Linked List/ListNode.cs
new file mode 100644
index 0000000..5b3aa9a
--- /dev/null
+++ b/206. Reverse Linked List/ListNode.cs
@@ -0,0 +1,36 @@
+namespace _206._Reverse_Linked_List;
+//Definition for singly-linked list.
+public class ListNode
+{
+ public int val;
+ public ListNode? next;
+ public ListNode(int val = 0, ListNode? next = null)
+ {
+ this.val = val;
+ this.next = next;
+ }
+
+ public static ListNode Create(int[] nums)
+ {
+ ListNode l = new ListNode(nums[0]);
+ ListNode cur = l;
+ for (int i = 1; i < nums.Length; i++)
+ {
+ cur.next = new ListNode(nums[i]);
+ cur = cur.next;
+ }
+ return l;
+ }
+
+ public override string ToString()
+ {
+ List list = new List();
+ ListNode? cur = this;
+ while (cur != null)
+ {
+ list.Add(cur.val);
+ cur = cur.next;
+ }
+ return String.Join(" ", list);
+ }
+}
diff --git a/206. Reverse Linked List/Program.cs b/206. Reverse Linked List/Program.cs
new file mode 100644
index 0000000..9f6bd6d
--- /dev/null
+++ b/206. Reverse Linked List/Program.cs
@@ -0,0 +1,11 @@
+namespace _206._Reverse_Linked_List
+{
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ var l = ListNode.Create(new int[] { 1 });
+ Console.WriteLine(new Solution().ReverseList(l));
+ }
+ }
+}
\ No newline at end of file
diff --git a/206. Reverse Linked List/Solution.cs b/206. Reverse Linked List/Solution.cs
new file mode 100644
index 0000000..6090f97
--- /dev/null
+++ b/206. Reverse Linked List/Solution.cs
@@ -0,0 +1,22 @@
+namespace _206._Reverse_Linked_List;
+
+public class Solution
+{
+ public ListNode? ReverseList(ListNode head)
+ {
+ if (head == null || head.next == null)
+ return head;
+ ListNode cur = head;
+ ListNode newHead = cur.next!;
+ cur.next = null;
+ while (true)
+ {
+ ListNode? buf = newHead.next;
+ newHead.next = cur;
+ if (buf == null)
+ return newHead;
+ cur = newHead;
+ newHead = buf;
+ }
+ }
+}
diff --git a/21. Merge Two Sorted Lists/21. Merge Two Sorted Lists.csproj b/21. Merge Two Sorted Lists/21. Merge Two Sorted Lists.csproj
new file mode 100644
index 0000000..81b68df
--- /dev/null
+++ b/21. Merge Two Sorted Lists/21. Merge Two Sorted Lists.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Exe
+ net6.0
+ _21._Merge_Two_Sorted_Lists
+ enable
+ enable
+
+
+
diff --git a/21. Merge Two Sorted Lists/ListNode.cs b/21. Merge Two Sorted Lists/ListNode.cs
new file mode 100644
index 0000000..f3edea8
--- /dev/null
+++ b/21. Merge Two Sorted Lists/ListNode.cs
@@ -0,0 +1,37 @@
+namespace _21._Merge_Two_Sorted_Lists;
+
+//Definition for singly-linked list.
+public class ListNode
+{
+ public int val;
+ public ListNode? next;
+ public ListNode(int val = 0, ListNode? next = null)
+ {
+ this.val = val;
+ this.next = next;
+ }
+
+ public static ListNode Create(int[] nums)
+ {
+ ListNode l = new ListNode(nums[0]);
+ ListNode cur = l;
+ for (int i = 1; i < nums.Length; i++)
+ {
+ cur.next = new ListNode(nums[i]);
+ cur = cur.next;
+ }
+ return l;
+ }
+
+ public override string ToString()
+ {
+ List list = new List();
+ ListNode? cur = this;
+ while (cur != null)
+ {
+ list.Add(cur.val);
+ cur = cur.next;
+ }
+ return String.Join(" ", list);
+ }
+}
diff --git a/21. Merge Two Sorted Lists/Program.cs b/21. Merge Two Sorted Lists/Program.cs
new file mode 100644
index 0000000..d22629d
--- /dev/null
+++ b/21. Merge Two Sorted Lists/Program.cs
@@ -0,0 +1,12 @@
+namespace _21._Merge_Two_Sorted_Lists
+{
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ var l1 = ListNode.Create(new int[] { 1, 2, 4 });
+ var l2 = ListNode.Create(new int[] { 1, 3, 4 });
+ Console.WriteLine(new Solution().MergeTwoLists(l1, l2));
+ }
+ }
+}
\ No newline at end of file
diff --git a/21. Merge Two Sorted Lists/Solution.cs b/21. Merge Two Sorted Lists/Solution.cs
new file mode 100644
index 0000000..fae53bb
--- /dev/null
+++ b/21. Merge Two Sorted Lists/Solution.cs
@@ -0,0 +1,44 @@
+namespace _21._Merge_Two_Sorted_Lists;
+
+public class Solution
+{
+ public ListNode MergeTwoLists(ListNode? list1, ListNode? list2)
+ {
+ ListNode? start = null;
+ ListNode? current = null;
+ List listNodes = new List() { list1, list2 };
+ while (listNodes.Any(l => l != null))
+ {
+ int i = MinIndex(listNodes);
+ ListNode? curMin = listNodes[i];
+ listNodes[i] = listNodes[i]!.next;
+
+ if (start == null)
+ {
+ start = curMin;
+ current = start;
+ }
+ else if (current != null)
+ {
+ current.next = curMin;
+ current = current.next;
+ }
+ }
+ return start!;
+ }
+
+ private int MinIndex(List list)
+ {
+ int minValue = int.MaxValue;
+ int index = -1;
+ for (int i = 0; i < list.Count; i++)
+ {
+ if (list[i]?.val < minValue)
+ {
+ minValue = list[i]!.val;
+ index = i;
+ }
+ }
+ return index;
+ }
+}
\ No newline at end of file
diff --git a/278. First Bad Version/278. First Bad Version.csproj b/278. First Bad Version/278. First Bad Version.csproj
new file mode 100644
index 0000000..edabac8
--- /dev/null
+++ b/278. First Bad Version/278. First Bad Version.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Exe
+ net6.0
+ _278._First_Bad_Version
+ enable
+ enable
+
+
+
diff --git a/278. First Bad Version/Program.cs b/278. First Bad Version/Program.cs
new file mode 100644
index 0000000..d16af1e
--- /dev/null
+++ b/278. First Bad Version/Program.cs
@@ -0,0 +1,10 @@
+namespace _278._First_Bad_Version
+{
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine(new Solution().FirstBadVersion(2147483647, 2147483647));
+ }
+ }
+}
\ No newline at end of file
diff --git a/278. First Bad Version/Solution.cs b/278. First Bad Version/Solution.cs
new file mode 100644
index 0000000..168fd99
--- /dev/null
+++ b/278. First Bad Version/Solution.cs
@@ -0,0 +1,33 @@
+namespace _278._First_Bad_Version;
+
+public class VersionControl
+{
+ protected int _badVersion = 0;
+ protected bool IsBadVersion(int version) => version >= _badVersion;
+}
+
+public class Solution : VersionControl
+{
+ public int FirstBadVersion(int n)
+ {
+ long l = -1;
+ long r = n;
+ while (l != r - 1)
+ {
+ long i = (r + l) / 2;
+ bool res = IsBadVersion((int)i);
+ if (res)
+ r = i;
+ else
+ l = i;
+ }
+ return (int)l + 1;
+ }
+
+ public int FirstBadVersion(int n, int bad)
+ {
+ _badVersion = bad;
+ return FirstBadVersion(n);
+ }
+}
+
diff --git a/35. Search Insert Position/35. Search Insert Position.csproj b/35. Search Insert Position/35. Search Insert Position.csproj
new file mode 100644
index 0000000..b0c6506
--- /dev/null
+++ b/35. Search Insert Position/35. Search Insert Position.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Exe
+ net6.0
+ _35._Search_Insert_Position
+ enable
+ enable
+
+
+
diff --git a/35. Search Insert Position/Program.cs b/35. Search Insert Position/Program.cs
new file mode 100644
index 0000000..548b75d
--- /dev/null
+++ b/35. Search Insert Position/Program.cs
@@ -0,0 +1,10 @@
+namespace _35._Search_Insert_Position
+{
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine("Hello, World!");
+ }
+ }
+}
\ No newline at end of file
diff --git a/35. Search Insert Position/Solution.cs b/35. Search Insert Position/Solution.cs
new file mode 100644
index 0000000..b5105fd
--- /dev/null
+++ b/35. Search Insert Position/Solution.cs
@@ -0,0 +1,19 @@
+namespace _35._Search_Insert_Position;
+
+public class Solution
+{
+ public int SearchInsert(int[] nums, int target)
+ {
+ int l = -1;
+ int r = nums.Length;
+ while (l != r - 1)
+ {
+ int i = (r + l) / 2;
+ if (nums[i] >= target)
+ r = i;
+ else
+ l = i;
+ }
+ return l + 1;
+ }
+}
\ No newline at end of file
diff --git a/350. Intersection of Two Arrays II/Solution.cs b/350. Intersection of Two Arrays II/Solution.cs
index ac4bef1..7a24cce 100644
--- a/350. Intersection of Two Arrays II/Solution.cs
+++ b/350. Intersection of Two Arrays II/Solution.cs
@@ -4,6 +4,24 @@ public class Solution
{
public int[] Intersect(int[] nums1, int[] nums2)
{
+ List result = new List();
+ Dictionary table = new Dictionary();
+ foreach (int n in nums1)
+ {
+ if (table.ContainsKey(n))
+ table[n]++;
+ else
+ table.Add(n, 1);
+ }
+ foreach (int n in nums2)
+ {
+ if (table.ContainsKey(n) && table[n] > 0)
+ {
+ result.Add(n);
+ table[n]--;
+ }
+ }
+ return result.ToArray();
}
}
diff --git a/392. Is Subsequence/Solution.cs b/392. Is Subsequence/Solution.cs
index 20a2152..69ea037 100644
--- a/392. Is Subsequence/Solution.cs
+++ b/392. Is Subsequence/Solution.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace _392._Is_Subsequence;
+namespace _392._Is_Subsequence;
public class Solution
{
@@ -13,7 +7,7 @@ public class Solution
if (s.Length == 0)
return true;
int sIndex = 0;
- for(int i = 0; i < t.Length; i++)
+ for (int i = 0; i < t.Length; i++)
{
if (t[i] == s[sIndex])
{
diff --git a/53. Maximum Subarray/Solution.cs b/53. Maximum Subarray/Solution.cs
index 617632e..3f657d8 100644
--- a/53. Maximum Subarray/Solution.cs
+++ b/53. Maximum Subarray/Solution.cs
@@ -6,7 +6,7 @@ public class Solution
{
int best_sum = int.MinValue;
int current_sum = 0;
- foreach(var x in nums)
+ foreach (var x in nums)
{
current_sum = Math.Max(x, current_sum + x);
best_sum = Math.Max(best_sum, current_sum);
diff --git a/704. Binary Search/704. Binary Search.csproj b/704. Binary Search/704. Binary Search.csproj
new file mode 100644
index 0000000..14b3774
--- /dev/null
+++ b/704. Binary Search/704. Binary Search.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Exe
+ net6.0
+ _704._Binary_Search
+ enable
+ enable
+
+
+
diff --git a/704. Binary Search/Program.cs b/704. Binary Search/Program.cs
new file mode 100644
index 0000000..f70ea71
--- /dev/null
+++ b/704. Binary Search/Program.cs
@@ -0,0 +1,10 @@
+namespace _704._Binary_Search
+{
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine(new Solution().Search(new int[] { -1, 0, 3, 5, 9, 12 }, 13));
+ }
+ }
+}
\ No newline at end of file
diff --git a/704. Binary Search/Solution.cs b/704. Binary Search/Solution.cs
new file mode 100644
index 0000000..514d448
--- /dev/null
+++ b/704. Binary Search/Solution.cs
@@ -0,0 +1,22 @@
+namespace _704._Binary_Search;
+
+public class Solution
+{
+ public int Search(int[] nums, int target)
+ {
+ int l = -1;
+ int r = nums.Length;
+ while (l < r - 1)
+ {
+ int i = l + (r - l) / 2;
+ int cur = nums[i];
+ if (cur == target)
+ return i;
+ if (cur > target)
+ r = i;
+ else
+ l = i;
+ }
+ return -1;
+ }
+}
diff --git a/724. Find Pivot Index/Program.cs b/724. Find Pivot Index/Program.cs
index 7804de2..360e9f2 100644
--- a/724. Find Pivot Index/Program.cs
+++ b/724. Find Pivot Index/Program.cs
@@ -5,7 +5,7 @@
static void Main(string[] args)
{
Solution sol = new Solution();
- sol.PivotIndex(new int[] { 1,4,2});
+ sol.PivotIndex(new int[] { 1, 4, 2 });
}
}
}
\ No newline at end of file
diff --git a/724. Find Pivot Index/Solution.cs b/724. Find Pivot Index/Solution.cs
index e7c1c7b..a2927ae 100644
--- a/724. Find Pivot Index/Solution.cs
+++ b/724. Find Pivot Index/Solution.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace _724._Find_Pivot_Index;
+namespace _724._Find_Pivot_Index;
public class Solution
{
@@ -12,7 +6,7 @@ public class Solution
{
int[] sumsFromLeft = new int[nums.Length];
int[] sumsFromRight = new int[nums.Length];
- for(int i = 1; i < nums.Length; i++)
+ for (int i = 1; i < nums.Length; i++)
sumsFromLeft[i] = nums[i - 1] + sumsFromLeft[i - 1];
for (int i = nums.Length - 2; i >= 0; i--)
diff --git a/88. Merge Sorted Array/Program.cs b/88. Merge Sorted Array/Program.cs
index 364137e..2aab37f 100644
--- a/88. Merge Sorted Array/Program.cs
+++ b/88. Merge Sorted Array/Program.cs
@@ -4,8 +4,8 @@
{
static void Main(string[] args)
{
- int[] n1 = new int[] { 1, 2, 3, 0, 0, 0 };
- int[] n2 = new int[] { 2,5,6 };
+ int[] n1 = new int[] { 1, 2, 3, 0, 0, 0 };
+ int[] n2 = new int[] { 2, 5, 6 };
Solution solution = new Solution();
solution.Merge(n1, 3, n2, n2.Length);
Console.WriteLine(String.Join(" ", n1));
diff --git a/88. Merge Sorted Array/Solution.cs b/88. Merge Sorted Array/Solution.cs
index 75ac69e..85afb4f 100644
--- a/88. Merge Sorted Array/Solution.cs
+++ b/88. Merge Sorted Array/Solution.cs
@@ -1,15 +1,11 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace _88._Merge_Sorted_Array;
+namespace _88._Merge_Sorted_Array;
public class Solution
{
public void Merge(int[] nums1, int m, int[] a2, int n)
{
int[] a1 = new int[m];
- for(int i = 0; i < m; i++)
+ for (int i = 0; i < m; i++)
a1[i] = nums1[i];
int resIndex = 0;
int a1Index = 0, a2Index = 0;
@@ -20,18 +16,18 @@ public class Solution
int toWrite = 0;
if (n1 != null && n2 != null)
{
- toWrite = Math.Min(n1.Value,n2.Value);
+ toWrite = Math.Min(n1.Value, n2.Value);
if (n1 < n2)
a1Index++;
else
a2Index++;
}
- else if(n1!=null)
+ else if (n1 != null)
{
toWrite = n1.Value;
a1Index++;
}
- else if(n2!=null)
+ else if (n2 != null)
{
toWrite = n2.Value;
a2Index++;
diff --git a/Leetcode.sln b/Leetcode.sln
index 6672cd0..c498d02 100644
--- a/Leetcode.sln
+++ b/Leetcode.sln
@@ -19,7 +19,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "205. Isomorphic Strings", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "392. Is Subsequence", "392. Is Subsequence\392. Is Subsequence.csproj", "{82D9F372-85D0-4293-932D-6F90D4AF9CBD}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "350. Intersection of Two Arrays II", "350. Intersection of Two Arrays II\350. Intersection of Two Arrays II.csproj", "{3EDA43F9-22B1-4CFE-9912-031FFAA2200E}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "350. Intersection of Two Arrays II", "350. Intersection of Two Arrays II\350. Intersection of Two Arrays II.csproj", "{3EDA43F9-22B1-4CFE-9912-031FFAA2200E}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "121. Best Time to Buy and Sell Stock", "121. Best Time to Buy and Sell Stock\121. Best Time to Buy and Sell Stock.csproj", "{79A12189-DF47-4F0B-ADB1-A5FD930AE7EB}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "21. Merge Two Sorted Lists", "21. Merge Two Sorted Lists\21. Merge Two Sorted Lists.csproj", "{3063143F-AAF9-4B23-8D98-A7236E01AA27}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "206. Reverse Linked List", "206. Reverse Linked List\206. Reverse Linked List.csproj", "{1C1BEA62-325F-48F8-8CC0-D5828A62F14F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "704. Binary Search", "704. Binary Search\704. Binary Search.csproj", "{69081812-D523-4211-AE09-9DAF8E9B83D8}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "278. First Bad Version", "278. First Bad Version\278. First Bad Version.csproj", "{3BA31E13-3748-4C4A-BE68-24D2E3DF0DC1}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "35. Search Insert Position", "35. Search Insert Position\35. Search Insert Position.csproj", "{B595BB51-666D-4E39-86EE-F9A3B8D8DA58}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -63,6 +75,30 @@ Global
{3EDA43F9-22B1-4CFE-9912-031FFAA2200E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3EDA43F9-22B1-4CFE-9912-031FFAA2200E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3EDA43F9-22B1-4CFE-9912-031FFAA2200E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {79A12189-DF47-4F0B-ADB1-A5FD930AE7EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {79A12189-DF47-4F0B-ADB1-A5FD930AE7EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {79A12189-DF47-4F0B-ADB1-A5FD930AE7EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {79A12189-DF47-4F0B-ADB1-A5FD930AE7EB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3063143F-AAF9-4B23-8D98-A7236E01AA27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3063143F-AAF9-4B23-8D98-A7236E01AA27}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3063143F-AAF9-4B23-8D98-A7236E01AA27}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3063143F-AAF9-4B23-8D98-A7236E01AA27}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1C1BEA62-325F-48F8-8CC0-D5828A62F14F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1C1BEA62-325F-48F8-8CC0-D5828A62F14F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1C1BEA62-325F-48F8-8CC0-D5828A62F14F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1C1BEA62-325F-48F8-8CC0-D5828A62F14F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {69081812-D523-4211-AE09-9DAF8E9B83D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {69081812-D523-4211-AE09-9DAF8E9B83D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {69081812-D523-4211-AE09-9DAF8E9B83D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {69081812-D523-4211-AE09-9DAF8E9B83D8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3BA31E13-3748-4C4A-BE68-24D2E3DF0DC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3BA31E13-3748-4C4A-BE68-24D2E3DF0DC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3BA31E13-3748-4C4A-BE68-24D2E3DF0DC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3BA31E13-3748-4C4A-BE68-24D2E3DF0DC1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B595BB51-666D-4E39-86EE-F9A3B8D8DA58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B595BB51-666D-4E39-86EE-F9A3B8D8DA58}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B595BB51-666D-4E39-86EE-F9A3B8D8DA58}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B595BB51-666D-4E39-86EE-F9A3B8D8DA58}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE