Judge process maybe has a problem

  • 0

    Here is the code cause the problem.

    The result is TLE, but it's the judge process cost the time, not the code itself.

    I think result should be wrong answer not TLE.

    If uncomment the two lines, code is accepted.

    Sorry for my poor English.

    class Solution:
        # @param head, a ListNode
        # @param k, an integer
        # @return a ListNode
        def rotateRight(self, head, k):
            if head is None or head.next is None or k == 0:
                return head
            i = 1
            t = head
            while (t.next != None):
                i = i + 1
                t = t.next
            t.next = head
            k = i - (k%i)
            for i in range(k-1):
                head = head.next
    #       t = head
            head = head.next
    #       t.next = None
            return head

  • 0

    I've tested your codes and got TLE with the last executed input: {1,2}, 1.

    I believe that the cause of TLE is because you did not ground the node---- the last node should refer to NULL.

    For the tested input: {1,2}, 1,
    the output of your codes is 1->2, and 2 is referred to back 1,
    while the correct output should be 2->1->NULL.

    Your TLE can be fixed by simply adding "head.next.next=None" above the last line.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.