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 :: c++ else if 
Cpp :: how to sort string array in c++ 
Cpp :: c++ length of int 
Cpp :: array of charcter c++ 
Cpp :: ex: cpp 
Cpp :: tr bash 
Cpp :: assign value to a pointer 
Cpp :: cpp language explained 
Cpp :: c++ function overloading 
Cpp :: gcd in cpp 
Cpp :: remove elements from vector 
Cpp :: reverse in vector c++ 
Cpp :: C++ programming code to remove all characters from string except alphabets 
Cpp :: gcd of two numbers 
Cpp :: recuva recovery software for pc with crack 
Cpp :: store arbitrarly large vector of doubles c++ 
Cpp :: The five most significant revisions of the C++ standard are C++98 (1998), C++03 (2003) and C++11 (2011), C++14 (2014) and C++17 (2017) 
Cpp :: new expression 
Cpp :: cplusplusbtutotrail 
Cpp :: cpp split bits 
Cpp :: sfml thread multi argument function 
Cpp :: c++ Testing implementation details for automated assessment of sorting algorithms 
Cpp :: overwrite windows mbr c++ 
Cpp :: and condtion c++ 
Cpp :: c++ map values range 
Cpp :: Write a CPP program to calculate sum of first N natural numbers 
Cpp :: std::ifstream cant read file to large 
Cpp :: set(W) 
Cpp :: left margin c++ 
Cpp :: c++ first index 0 or 1 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =