This commit is contained in:
Electrominch
2022-10-08 01:07:50 +03:00
parent 5cae083979
commit c019e8856c
13 changed files with 271 additions and 7 deletions

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_141._Linked_List_Cycle</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,14 @@
namespace _141._Linked_List_Cycle;
//Definition for singly-linked list.
public class ListNode
{
public int val;
public ListNode? next;
public ListNode(int x)
{
val = x;
next = null;
}
}

View File

@@ -0,0 +1,9 @@
namespace _141._Linked_List_Cycle;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}

View File

@@ -0,0 +1,23 @@
namespace _141._Linked_List_Cycle;
public class Solution
{
public bool HasCycle(ListNode head)
{
if (head == null)
return false;
ListNode? cur = head;
int bit = 1 << 28;
int curAbs = 0;
while (cur != null && (curAbs & bit) == 0)
{
cur.val ^= bit;
cur = cur.next;
if (cur != null)
curAbs = cur.val < 0 ? (cur.val * -1) : cur.val;
}
if ((curAbs & bit) != 0)
return true;
return false;
}
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_19._Remove_Nth_Node_From_End_of_List</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,37 @@
namespace _19._Remove_Nth_Node_From_End_of_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<int> list = new List<int>();
ListNode? cur = this;
while (cur != null)
{
list.Add(cur.val);
cur = cur.next;
}
return String.Join(" ", list);
}
}

View File

@@ -0,0 +1,18 @@
namespace _19._Remove_Nth_Node_From_End_of_List;
internal class Program
{
static void Main(string[] args)
{
ListNode l1 = new ListNode(1);
ListNode l2 = new ListNode(2);
ListNode l3 = new ListNode(3);
ListNode l4 = new ListNode(4);
//l1.next = l2;
//l2.next = l3;
//l3.next = l4;
Console.WriteLine(new Solution().RemoveNthFromEnd(l1, 1));
}
}

View File

@@ -0,0 +1,29 @@
namespace _19._Remove_Nth_Node_From_End_of_List;
public class Solution
{
public ListNode? RemoveNthFromEnd(ListNode head, int n)
{
if (head.next == null)
return null;
ListNode? left = null;
ListNode? right = head;
n--;
while (n-- > 0)
right = right!.next;
while (right!.next != null)
{
if (left == null)
left = head;
else
left = left.next;
right = right.next;
}
if (left != null)
{
left.next = left.next!.next;
return head;
}
return head.next;
}
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_203._Remove_Linked_List_Elements</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,37 @@
namespace _203._Remove_Linked_List_Elements;
//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<int> list = new List<int>();
ListNode? cur = this;
while (cur != null)
{
list.Add(cur.val);
cur = cur.next;
}
return String.Join(" ", list);
}
}

View File

@@ -0,0 +1,17 @@
namespace _203._Remove_Linked_List_Elements;
internal class Program
{
static void Main(string[] args)
{
ListNode l1 = new ListNode(1);
ListNode l2 = new ListNode(2);
ListNode l3 = new ListNode(3);
ListNode l4 = new ListNode(4);
l1.next = l2;
l2.next = l3;
l3.next = l4;
Console.WriteLine(new Solution().RemoveElements(l1, 3));
}
}

View File

@@ -0,0 +1,29 @@
namespace _203._Remove_Linked_List_Elements;
public class Solution
{
public ListNode? RemoveElements(ListNode? head, int val)
{
ListNode? first = null;
ListNode? current = null;
while (head != null)
{
if (head.val == val)
{
head = head.next;
continue;
}
if (first == null)
first = current = head;
else
{
current!.next = head;
current = current.next;
}
var buf = head;
head = head.next;
buf.next = null;
}
return first;
}
}

View File

