Any better way by C++? Someone handle it only 12ms


  • 0
    K

    /**

    • Definition for singly-linked list.

    • struct ListNode {

    • int val;
      
    • ListNode *next;
      
    • ListNode(int x) : val(x), next(NULL) {}
      
    • };
      */

      class Solution {
      public:
      void deleteNode(ListNode* node) {
      if(!node || !node->next)
      return;
      struct ListNode *ptr = node->next;
      node->val = ptr->val;
      node->next = ptr->next;
      delete ptr;
      }
      };


Log in to reply
 

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