KZ
item
Негізгі бет
Трендинг
Журнал
Ұнаған бейнелер
Ең жақсы KZitem
Фильм және анимация
Автокөліктер мен көлік құралдары
Музыка
Үй жануарлары мен аңдар
Спорт
Ойындар
Комедия
Ойын-сауық
Тәжірибелік нұсқаулар және стиль
Ғылым және технология
Кіру
Тіркелу
Кіру
Тіркелу
Негізгі бет
Трендинг
Журнал
Ұнаған бейнелер
Ең жақсы KZitem
Фильм және анимация
Автокөліктер мен көлік құралдары
Музыка
Үй жануарлары мен аңдар
Спорт
Ойындар
Комедия
Ойын-сауық
Тәжірибелік нұсқаулар және стиль
Ғылым және технология
Негізгі бет
LeetCode - Serialize and Deserialize Binary Tree - C++
Күн бұрын
LeetCode - Serialize and Deserialize Binary Tree - C++
Рет қаралды
45
Lansicus
1
1
Жүктеу
Пікірлер: 3
@lansicus
Ай бұрын
class Codec { private: void serDfs(TreeNode *tn, string &s) { if (!tn) { s.append(",#"); return; } else { s.append(","); s.append(to_string(tn->val)); } serDfs(tn->left, s); serDfs(tn->right, s); } TreeNode *deserDfs(string &s, int &i) { i++; string num; while (i < s.size() && s[i] != ',') { num += s[i]; i++; } if (num == "#") { return nullptr; } TreeNode *tn = new TreeNode(stoi(num)); tn->left = deserDfs(s, i); tn->right = deserDfs(s, i); return tn; } public: // Encodes a tree to a single string. string serialize(TreeNode* root) { // O(n) time, O(h) space string s; serDfs(root, s); return s; } // Decodes your encoded data to tree. TreeNode* deserialize(string data) { // O(n) time, O(h) space int i = 0; TreeNode *root = deserDfs(data, i); return root; } };
@SubhashSB-p3f
Ай бұрын
Bro what are the major topics covered to be covered in c++ for DSA
@lansicus
Ай бұрын
I'll be covering arrays/hashing, two pointers, stack, binary search, sliding window, linked list, trees, tries, backtracking, heap, graphs, dynamic programming, intervals, greedy, bit manipulation, and math/geometry
Пікірлер: 3