Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CodeWars/Array-diff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections;
using System.Collections.Generic;

public class Kata
{
public static int[] ArrayDiff(int[] a, int[] b)
{
var hashSet = new HashSet<int>(b);
var response = new List<int>();

foreach (var x in a)
{
if (!hashSet.Contains(x))
{
response.Add(x);
}
}

return response.ToArray();
}
}
48 changes: 48 additions & 0 deletions CodeWars/LinkedLists-InsertNthNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;

public partial class Node
{
public int Data;
public Node Next;

public Node(int data)
{
this.Data = data;
this.Next = null;
}

public static Node InsertNth(Node head, int index, int data)
{

if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index), "Index is out of the range of the list.");

var newNode = new Node(data);

if (index == 0)
{
newNode.Next = head;
return newNode;
}

var current = head;
int count = 0;

while (current != null && count < index - 1)
{
current = current.Next;
count++;
}

if (current == null)
{
throw new ArgumentOutOfRangeException(nameof(index), "Index is out of the range of the list.");
}

newNode.Next = current.Next;
current.Next = newNode;

return head;

}
}
34 changes: 34 additions & 0 deletions CodeWars/Parse-a-linked-list-from-a-string.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

public static class Kata
{
public static Node Parse(string nodes)
{
Node head = null;
Node prev = null;
var array = nodes.Split(" -> ");

foreach (var current in array)
{
if (current.Trim() == "null")
break;

var value = int.Parse(current.Trim());

var newNode = new Node(value);

if (head == null)
{
head = newNode;
}
else
{
prev.Next = newNode;
}

prev = newNode;
}

return head;
}
}