diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b64967 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +.vscode +.DS_Store diff --git a/README.md b/README.md index 8f219ef..395d94c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ LeetBook《图解算法数据结构》面向算法初学者、互联网求职者 ### :green_book: 剑指 Offer 图文题解 -- 图文详解 75 道题目,覆盖主要算法知识点,非常适合作为算法学习的**第一份题库**。 +- 图文详解 75 道题目,覆盖主要算法知识点,非常适合作为算法学习的 **第一份题库** 。 - 题库活跃于各大互联网公司招聘中,可使笔面试准备事半功倍。 - 致力于行文深入浅出、图文搭配,提供简洁的 **Python3, Java, C++** 解题代码。 - 笔者整理了 **30 天刷题计划**、**题目分类**,让刷题有迹可循。 @@ -35,8 +35,8 @@ LeetBook《图解算法数据结构》面向算法初学者、互联网求职者 > 建议对数据结构不熟悉的同学,先看这篇熟悉用法。 -- 常用数据结构的**分类**和**基本特点**; -- 在算法解题中,数据结构的**常用操作**; +- 常用数据结构的**分类**和**基本特点**。 +- 在算法解题中,数据结构的**常用操作**。 - 在 Python3 , Java , C++ 语言中,各数据结构的**初始化与构建方法**。 ### 「[算法复杂度](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/r84gmi/)」 diff --git a/cpp/include/PrintUtil.hpp b/cpp/include/PrintUtil.hpp index c68cd8a..34e8b86 100644 --- a/cpp/include/PrintUtil.hpp +++ b/cpp/include/PrintUtil.hpp @@ -12,130 +12,186 @@ #include "ListNode.hpp" #include "TreeNode.hpp" -/** - * @brief Find an element in a vector - * - * @tparam T - * @param vec - * @param ele - * @return int - */ -template -int vecFind(const vector& vec, T ele) { - int j = INT_MAX; - for (int i = 0; i < vec.size(); i++) { - if (vec[i] == ele) { - j = i; +class PrintUtil { + public: + /** + * @brief Find an element in a vector + * + * @tparam T + * @param vec + * @param ele + * @return int + */ + template + static int vecFind(const vector& vec, T ele) { + int j = INT_MAX; + for (int i = 0; i < vec.size(); i++) { + if (vec[i] == ele) { + j = i; + } + } + return j; } - } - return j; -} -/** - * @brief Concatenate a vector with a delim - * - * @tparam T - * @param delim - * @param vec - * @return string - */ -template -string join(const string& delim, const T& vec) { - ostringstream s; - for (const auto& i : vec) { - if (&i != &vec[0]) { - s << delim; + /** + * @brief Concatenate a vector with a delim + * + * @tparam T + * @param delim + * @param vec + * @return string + */ + template + static string strJoin(const string& delim, const T& vec) { + ostringstream s; + for (const auto& i : vec) { + if (&i != &vec[0]) { + s << delim; + } + s << i; + } + return s.str(); } - s << i; - } - return s.str(); -} -/** - * @brief Repeat a string for n times - * - * @param str - * @param n - * @return string - */ -string repeat(string str, int n) { - ostringstream os; - for(int i = 0; i < n; i++) - os << str; - return os.str(); -} + /** + * @brief Repeat a string for n times + * + * @param str + * @param n + * @return string + */ + static string strRepeat(string str, int n) { + ostringstream os; + for(int i = 0; i < n; i++) + os << str; + return os.str(); + } -/** - * @brief Get the Vector String object - * - * @tparam T - * @param list - * @return string - */ -template -string getVectorString(vector &list) { - return "[" + join(", ", list) + "]"; -} + /** + * @brief Get the Vector String object + * + * @tparam T + * @param list + * @return string + */ + template + static string getVectorString(vector &list) { + return "[" + strJoin(", ", list) + "]"; + } -/** - * @brief Print a vector - * - * @tparam T - * @param list - */ -template -void printVector(vector &list) { - cout << getVectorString(list) << '\n'; -} + /** + * @brief Print a vector + * + * @tparam T + * @param list + */ + template + static void printVector(vector &list) { + cout << getVectorString(list) << '\n'; + } -/** - * @brief Print a vector matrix - * - * @tparam T - * @param matrix - */ -template -void printVectorMatrix(vector> &matrix) { - cout << "[" << '\n'; - for (vector &list : matrix) - cout << " " + getVectorString(list) + "," << '\n'; - cout << "]" << '\n'; -} + /** + * @brief Print a vector matrix + * + * @tparam T + * @param matrix + */ + template + static void printVectorMatrix(vector> &matrix) { + cout << "[" << '\n'; + for (vector &list : matrix) + cout << " " + getVectorString(list) + "," << '\n'; + cout << "]" << '\n'; + } -/** - * @brief Print a linked list - * - * @param head - */ -void printLinkedList(ListNode *head) { - vector list; - while (head != nullptr) { - list.push_back(head->val); - head = head->next; - } - - cout << join(" -> ", list) << '\n'; -} + /** + * @brief Print a linked list + * + * @param head + */ + static void printLinkedList(ListNode *head) { + vector list; + while (head != nullptr) { + list.push_back(head->val); + head = head->next; + } + + cout << strJoin(" -> ", list) << '\n'; + } -/** - * @brief Print helper for binary tree - * - * @param root - * @param level - */ -void printTreeHelper(TreeNode *root, int level) { - if (root == nullptr) - return; - printTreeHelper(root->right, level + 1); - cout << repeat(" ", 4 * level) + "->" << root->val << '\n'; - printTreeHelper(root->left, level + 1); -} + /** + * @brief This tree printer is borrowed from TECHIE DELIGHT + * https://www.techiedelight.com/c-program-print-binary-tree/ + */ + struct Trunk { + Trunk *prev; + string str; + Trunk(Trunk *prev, string str) { + this->prev = prev; + this->str = str; + } + }; + + /** + * @brief Helper function to print branches of the binary tree + * + * @param p + */ + static void showTrunks(Trunk *p) { + if (p == nullptr) { + return; + } + + showTrunks(p->prev); + cout << p->str; + } -/** - * @brief Print a binary tree (90º counter-clockwise rotated) - * - * @param root - */ -void printTree(TreeNode *root) { - printTreeHelper(root, 0); -} + /** + * @brief The interface of the tree printer + * + * @param root + */ + static void printTree(TreeNode *root) { + printTree(root, nullptr, false); + } + + /** + * @brief Print a binary tree + * + * @param root + * @param prev + * @param isLeft + */ + static void printTree(TreeNode *root, Trunk *prev, bool isLeft) { + if (root == nullptr) { + return; + } + + string prev_str = " "; + Trunk *trunk = new Trunk(prev, prev_str); + + printTree(root->right, trunk, true); + + if (!prev) { + trunk->str = "———"; + } + else if (isLeft) { + trunk->str = "/———"; + prev_str = " |"; + } + else { + trunk->str = "\\———"; + prev->str = prev_str; + } + + showTrunks(trunk); + cout << " " << root->val << endl; + + if (prev) { + prev->str = prev_str; + } + trunk->str = " |"; + + printTree(root->left, trunk, false); + } +}; diff --git a/cpp/sfo_06_print_a_linked_list_in_reverse_order_s1/sfo_06_print_a_linked_list_in_reverse_order_s1.cpp b/cpp/sfo_06_print_a_linked_list_in_reverse_order_s1/sfo_06_print_a_linked_list_in_reverse_order_s1.cpp index 1a9a3c8..903fcd0 100644 --- a/cpp/sfo_06_print_a_linked_list_in_reverse_order_s1/sfo_06_print_a_linked_list_in_reverse_order_s1.cpp +++ b/cpp/sfo_06_print_a_linked_list_in_reverse_order_s1/sfo_06_print_a_linked_list_in_reverse_order_s1.cpp @@ -28,7 +28,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->reversePrint(head); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_06_print_a_linked_list_in_reverse_order_s2/sfo_06_print_a_linked_list_in_reverse_order_s2.cpp b/cpp/sfo_06_print_a_linked_list_in_reverse_order_s2/sfo_06_print_a_linked_list_in_reverse_order_s2.cpp index 4dfe193..6e4cfce 100644 --- a/cpp/sfo_06_print_a_linked_list_in_reverse_order_s2/sfo_06_print_a_linked_list_in_reverse_order_s2.cpp +++ b/cpp/sfo_06_print_a_linked_list_in_reverse_order_s2/sfo_06_print_a_linked_list_in_reverse_order_s2.cpp @@ -30,7 +30,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->reversePrint(head); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_07_reconstruct_binary_tree_s1/sfo_07_reconstruct_binary_tree_s1.cpp b/cpp/sfo_07_reconstruct_binary_tree_s1/sfo_07_reconstruct_binary_tree_s1.cpp index 43985af..4375d57 100644 --- a/cpp/sfo_07_reconstruct_binary_tree_s1/sfo_07_reconstruct_binary_tree_s1.cpp +++ b/cpp/sfo_07_reconstruct_binary_tree_s1/sfo_07_reconstruct_binary_tree_s1.cpp @@ -35,7 +35,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); TreeNode* res = slt->buildTree(preorder, inorder); - printTree(res); + PrintUtil::printTree(res); return 0; } diff --git a/cpp/sfo_09_implement_a_queue_using_two_stacks_s1/sfo_09_implement_a_queue_using_two_stacks_s1.cpp b/cpp/sfo_09_implement_a_queue_using_two_stacks_s1/sfo_09_implement_a_queue_using_two_stacks_s1.cpp index 5f17058..4c7da99 100644 --- a/cpp/sfo_09_implement_a_queue_using_two_stacks_s1/sfo_09_implement_a_queue_using_two_stacks_s1.cpp +++ b/cpp/sfo_09_implement_a_queue_using_two_stacks_s1/sfo_09_implement_a_queue_using_two_stacks_s1.cpp @@ -41,7 +41,7 @@ int main() { cQueue->appendTail(2); res.push_back(cQueue->deleteHead()); res.push_back(cQueue->deleteHead()); - printVector(res); + PrintUtil::printVector(res); return 0; } \ No newline at end of file diff --git a/cpp/sfo_18_delete_a_node_from_a_linked_list_s1/sfo_18_delete_a_node_from_a_linked_list_s1.cpp b/cpp/sfo_18_delete_a_node_from_a_linked_list_s1/sfo_18_delete_a_node_from_a_linked_list_s1.cpp index 8f3beb6..37dbc00 100644 --- a/cpp/sfo_18_delete_a_node_from_a_linked_list_s1/sfo_18_delete_a_node_from_a_linked_list_s1.cpp +++ b/cpp/sfo_18_delete_a_node_from_a_linked_list_s1/sfo_18_delete_a_node_from_a_linked_list_s1.cpp @@ -28,7 +28,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); ListNode* res = slt->deleteNode(head, val); - printLinkedList(res); + PrintUtil::printLinkedList(res); return 0; } diff --git a/cpp/sfo_21_adjust_the_order_of_numbers_in_an_array_s1/sfo_21_adjust_the_order_of_numbers_in_an_array_s1.cpp b/cpp/sfo_21_adjust_the_order_of_numbers_in_an_array_s1/sfo_21_adjust_the_order_of_numbers_in_an_array_s1.cpp index ccb9165..cc74780 100644 --- a/cpp/sfo_21_adjust_the_order_of_numbers_in_an_array_s1/sfo_21_adjust_the_order_of_numbers_in_an_array_s1.cpp +++ b/cpp/sfo_21_adjust_the_order_of_numbers_in_an_array_s1/sfo_21_adjust_the_order_of_numbers_in_an_array_s1.cpp @@ -27,7 +27,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->exchange(nums); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1.cpp b/cpp/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1.cpp index 2368445..8e54ec8 100644 --- a/cpp/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1.cpp +++ b/cpp/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1.cpp @@ -28,7 +28,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); ListNode* res = slt->getKthFromEnd(head, k); - printLinkedList(res); + PrintUtil::printLinkedList(res); return 0; } diff --git a/cpp/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2.cpp b/cpp/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2.cpp index 350f206..1c80e0d 100644 --- a/cpp/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2.cpp +++ b/cpp/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2.cpp @@ -30,7 +30,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); ListNode* res = slt->getKthFromEnd(head, k); - printLinkedList(res); + PrintUtil::printLinkedList(res); return 0; } diff --git a/cpp/sfo_24_reverse_a_linked_list_s1/sfo_24_reverse_a_linked_list_s1.cpp b/cpp/sfo_24_reverse_a_linked_list_s1/sfo_24_reverse_a_linked_list_s1.cpp index ae3e38e..24a0c66 100644 --- a/cpp/sfo_24_reverse_a_linked_list_s1/sfo_24_reverse_a_linked_list_s1.cpp +++ b/cpp/sfo_24_reverse_a_linked_list_s1/sfo_24_reverse_a_linked_list_s1.cpp @@ -27,7 +27,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); ListNode* res = slt->reverseList(head); - printLinkedList(res); + PrintUtil::printLinkedList(res); return 0; } diff --git a/cpp/sfo_24_reverse_a_linked_list_s2/sfo_24_reverse_a_linked_list_s2.cpp b/cpp/sfo_24_reverse_a_linked_list_s2/sfo_24_reverse_a_linked_list_s2.cpp index b4acb8c..2ec993e 100644 --- a/cpp/sfo_24_reverse_a_linked_list_s2/sfo_24_reverse_a_linked_list_s2.cpp +++ b/cpp/sfo_24_reverse_a_linked_list_s2/sfo_24_reverse_a_linked_list_s2.cpp @@ -27,7 +27,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); ListNode* res = slt->reverseList(head); - printLinkedList(res); + PrintUtil::printLinkedList(res); return 0; } diff --git a/cpp/sfo_25_combine_two_sorted_linked_lists_s1/sfo_25_combine_two_sorted_linked_lists_s1.cpp b/cpp/sfo_25_combine_two_sorted_linked_lists_s1/sfo_25_combine_two_sorted_linked_lists_s1.cpp index 7165bf6..5ca2443 100644 --- a/cpp/sfo_25_combine_two_sorted_linked_lists_s1/sfo_25_combine_two_sorted_linked_lists_s1.cpp +++ b/cpp/sfo_25_combine_two_sorted_linked_lists_s1/sfo_25_combine_two_sorted_linked_lists_s1.cpp @@ -35,7 +35,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); ListNode* res = slt->mergeTwoLists(l1, l2); - printLinkedList(res); + PrintUtil::printLinkedList(res); return 0; } diff --git a/cpp/sfo_27_mirror_of_a_binary_tree_s1/sfo_27_mirror_of_a_binary_tree_s1.cpp b/cpp/sfo_27_mirror_of_a_binary_tree_s1/sfo_27_mirror_of_a_binary_tree_s1.cpp index aa7a999..700f2cd 100644 --- a/cpp/sfo_27_mirror_of_a_binary_tree_s1/sfo_27_mirror_of_a_binary_tree_s1.cpp +++ b/cpp/sfo_27_mirror_of_a_binary_tree_s1/sfo_27_mirror_of_a_binary_tree_s1.cpp @@ -24,7 +24,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); TreeNode* res = slt->mirrorTree(root); - printTree(res); + PrintUtil::printTree(res); return 0; } diff --git a/cpp/sfo_27_mirror_of_a_binary_tree_s2/sfo_27_mirror_of_a_binary_tree_s2.cpp b/cpp/sfo_27_mirror_of_a_binary_tree_s2/sfo_27_mirror_of_a_binary_tree_s2.cpp index d4598f4..a406e23 100644 --- a/cpp/sfo_27_mirror_of_a_binary_tree_s2/sfo_27_mirror_of_a_binary_tree_s2.cpp +++ b/cpp/sfo_27_mirror_of_a_binary_tree_s2/sfo_27_mirror_of_a_binary_tree_s2.cpp @@ -33,7 +33,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); TreeNode* res = slt->mirrorTree(root); - printTree(res); + PrintUtil::printTree(res); return 0; } diff --git a/cpp/sfo_29_print_a_given_matrix_in_spiral_form_s1/sfo_29_print_a_given_matrix_in_spiral_form_s1.cpp b/cpp/sfo_29_print_a_given_matrix_in_spiral_form_s1/sfo_29_print_a_given_matrix_in_spiral_form_s1.cpp index edf4aae..d4d303b 100644 --- a/cpp/sfo_29_print_a_given_matrix_in_spiral_form_s1/sfo_29_print_a_given_matrix_in_spiral_form_s1.cpp +++ b/cpp/sfo_29_print_a_given_matrix_in_spiral_form_s1/sfo_29_print_a_given_matrix_in_spiral_form_s1.cpp @@ -38,7 +38,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->spiralOrder(matrix); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_30_min_stack_s1/sfo_30_min_stack_s1.cpp b/cpp/sfo_30_min_stack_s1/sfo_30_min_stack_s1.cpp index 9e04dab..05ae45d 100644 --- a/cpp/sfo_30_min_stack_s1/sfo_30_min_stack_s1.cpp +++ b/cpp/sfo_30_min_stack_s1/sfo_30_min_stack_s1.cpp @@ -40,7 +40,7 @@ int main() { minStack->pop(); res.push_back(minStack->top()); res.push_back(minStack->min()); - printVector(res); + PrintUtil::printVector(res); return 0; } \ No newline at end of file diff --git a/cpp/sfo_32i_print_a_binary_tree_topbottom_i_s1/sfo_32i_print_a_binary_tree_topbottom_i_s1.cpp b/cpp/sfo_32i_print_a_binary_tree_topbottom_i_s1/sfo_32i_print_a_binary_tree_topbottom_i_s1.cpp index 7fc479f..e7ebcd1 100644 --- a/cpp/sfo_32i_print_a_binary_tree_topbottom_i_s1/sfo_32i_print_a_binary_tree_topbottom_i_s1.cpp +++ b/cpp/sfo_32i_print_a_binary_tree_topbottom_i_s1/sfo_32i_print_a_binary_tree_topbottom_i_s1.cpp @@ -31,7 +31,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->levelOrder(root); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_32ii_print_a_binary_tree_topbottom_ii_s1/sfo_32ii_print_a_binary_tree_topbottom_ii_s1.cpp b/cpp/sfo_32ii_print_a_binary_tree_topbottom_ii_s1/sfo_32ii_print_a_binary_tree_topbottom_ii_s1.cpp index db69578..98e77e6 100644 --- a/cpp/sfo_32ii_print_a_binary_tree_topbottom_ii_s1/sfo_32ii_print_a_binary_tree_topbottom_ii_s1.cpp +++ b/cpp/sfo_32ii_print_a_binary_tree_topbottom_ii_s1/sfo_32ii_print_a_binary_tree_topbottom_ii_s1.cpp @@ -35,7 +35,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector> res = slt->levelOrder(root); - printVectorMatrix(res); + PrintUtil::printVectorMatrix(res); return 0; } diff --git a/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s1/sfo_32iii_print_a_binary_tree_topbottom_iii_s1.cpp b/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s1/sfo_32iii_print_a_binary_tree_topbottom_iii_s1.cpp index c1c7506..1d90ac8 100644 --- a/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s1/sfo_32iii_print_a_binary_tree_topbottom_iii_s1.cpp +++ b/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s1/sfo_32iii_print_a_binary_tree_topbottom_iii_s1.cpp @@ -50,7 +50,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector> res = slt->levelOrder(root); - printVectorMatrix(res); + PrintUtil::printVectorMatrix(res); return 0; } diff --git a/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s2/sfo_32iii_print_a_binary_tree_topbottom_iii_s2.cpp b/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s2/sfo_32iii_print_a_binary_tree_topbottom_iii_s2.cpp index bc0e079..660d0e9 100644 --- a/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s2/sfo_32iii_print_a_binary_tree_topbottom_iii_s2.cpp +++ b/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s2/sfo_32iii_print_a_binary_tree_topbottom_iii_s2.cpp @@ -35,7 +35,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector> res = slt->levelOrder(root); - printVectorMatrix(res); + PrintUtil::printVectorMatrix(res); return 0; } diff --git a/cpp/sfo_34_all_xsum_paths_in_a_binary_tree_s1/sfo_34_all_xsum_paths_in_a_binary_tree_s1.cpp b/cpp/sfo_34_all_xsum_paths_in_a_binary_tree_s1/sfo_34_all_xsum_paths_in_a_binary_tree_s1.cpp index 92bcd2e..301b13e 100644 --- a/cpp/sfo_34_all_xsum_paths_in_a_binary_tree_s1/sfo_34_all_xsum_paths_in_a_binary_tree_s1.cpp +++ b/cpp/sfo_34_all_xsum_paths_in_a_binary_tree_s1/sfo_34_all_xsum_paths_in_a_binary_tree_s1.cpp @@ -35,7 +35,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector> res = slt->pathSum(root, sum); - printVectorMatrix(res); + PrintUtil::printVectorMatrix(res); return 0; } diff --git a/cpp/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1.cpp b/cpp/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1.cpp index 3439e81..41b199b 100644 --- a/cpp/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1.cpp +++ b/cpp/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1.cpp @@ -74,9 +74,9 @@ int main() { for (int i = 0; i < nodeListNew.size(); i++) { Node* node = nodeListNew[i]; printArr[i][0] = node->val; - printArr[i][1] = vecFind(nodeListNew, node->random); + printArr[i][1] = PrintUtil::vecFind(nodeListNew, node->random); } - printVectorMatrix(printArr); + PrintUtil::printVectorMatrix(printArr); return 0; } diff --git a/cpp/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2.cpp b/cpp/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2.cpp index 683bc95..d56c2f0 100644 --- a/cpp/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2.cpp +++ b/cpp/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2.cpp @@ -84,9 +84,9 @@ int main() { for (int i = 0; i < nodeListNew.size(); i++) { Node* node = nodeListNew[i]; printArr[i][0] = node->val; - printArr[i][1] = vecFind(nodeListNew, node->random); + printArr[i][1] = PrintUtil::vecFind(nodeListNew, node->random); } - printVectorMatrix(printArr); + PrintUtil::printVectorMatrix(printArr); return 0; } diff --git a/cpp/sfo_36_binary_search_tree_and_doubly_linked_list_s1/sfo_36_binary_search_tree_and_doubly_linked_list_s1.cpp b/cpp/sfo_36_binary_search_tree_and_doubly_linked_list_s1/sfo_36_binary_search_tree_and_doubly_linked_list_s1.cpp index 468adae..43f354e 100644 --- a/cpp/sfo_36_binary_search_tree_and_doubly_linked_list_s1/sfo_36_binary_search_tree_and_doubly_linked_list_s1.cpp +++ b/cpp/sfo_36_binary_search_tree_and_doubly_linked_list_s1/sfo_36_binary_search_tree_and_doubly_linked_list_s1.cpp @@ -63,7 +63,7 @@ int main() { nodesVal.push_back(res->val); res = res->right; } - cout << join(" <-> ", nodesVal) << endl; + cout << PrintUtil::strJoin(" <-> ", nodesVal) << endl; return 0; } diff --git a/cpp/sfo_37_serialize_and_deserialize_a_binary_tree_s1/sfo_37_serialize_and_deserialize_a_binary_tree_s1.cpp b/cpp/sfo_37_serialize_and_deserialize_a_binary_tree_s1/sfo_37_serialize_and_deserialize_a_binary_tree_s1.cpp index a527094..d7677e9 100644 --- a/cpp/sfo_37_serialize_and_deserialize_a_binary_tree_s1/sfo_37_serialize_and_deserialize_a_binary_tree_s1.cpp +++ b/cpp/sfo_37_serialize_and_deserialize_a_binary_tree_s1/sfo_37_serialize_and_deserialize_a_binary_tree_s1.cpp @@ -75,6 +75,6 @@ int main() { Codec* codec = new Codec(); TreeNode* root = codec->deserialize(data); string res = codec->serialize(root); - printTree(root); + PrintUtil::printTree(root); cout << res << endl; } diff --git a/cpp/sfo_38_all_permutations_of_a_string_s1/sfo_38_all_permutations_of_a_string_s1.cpp b/cpp/sfo_38_all_permutations_of_a_string_s1/sfo_38_all_permutations_of_a_string_s1.cpp index 28b337b..6ab23af 100644 --- a/cpp/sfo_38_all_permutations_of_a_string_s1/sfo_38_all_permutations_of_a_string_s1.cpp +++ b/cpp/sfo_38_all_permutations_of_a_string_s1/sfo_38_all_permutations_of_a_string_s1.cpp @@ -37,7 +37,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->permutation(s); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_40_the_smallest_k_numbers_s1/sfo_40_the_smallest_k_numbers_s1.cpp b/cpp/sfo_40_the_smallest_k_numbers_s1/sfo_40_the_smallest_k_numbers_s1.cpp index ddef50c..b026047 100644 --- a/cpp/sfo_40_the_smallest_k_numbers_s1/sfo_40_the_smallest_k_numbers_s1.cpp +++ b/cpp/sfo_40_the_smallest_k_numbers_s1/sfo_40_the_smallest_k_numbers_s1.cpp @@ -40,7 +40,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->getLeastNumbers(arr, k); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_40_the_smallest_k_numbers_s2/sfo_40_the_smallest_k_numbers_s2.cpp b/cpp/sfo_40_the_smallest_k_numbers_s2/sfo_40_the_smallest_k_numbers_s2.cpp index 9c68da0..efb0ab6 100644 --- a/cpp/sfo_40_the_smallest_k_numbers_s2/sfo_40_the_smallest_k_numbers_s2.cpp +++ b/cpp/sfo_40_the_smallest_k_numbers_s2/sfo_40_the_smallest_k_numbers_s2.cpp @@ -37,7 +37,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->getLeastNumbers(arr, k); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_41_find_median_from_data_stream_s1/sfo_41_find_median_from_data_stream_s1.cpp b/cpp/sfo_41_find_median_from_data_stream_s1/sfo_41_find_median_from_data_stream_s1.cpp index 15fd119..07a171d 100644 --- a/cpp/sfo_41_find_median_from_data_stream_s1/sfo_41_find_median_from_data_stream_s1.cpp +++ b/cpp/sfo_41_find_median_from_data_stream_s1/sfo_41_find_median_from_data_stream_s1.cpp @@ -37,7 +37,7 @@ int main() { res.push_back(medianFinder->findMedian()); medianFinder->addNum(3); res.push_back(medianFinder->findMedian()); - printVector(res); + PrintUtil::printVector(res); return 0; } \ No newline at end of file diff --git a/cpp/sfo_56i_single_number_i_s1/sfo_56i_single_number_i_s1.cpp b/cpp/sfo_56i_single_number_i_s1/sfo_56i_single_number_i_s1.cpp index 3668cf7..8ea515e 100644 --- a/cpp/sfo_56i_single_number_i_s1/sfo_56i_single_number_i_s1.cpp +++ b/cpp/sfo_56i_single_number_i_s1/sfo_56i_single_number_i_s1.cpp @@ -29,7 +29,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->singleNumbers(nums); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_57_two_numbers_with_sum_s_s1/sfo_57_two_numbers_with_sum_s_s1.cpp b/cpp/sfo_57_two_numbers_with_sum_s_s1/sfo_57_two_numbers_with_sum_s_s1.cpp index 14399bf..cea8b07 100644 --- a/cpp/sfo_57_two_numbers_with_sum_s_s1/sfo_57_two_numbers_with_sum_s_s1.cpp +++ b/cpp/sfo_57_two_numbers_with_sum_s_s1/sfo_57_two_numbers_with_sum_s_s1.cpp @@ -28,7 +28,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->twoSum(nums, target); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s1/sfo_57ii_consecutive_numbers_with_sum_s_s1.cpp b/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s1/sfo_57ii_consecutive_numbers_with_sum_s_s1.cpp index d7afc74..1fdc139 100644 --- a/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s1/sfo_57ii_consecutive_numbers_with_sum_s_s1.cpp +++ b/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s1/sfo_57ii_consecutive_numbers_with_sum_s_s1.cpp @@ -33,7 +33,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector> res = slt->findContinuousSequence(target); - printVectorMatrix(res); + PrintUtil::printVectorMatrix(res); return 0; } diff --git a/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s2/sfo_57ii_consecutive_numbers_with_sum_s_s2.cpp b/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s2/sfo_57ii_consecutive_numbers_with_sum_s_s2.cpp index 9b527a7..bd522a9 100644 --- a/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s2/sfo_57ii_consecutive_numbers_with_sum_s_s2.cpp +++ b/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s2/sfo_57ii_consecutive_numbers_with_sum_s_s2.cpp @@ -37,7 +37,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector> res = slt->findContinuousSequence(target); - printVectorMatrix(res); + PrintUtil::printVectorMatrix(res); return 0; } diff --git a/cpp/sfo_59ii_max_queue_s1/sfo_59ii_max_queue_s1.cpp b/cpp/sfo_59ii_max_queue_s1/sfo_59ii_max_queue_s1.cpp index 26e6011..93a1388 100644 --- a/cpp/sfo_59ii_max_queue_s1/sfo_59ii_max_queue_s1.cpp +++ b/cpp/sfo_59ii_max_queue_s1/sfo_59ii_max_queue_s1.cpp @@ -40,7 +40,7 @@ int main() { res.push_back(maxQueue->max_value()); res.push_back(maxQueue->pop_front()); res.push_back(maxQueue->max_value()); - printVector(res); + PrintUtil::printVector(res); return 0; } \ No newline at end of file diff --git a/cpp/sfo_60_probabilities_for_rolling_n_dices_s1/sfo_60_probabilities_for_rolling_n_dices_s1.cpp b/cpp/sfo_60_probabilities_for_rolling_n_dices_s1/sfo_60_probabilities_for_rolling_n_dices_s1.cpp index 051f8d1..13108c6 100644 --- a/cpp/sfo_60_probabilities_for_rolling_n_dices_s1/sfo_60_probabilities_for_rolling_n_dices_s1.cpp +++ b/cpp/sfo_60_probabilities_for_rolling_n_dices_s1/sfo_60_probabilities_for_rolling_n_dices_s1.cpp @@ -30,7 +30,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->dicesProbability(n); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/cpp/sfo_66_a_product_array_puzzle_s1/sfo_66_a_product_array_puzzle_s1.cpp b/cpp/sfo_66_a_product_array_puzzle_s1/sfo_66_a_product_array_puzzle_s1.cpp index edc6331..3db51e5 100644 --- a/cpp/sfo_66_a_product_array_puzzle_s1/sfo_66_a_product_array_puzzle_s1.cpp +++ b/cpp/sfo_66_a_product_array_puzzle_s1/sfo_66_a_product_array_puzzle_s1.cpp @@ -32,7 +32,7 @@ int main() { // ====== Driver Code ====== Solution* slt = new Solution(); vector res = slt->constructArr(a); - printVector(res); + PrintUtil::printVector(res); return 0; } diff --git a/java/include/PrintUtil.java b/java/include/PrintUtil.java index 944532f..d5b78e2 100644 --- a/java/include/PrintUtil.java +++ b/java/include/PrintUtil.java @@ -2,6 +2,16 @@ package include; import java.util.*; +class Trunk { + Trunk prev; + String str; + + Trunk(Trunk prev, String str) { + this.prev = prev; + this.str = str; + } +}; + public class PrintUtil { /** * Print a linked list @@ -17,23 +27,58 @@ public class PrintUtil { } /** - * Print a binary tree (90º counter-clockwise rotated) + * The interface of the tree printer + * This tree printer is borrowed from TECHIE DELIGHT + * https://www.techiedelight.com/c-program-print-binary-tree/ * @param root */ public static void printTree(TreeNode root) { - printTreeHelper(root, 0); + printTree(root, null, false); } /** - * Print helper for binary tree + * Print a binary tree * @param root - * @param level + * @param prev + * @param isLeft */ - private static void printTreeHelper(TreeNode root, int level) { - if (root == null) + public static void printTree(TreeNode root, Trunk prev, boolean isLeft) { + if (root == null) { return; - printTreeHelper(root.right, level + 1); - System.out.println(" ".repeat(4 * level) + "->" + root.val); - printTreeHelper(root.left, level + 1); + } + + String prev_str = " "; + Trunk trunk = new Trunk(prev, prev_str); + + printTree(root.right, trunk, true); + + if (prev == null) { + trunk.str = "———"; + } else if (isLeft) { + trunk.str = "/———"; + prev_str = " |"; + } else { + trunk.str = "\\———"; + prev.str = prev_str; + } + + showTrunks(trunk); + System.out.println(" " + root.val); + + if (prev != null) { + prev.str = prev_str; + } + trunk.str = " |"; + + printTree(root.left, trunk, false); + } + + public static void showTrunks(Trunk p) { + if (p == null) { + return; + } + + showTrunks(p.prev); + System.out.print(p.str); } } diff --git a/python/include/print_util.py b/python/include/print_util.py index e26156d..b7c2ba2 100644 --- a/python/include/print_util.py +++ b/python/include/print_util.py @@ -28,16 +28,46 @@ def print_linked_list(head): arr = linked_list_to_list(head) print(' -> '.join([str(a) for a in arr])) -def print_tree(root): - """Print a binary tree (90º counter-clockwise rotated) +class Trunk: + def __init__(self, prev=None, str=None): + self.prev = prev + self.str = str + +def showTrunks(p): + if p is None: + return + showTrunks(p.prev) + print(p.str, end='') + +def print_tree(root, prev=None, isLeft=False): + """Print a binary tree + This tree printer is borrowed from TECHIE DELIGHT + https://www.techiedelight.com/c-program-print-binary-tree/ Args: root ([type]): [description] - """ - def helper(root, level): - if not root: - return - helper(root.right, level + 1) - print(' ' * 4 * level + '->', root.val) - helper(root.left, level + 1) - helper(root, 0) + prev ([type], optional): [description]. Defaults to None. + isLeft (bool, optional): [description]. Defaults to False. + """ + if root is None: + return + + prev_str = ' ' + trunk = Trunk(prev, prev_str) + print_tree(root.right, trunk, True) + + if prev is None: + trunk.str = '———' + elif isLeft: + trunk.str = '/———' + prev_str = ' |' + else: + trunk.str = '\———' + prev.str = prev_str + + showTrunks(trunk) + print(' ' + str(root.val)) + if prev: + prev.str = prev_str + trunk.str = ' |' + print_tree(root.left, trunk, False) diff --git a/python/sfo_10-i_fibonacci_numbers_s1.py b/python/sfo_10i_fibonacci_numbers_s1.py similarity index 100% rename from python/sfo_10-i_fibonacci_numbers_s1.py rename to python/sfo_10i_fibonacci_numbers_s1.py diff --git a/python/sfo_10-i_fibonacci_numbers_s2.py b/python/sfo_10i_fibonacci_numbers_s2.py similarity index 100% rename from python/sfo_10-i_fibonacci_numbers_s2.py rename to python/sfo_10i_fibonacci_numbers_s2.py diff --git a/python/sfo_10-ii_frog_jump_s1.py b/python/sfo_10ii_frog_jump_s1.py similarity index 100% rename from python/sfo_10-ii_frog_jump_s1.py rename to python/sfo_10ii_frog_jump_s1.py diff --git a/python/sfo_10-ii_frog_jump_s2.py b/python/sfo_10ii_frog_jump_s2.py similarity index 100% rename from python/sfo_10-ii_frog_jump_s2.py rename to python/sfo_10ii_frog_jump_s2.py diff --git a/python/sfo_14-i_cut_the_rope_i_s1.py b/python/sfo_14i_cut_the_rope_i_s1.py similarity index 100% rename from python/sfo_14-i_cut_the_rope_i_s1.py rename to python/sfo_14i_cut_the_rope_i_s1.py diff --git a/python/sfo_14-ii_cut_the_rope_ii_s1.py b/python/sfo_14ii_cut_the_rope_ii_s1.py similarity index 100% rename from python/sfo_14-ii_cut_the_rope_ii_s1.py rename to python/sfo_14ii_cut_the_rope_ii_s1.py diff --git a/python/sfo_14-ii_cut_the_rope_ii_s2.py b/python/sfo_14ii_cut_the_rope_ii_s2.py similarity index 100% rename from python/sfo_14-ii_cut_the_rope_ii_s2.py rename to python/sfo_14ii_cut_the_rope_ii_s2.py diff --git a/python/sfo_22_the_k-th_node_from_the_end_of_a_linked_list_s1.py b/python/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1.py similarity index 100% rename from python/sfo_22_the_k-th_node_from_the_end_of_a_linked_list_s1.py rename to python/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1.py diff --git a/python/sfo_22_the_k-th_node_from_the_end_of_a_linked_list_s2.py b/python/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2.py similarity index 100% rename from python/sfo_22_the_k-th_node_from_the_end_of_a_linked_list_s2.py rename to python/sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2.py diff --git a/python/sfo_32-i_print_a_binary_tree_top-bottom_i_s1.py b/python/sfo_32i_print_a_binary_tree_topbottom_i_s1.py similarity index 100% rename from python/sfo_32-i_print_a_binary_tree_top-bottom_i_s1.py rename to python/sfo_32i_print_a_binary_tree_topbottom_i_s1.py diff --git a/python/sfo_32-ii_print_a_binary_tree_top-bottom_ii_s1.py b/python/sfo_32ii_print_a_binary_tree_topbottom_ii_s1.py similarity index 100% rename from python/sfo_32-ii_print_a_binary_tree_top-bottom_ii_s1.py rename to python/sfo_32ii_print_a_binary_tree_topbottom_ii_s1.py diff --git a/python/sfo_32-iii_print_a_binary_tree_top-bottom_iii_s1.py b/python/sfo_32iii_print_a_binary_tree_topbottom_iii_s1.py similarity index 100% rename from python/sfo_32-iii_print_a_binary_tree_top-bottom_iii_s1.py rename to python/sfo_32iii_print_a_binary_tree_topbottom_iii_s1.py diff --git a/python/sfo_32-iii_print_a_binary_tree_top-bottom_iii_s2.py b/python/sfo_32iii_print_a_binary_tree_topbottom_iii_s2.py similarity index 100% rename from python/sfo_32-iii_print_a_binary_tree_top-bottom_iii_s2.py rename to python/sfo_32iii_print_a_binary_tree_topbottom_iii_s2.py diff --git a/python/sfo_32-iii_print_a_binary_tree_top-bottom_iii_s3.py b/python/sfo_32iii_print_a_binary_tree_topbottom_iii_s3.py similarity index 100% rename from python/sfo_32-iii_print_a_binary_tree_top-bottom_iii_s3.py rename to python/sfo_32iii_print_a_binary_tree_topbottom_iii_s3.py diff --git a/python/sfo_33_post-order_traversal_of_a_binary_search_tree_s1.py b/python/sfo_33_postorder_traversal_of_a_binary_search_tree_s1.py similarity index 100% rename from python/sfo_33_post-order_traversal_of_a_binary_search_tree_s1.py rename to python/sfo_33_postorder_traversal_of_a_binary_search_tree_s1.py diff --git a/python/sfo_33_post-order_traversal_of_a_binary_search_tree_s2.py b/python/sfo_33_postorder_traversal_of_a_binary_search_tree_s2.py similarity index 100% rename from python/sfo_33_post-order_traversal_of_a_binary_search_tree_s2.py rename to python/sfo_33_postorder_traversal_of_a_binary_search_tree_s2.py diff --git a/python/sfo_34_all_x-sum_paths_in_a_binary_tree_s1.py b/python/sfo_34_all_xsum_paths_in_a_binary_tree_s1.py similarity index 100% rename from python/sfo_34_all_x-sum_paths_in_a_binary_tree_s1.py rename to python/sfo_34_all_xsum_paths_in_a_binary_tree_s1.py diff --git a/python/sfo_50_find_the_first_non-repeating_character_in_a_string_s1.py b/python/sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.py similarity index 100% rename from python/sfo_50_find_the_first_non-repeating_character_in_a_string_s1.py rename to python/sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.py diff --git a/python/sfo_50_find_the_first_non-repeating_character_in_a_string_s2.py b/python/sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.py similarity index 100% rename from python/sfo_50_find_the_first_non-repeating_character_in_a_string_s2.py rename to python/sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.py diff --git a/python/sfo_50_find_the_first_non-repeating_character_in_a_string_s3.py b/python/sfo_50_find_the_first_nonrepeating_character_in_a_string_s3.py similarity index 100% rename from python/sfo_50_find_the_first_non-repeating_character_in_a_string_s3.py rename to python/sfo_50_find_the_first_nonrepeating_character_in_a_string_s3.py diff --git a/python/sfo_53-i_find_a_number_in_a_sorted_array_s1.py b/python/sfo_53i_find_a_number_in_a_sorted_array_s1.py similarity index 100% rename from python/sfo_53-i_find_a_number_in_a_sorted_array_s1.py rename to python/sfo_53i_find_a_number_in_a_sorted_array_s1.py diff --git a/python/sfo_53-i_find_a_number_in_a_sorted_array_s2.py b/python/sfo_53i_find_a_number_in_a_sorted_array_s2.py similarity index 100% rename from python/sfo_53-i_find_a_number_in_a_sorted_array_s2.py rename to python/sfo_53i_find_a_number_in_a_sorted_array_s2.py diff --git a/python/sfo_53-ii_the_missing_number_from_0_to_n-1_s1.py b/python/sfo_53ii_the_missing_number_from_0_to_n1_s1.py similarity index 100% rename from python/sfo_53-ii_the_missing_number_from_0_to_n-1_s1.py rename to python/sfo_53ii_the_missing_number_from_0_to_n1_s1.py diff --git a/python/sfo_54_the_k-th_largest_node_of_a_binary_search_tree_s1.py b/python/sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.py similarity index 100% rename from python/sfo_54_the_k-th_largest_node_of_a_binary_search_tree_s1.py rename to python/sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.py diff --git a/python/sfo_55-i_depth_of_a_binary_tree_s1.py b/python/sfo_55i_depth_of_a_binary_tree_s1.py similarity index 100% rename from python/sfo_55-i_depth_of_a_binary_tree_s1.py rename to python/sfo_55i_depth_of_a_binary_tree_s1.py diff --git a/python/sfo_55-i_depth_of_a_binary_tree_s2.py b/python/sfo_55i_depth_of_a_binary_tree_s2.py similarity index 100% rename from python/sfo_55-i_depth_of_a_binary_tree_s2.py rename to python/sfo_55i_depth_of_a_binary_tree_s2.py diff --git a/python/sfo_55-ii_balanced_binary_tree_s1.py b/python/sfo_55ii_balanced_binary_tree_s1.py similarity index 100% rename from python/sfo_55-ii_balanced_binary_tree_s1.py rename to python/sfo_55ii_balanced_binary_tree_s1.py diff --git a/python/sfo_55-ii_balanced_binary_tree_s2.py b/python/sfo_55ii_balanced_binary_tree_s2.py similarity index 100% rename from python/sfo_55-ii_balanced_binary_tree_s2.py rename to python/sfo_55ii_balanced_binary_tree_s2.py diff --git a/python/sfo_56-i_single_number_i_s1.py b/python/sfo_56i_single_number_i_s1.py similarity index 100% rename from python/sfo_56-i_single_number_i_s1.py rename to python/sfo_56i_single_number_i_s1.py diff --git a/python/sfo_56-ii_single_number_ii_s1.py b/python/sfo_56ii_single_number_ii_s1.py similarity index 100% rename from python/sfo_56-ii_single_number_ii_s1.py rename to python/sfo_56ii_single_number_ii_s1.py diff --git a/python/sfo_56-ii_single_number_ii_s2.py b/python/sfo_56ii_single_number_ii_s2.py similarity index 100% rename from python/sfo_56-ii_single_number_ii_s2.py rename to python/sfo_56ii_single_number_ii_s2.py diff --git a/python/sfo_57-ii_consecutive_numbers_with_sum_s_s1.py b/python/sfo_57ii_consecutive_numbers_with_sum_s_s1.py similarity index 100% rename from python/sfo_57-ii_consecutive_numbers_with_sum_s_s1.py rename to python/sfo_57ii_consecutive_numbers_with_sum_s_s1.py diff --git a/python/sfo_57-ii_consecutive_numbers_with_sum_s_s2.py b/python/sfo_57ii_consecutive_numbers_with_sum_s_s2.py similarity index 100% rename from python/sfo_57-ii_consecutive_numbers_with_sum_s_s2.py rename to python/sfo_57ii_consecutive_numbers_with_sum_s_s2.py diff --git a/python/sfo_58-i_reverse_order_of_words_s1.py b/python/sfo_58i_reverse_order_of_words_s1.py similarity index 100% rename from python/sfo_58-i_reverse_order_of_words_s1.py rename to python/sfo_58i_reverse_order_of_words_s1.py diff --git a/python/sfo_58-i_reverse_order_of_words_s2.py b/python/sfo_58i_reverse_order_of_words_s2.py similarity index 100% rename from python/sfo_58-i_reverse_order_of_words_s2.py rename to python/sfo_58i_reverse_order_of_words_s2.py diff --git a/python/sfo_58-i_reverse_order_of_words_s3.py b/python/sfo_58i_reverse_order_of_words_s3.py similarity index 100% rename from python/sfo_58-i_reverse_order_of_words_s3.py rename to python/sfo_58i_reverse_order_of_words_s3.py diff --git a/python/sfo_58-ii_left_rotation_of_a_string_s1.py b/python/sfo_58ii_left_rotation_of_a_string_s1.py similarity index 100% rename from python/sfo_58-ii_left_rotation_of_a_string_s1.py rename to python/sfo_58ii_left_rotation_of_a_string_s1.py diff --git a/python/sfo_58-ii_left_rotation_of_a_string_s2.py b/python/sfo_58ii_left_rotation_of_a_string_s2.py similarity index 100% rename from python/sfo_58-ii_left_rotation_of_a_string_s2.py rename to python/sfo_58ii_left_rotation_of_a_string_s2.py diff --git a/python/sfo_58-ii_left_rotation_of_a_string_s3.py b/python/sfo_58ii_left_rotation_of_a_string_s3.py similarity index 100% rename from python/sfo_58-ii_left_rotation_of_a_string_s3.py rename to python/sfo_58ii_left_rotation_of_a_string_s3.py diff --git a/python/sfo_58-ii_left_rotation_of_a_string_s4.py b/python/sfo_58ii_left_rotation_of_a_string_s4.py similarity index 100% rename from python/sfo_58-ii_left_rotation_of_a_string_s4.py rename to python/sfo_58ii_left_rotation_of_a_string_s4.py diff --git a/python/sfo_58-ii_left_rotation_of_a_string_s5.py b/python/sfo_58ii_left_rotation_of_a_string_s5.py similarity index 100% rename from python/sfo_58-ii_left_rotation_of_a_string_s5.py rename to python/sfo_58ii_left_rotation_of_a_string_s5.py diff --git a/python/sfo_59-i_sliding_window_maximum_s1.py b/python/sfo_59i_sliding_window_maximum_s1.py similarity index 100% rename from python/sfo_59-i_sliding_window_maximum_s1.py rename to python/sfo_59i_sliding_window_maximum_s1.py diff --git a/python/sfo_59-i_sliding_window_maximum_s2.py b/python/sfo_59i_sliding_window_maximum_s2.py similarity index 100% rename from python/sfo_59-i_sliding_window_maximum_s2.py rename to python/sfo_59i_sliding_window_maximum_s2.py diff --git a/python/sfo_59-ii_max_queue_s1.py b/python/sfo_59ii_max_queue_s1.py similarity index 100% rename from python/sfo_59-ii_max_queue_s1.py rename to python/sfo_59ii_max_queue_s1.py diff --git a/python/sfo_64_solve_1+2+...+n_s1.py b/python/sfo_64_solve_1_2___n_s1.py similarity index 100% rename from python/sfo_64_solve_1+2+...+n_s1.py rename to python/sfo_64_solve_1_2___n_s1.py diff --git a/python/sfo_68-i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.py b/python/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.py similarity index 100% rename from python/sfo_68-i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.py rename to python/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.py diff --git a/python/sfo_68-i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.py b/python/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.py similarity index 100% rename from python/sfo_68-i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.py rename to python/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.py diff --git a/python/sfo_68-i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.py b/python/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.py similarity index 100% rename from python/sfo_68-i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.py rename to python/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.py diff --git a/python/sfo_68-ii_the_nearest_common_ancestor_of_a_binary_tree_s1.py b/python/sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1.py similarity index 100% rename from python/sfo_68-ii_the_nearest_common_ancestor_of_a_binary_tree_s1.py rename to python/sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1.py diff --git a/python/sfo_68-ii_the_nearest_common_ancestor_of_a_binary_tree_s2.py b/python/sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2.py similarity index 100% rename from python/sfo_68-ii_the_nearest_common_ancestor_of_a_binary_tree_s2.py rename to python/sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2.py