Beispiel #1
0
        public void TestMethod1(int[] head, int k, int[] expected)
        {
            // Arrange
            RotateList question = new RotateList();
            ListNode   headList = null;

            if (head != null && head.Length > 0)
            {
                headList = new ListNode(head[0]);
                ListNode node = headList;

                for (int i = 1; i < head.Length; i++)
                {
                    node.next = new ListNode(head[i]);
                    node      = node.next;
                }
            }

            // Act
            ListNode   actual     = question.RotateRight(headList, k);
            List <int> actualList = null;

            if (actual != null)
            {
                actualList = new List <int>();
                while (actual != null)
                {
                    actualList.Add(actual.val);
                    actual = actual.next;
                }
            }

            // Assert
            CollectionAssert.AreEqual(expected, actualList?.ToArray());
        }
Beispiel #2
0
        public void Given_123_When_rotate_0_Then_123()
        {
            var list = new ListNode(1)
            {
                next = new ListNode(2)
                {
                    next = new ListNode(3)
                }
            };

            var result = RotateList.RotateRight(list, 0);

            Assert.AreEqual(1, result.val);
            Assert.AreEqual(2, result.next.val);
            Assert.AreEqual(3, result.next.next.val);
        }