Skip to content
Merged
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
33 changes: 33 additions & 0 deletions csharp/0028-find-the-index-of-the-first-occurrence-in-a-string.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class Solution
{
public int StrStr(string haystack, string needle)
{
if (needle.Length > haystack.Length) return -1;

int l = 0;
int r = needle.Length - 1;

while (r < haystack.Length)
{
bool areEqual = true;
for (int i = l, j = 0; i <= r; i++, j++)
{
if (haystack[i] != needle[j])
{
areEqual = false;
break;
}
}

if (areEqual)
{
return l;
}

l++;
r++;
}

return -1;
}
}
26 changes: 26 additions & 0 deletions csharp/2215-find-the-difference-of-two-arrays.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Solution
{
public IList<IList<int>> FindDifference(int[] nums1, int[] nums2)
{
HashSet<int> set1 = new HashSet<int>(nums1);
HashSet<int> set2 = new HashSet<int>(nums2);

IList<IList<int>> res = new List<IList<int>>() { new List<int>(), new List<int>() };

foreach (var el in set1)
{
if (set2.Contains(el)) continue;

res[0].Add(el);
}

foreach (var el in set2)
{
if (set1.Contains(el)) continue;

res[1].Add(el);
}

return res;
}
}