Untitled
unknown
csharp
2 years ago
658 B
11
Indexable
public static bool IsTowNums(Node<int> p)
{
if (p == null || !p.HasNext())
{
return false;
}
//saving the two first nums in an array
int[] nums = { p.GetValue(), p.GetNext().GetValue() };
p = p.GetNext().GetNext();
int count = 0;
while (p != null)
{
if (p.GetValue() != nums[count%2])
{
return false;
}
count++;
p = p.GetNext();
}
return (count > 0 && count%2 == 0);
}Editor is loading...
Leave a Comment