Coding

[Chapter 5] Butterfly Effect

**AN ALIEN FRIEND**10 years agoCanny was sitting two tables over during the lunch period, sketching in her little notepad. She noticed a guy from her math class pass by, she…

How to study guides

isListPalindrome | Linked List | Data Structure

// Singly-linked lists are already defined with this interface:// template<typename T>// struct ListNode {//   ListNode(const T &v) : value(v), next(nullptr) {}//   T value;//   ListNode *next;// };//bool isListPalindrome(ListNode<int> * l) {    ListNode<int> * fast=l;    ListNode<int> *slow =l;    while(fast != nullptr && fast->next != nullptr){            fast = (fast->next)->next;            slow = slow->next;        }            ListNode<int> *current = slow;    ListNode<int> *prev = NULL;    ListNode<int> *next = NULL;    while (current != NULL) {             // Store next             next = current->next;               // Reverse current node’s pointer             current->next = prev;               // Move pointers one position ahead.             prev = current;             current = next;         }         slow = prev;        fast = l;                while(slow != NULL){                        if(fast->value != slow->value){                return false;            }            fast = fast->next;            slow = slow->next;        }        return true;}

Middle Element Of Linked List | Linked List | Data Structure

/*** Definition for singly-linked list.* struct ListNode {* int val;* ListNode *next;* ListNode(int x) : val(x), next(NULL) {}* };*/class Solution {    public:       ListNode* middleNode(ListNode* head) {             ListNode * fast…

Some category

isListPalindrome | Linked List | Data Structure

// Singly-linked lists are already defined with this interface:// template<typename T>// struct ListNode {//   ListNode(const T &v) : value(v), next(nullptr) {}//   T value;//   ListNode *next;// };//bool isListPalindrome(ListNode<int> * l) {    ListNode<int> * fast=l;    ListNode<int> *slow =l;    while(fast != nullptr && fast->next != nullptr){            fast = (fast->next)->next;            slow = slow->next;        }            ListNode<int> *current = slow;    ListNode<int> *prev = NULL;    ListNode<int> *next = NULL;    while (current != NULL) {             // Store next             next = current->next;               // Reverse current node’s pointer             current->next = prev;               // Move pointers one position ahead.             prev = current;             current = next;         }         slow = prev;        fast = l;                while(slow != NULL){                        if(fast->value != slow->value){                return false;            }            fast = fast->next;            slow = slow->next;        }        return true;}

Some category