Why do I see different % of solutions that are better than mine when i submit the same code twice ?


  • 0
    V

    Anyways, I have an in-place linked list reversal:

    /**

    • Definition for singly-linked list.

    • struct ListNode {

    • int val;
      
    • ListNode *next;
      
    • ListNode(int x) : val(x), next(NULL) {}
      
    • };
      /
      class Solution {
      public:
      ListNode
      reverseList(ListNode* head) {
      if(head == NULL) { return head; }

       ListNode* nodeNext = head->next, *reversedHead = head, *reverseEnd = head;
       while(nodeNext){
           ListNode* tmp = nodeNext->next;
           nodeNext->next = reversedHead;
           reverseEnd->next = tmp;
           
           reversedHead = nodeNext;
           nodeNext = tmp;
       }
       
       return reversedHead;
      

      }
      };


  • 0

    "Why do I see different % of solutions that are better than mine when i submit the same code twice ?"

    Did the two submissions get the same time or different times? I suspect different times, but then you wouldn't be surprised, so I'm confused.


Log in to reply
 

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