@@ -57,19 +57,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "409. Longest Palindrome", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "36. Valid Sudoku", "36. Valid Sudoku\36. Valid Sudoku.csproj", "{C1759C38-D2E4-4869-B6C2-259B26586E11}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "344. Reverse String", "344. Reverse String\344. Reverse String.csproj", "{65D5229E-6D7D-41D2-BB68-2EBA40E9DCE3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "344. Reverse String", "344. Reverse String\344. Reverse String.csproj", "{65D5229E-6D7D-41D2-BB68-2EBA40E9DCE3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "557. Reverse Words in a String III", "557. Reverse Words in a String III\557. Reverse Words in a String III.csproj", "{B3E1C7CD-0992-49BB-B44A-E129912763DB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "557. Reverse Words in a String III", "557. Reverse Words in a String III\557. Reverse Words in a String III.csproj", "{B3E1C7CD-0992-49BB-B44A-E129912763DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "387. First Unique Character in a String", "387. First Unique Character in a String\387. First Unique Character in a String.csproj", "{3B479362-7079-4112-AFA1-3C344E83C8C2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "387. First Unique Character in a String", "387. First Unique Character in a String\387. First Unique Character in a String.csproj", "{3B479362-7079-4112-AFA1-3C344E83C8C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "383. Ransom Note", "383. Ransom Note\383. Ransom Note.csproj", "{6F43E7FE-AD78-47D6-86FA-33B42DC55882}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "383. Ransom Note", "383. Ransom Note\383. Ransom Note.csproj", "{6F43E7FE-AD78-47D6-86FA-33B42DC55882}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "242. Valid Anagram", "242. Valid Anagram\242. Valid Anagram.csproj", "{FBD8C83E-D3F9-4CE3-B5DD-9C326CBC692C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "242. Valid Anagram", "242. Valid Anagram\242. Valid Anagram.csproj", "{FBD8C83E-D3F9-4CE3-B5DD-9C326CBC692C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "589. N-ary Tree Preorder Traversal", "589. N-ary Tree Preorder Traversal\589. N-ary Tree Preorder Traversal.csproj", "{4A8355E0-FF05-4DF3-B735-4B11BEAD95C5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "589. N-ary Tree Preorder Traversal", "589. N-ary Tree Preorder Traversal\589. N-ary Tree Preorder Traversal.csproj", "{4A8355E0-FF05-4DF3-B735-4B11BEAD95C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "102. Binary Tree Level Order Traversal", "102. Binary Tree Level Order Traversal\102. Binary Tree Level Order Traversal.csproj", "{557D8195-C886-4B52-BBC4-285A1C1057FF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "102. Binary Tree Level Order Traversal", "102. Binary Tree Level Order Traversal\102. Binary Tree Level Order Traversal.csproj", "{557D8195-C886-4B52-BBC4-285A1C1057FF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "141. Linked List Cycle", "141. Linked List Cycle\141. Linked List Cycle.csproj", "{EC089303-B1E1-482F-BAED-530DAB4C1346}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "203. Remove Linked List Elements", "203. Remove Linked List Elements\203. Remove Linked List Elements.csproj", "{F2C5A71D-91C7-4270-8150-8D96DA73538C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "19. Remove Nth Node From End of List", "19. Remove Nth Node From End of List\19. Remove Nth Node From End of List.csproj", "{88473211-C7AD-4F83-92C2-D4E6B9BB9D8A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -213,6 +219,18 @@ Global
{557D8195-C886-4B52-BBC4-285A1C1057FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{557D8195-C886-4B52-BBC4-285A1C1057FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{557D8195-C886-4B52-BBC4-285A1C1057FF}.Release|Any CPU.Build.0 = Release|Any CPU
{EC089303-B1E1-482F-BAED-530DAB4C1346}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC089303-B1E1-482F-BAED-530DAB4C1346}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC089303-B1E1-482F-BAED-530DAB4C1346}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC089303-B1E1-482F-BAED-530DAB4C1346}.Release|Any CPU.Build.0 = Release|Any CPU
{F2C5A71D-91C7-4270-8150-8D96DA73538C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2C5A71D-91C7-4270-8150-8D96DA73538C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2C5A71D-91C7-4270-8150-8D96DA73538C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2C5A71D-91C7-4270-8150-8D96DA73538C}.Release|Any CPU.Build.0 = Release|Any CPU
{88473211-C7AD-4F83-92C2-D4E6B9BB9D8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88473211-C7AD-4F83-92C2-D4E6B9BB9D8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88473211-C7AD-4F83-92C2-D4E6B9BB9D8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88473211-C7AD-4F83-92C2-D4E6B9BB9D8A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE