Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
google
//Title of this code //g++ 4.8.2 #include <iostream> #include <vector> using namespace std; struct Node { unsigned data; vector<Node*> children; Node(unsigned d, vector<Node*> c) : data(d), children(c) {} }; struct ret { unsigned longest; unsigned current; ret(unsigned l, unsigned c) : longest(l), current(c) {} ret() : longest(0), current(0) {} }; ret findLongest(Node* root) { if (!root) return ret(); if (root->children.size() == 0) return ret(0,1); ret cur = ret(0, 0); unsigned r = root->data; for (int i = 0; i < root->children.size(); ++i) { unsigned c = root->children[i]->data; cur = findLongest(root->children[i]); if (c-1 == r) { ++cur.current; cur.longest = max(cur.longest, cur.current); } else cur.current = 1; } return cur; } int main() { Node* root = new Node(1, { new Node(2, {}), new Node(2, {new Node(3, {new Node(4, {}), new Node(5, {})}) }), new Node(2, {}) }); ret r = findLongest(root); std::cout << r.longest; }
run
|
edit
|
history
|
help
0
matrix
Operators
same
LRUCache
Ultimo intento
initializer_list example
Decimal to Binary
max_recursion
Szukanie elementu w niemalejąco posortowanej tablicy używając wyszukiwania binarnego
Guess Number