Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Remove Linked List Elements leetcode

class Solution {
public:
    ListNode* removeElements(ListNode* head, int val) {
        
        /*while (head == NULL){
            return head;
        }
        No need for this funtion since we gotta return head in the end of the funtion anyways so this case wud be included
        */
        
        while (head != NULL && head -> val == val){
            head = head -> next;
        }
        ListNode* curr = head;
        while (curr != NULL && curr -> next != NULL){
            if (curr -> next -> val == val){
                curr -> next = curr -> next -> next;
            }
            else {
                curr = curr -> next;
            }
        }
    return head;
    }
};
Comment

Delete Node in a Linked List leetcode

class Solution {
public:
    void deleteNode(ListNode* node) {
        //Make the given node to the next node and delete one of them since they now same
        //Say linked list is 4 -> 5 -> 1 -> 9, node = 5
        
        node -> val = node -> next -> val;
        
        //Now it'll be 4 -> 1 -> 1 -> 9, now our node is the first 1
        
        node -> next = node -> next -> next;
        
        //Now it'll be 4 -> 1 -> 9 (the second 1's next link is cut off)
        //That's the whole answer we don't have to return anything
    }
};
Comment

PREVIOUS NEXT
Code Example
Cpp :: pointeur cpp 
Cpp :: c++ coding questions for interview 
Cpp :: qrandomgenerator bounded 
Cpp :: hello command not printing in c++ 
Cpp :: c++ suare 
Cpp :: bullet physics directx 11 
Cpp :: operator = overloading c++ 
Cpp :: how to implement stack 
Cpp :: turn github into vscode 
Cpp :: strip whitespace c++ 
Cpp :: palindrome no example 
Cpp :: Set Specific Time in youtube Video url 
Cpp :: stream in c++ 
Cpp :: what does | mean in c++ 
Cpp :: how to put string in array c++ 
Cpp :: what does for do in c++ 
Cpp :: c++ switch case statement 
C :: how to remove button decoration 
C :: install gitk mac 
C :: Invalid public key for CUDA apt repository 
C :: if statement shorthand c 
C :: Write a C program to find reverse of an array 
C :: successeur ("123") 
C :: c concatenate strings 
C :: c fractional sleep 
C :: differnce between spooling and buffering 
C :: uuidv4 javascript 
C :: strcmp c 
C :: ruby find object in array by attribute 
C :: warning: function returns address of local variable [-Wreturn-local-addr] 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =