Untitled

mail@pastecode.io avatar
unknown
csharp
2 months ago
658 B
5
Indexable
Never
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);
        }
Leave a Comment