Full Code of krahets/LeetCode-Book for AI

main c1dd432e9167 cached
983 files
1.8 MB
558.0k tokens
2360 symbols
1 requests
Download .txt
Showing preview only (2,190K chars total). Download the full file or copy to clipboard to get everything.
Repository: krahets/LeetCode-Book
Branch: main
Commit: c1dd432e9167
Files: 983
Total size: 1.8 MB

Directory structure:
gitextract_y7isvm8k/

├── .gitignore
├── LICENSE
├── README.md
├── leetbook_ioa/
│   └── docs/
│       ├── # 0 引言.md
│       ├── # 0.1 刷题建议.md
│       ├── # 0.2 题目分类.md
│       ├── # 1.1 数据结构简介.md
│       ├── # 1.2 算法复杂度.md
│       ├── # 1.3 时间复杂度.md
│       ├── # 1.4 空间复杂度.md
│       ├── # 11.1 动态规划解题框架.md
│       ├── # 7.1 排序算法简介.md
│       ├── # 7.2 冒泡排序.md
│       ├── # 7.3 快速排序.md
│       ├── # 7.4 归并排序.md
│       ├── LCR 120. 寻找文件副本.md
│       ├── LCR 121. 寻找目标值 - 二维数组.md
│       ├── LCR 122. 路径加密.md
│       ├── LCR 123. 图书整理 I.md
│       ├── LCR 124. 推理二叉树.md
│       ├── LCR 125. 图书整理 II.md
│       ├── LCR 126. 斐波那契数.md
│       ├── LCR 127. 跳跃训练.md
│       ├── LCR 128. 库存管理 I.md
│       ├── LCR 129. 字母迷宫.md
│       ├── LCR 130. 衣橱整理.md
│       ├── LCR 131. 砍竹子 I.md
│       ├── LCR 132. 砍竹子 II.md
│       ├── LCR 133. 位 1 的个数.md
│       ├── LCR 134. Pow(x, n).md
│       ├── LCR 135. 报数.md
│       ├── LCR 136. 删除链表节点.md
│       ├── LCR 137. 模糊搜索验证.md
│       ├── LCR 138. 有效数字.md
│       ├── LCR 139. 训练计划 I.md
│       ├── LCR 140. 训练计划 II.md
│       ├── LCR 141. 训练计划 III.md
│       ├── LCR 142. 训练计划 IV.md
│       ├── LCR 143. 子结构判断.md
│       ├── LCR 144. 翻转二叉树.md
│       ├── LCR 145. 判断对称二叉树.md
│       ├── LCR 146. 螺旋遍历二维数组.md
│       ├── LCR 147. 最小栈.md
│       ├── LCR 148. 验证图书取出顺序.md
│       ├── LCR 149. 彩灯装饰记录 I.md
│       ├── LCR 150. 彩灯装饰记录 II.md
│       ├── LCR 151. 彩灯装饰记录 III.md
│       ├── LCR 152. 验证二叉搜索树的后序遍历序列.md
│       ├── LCR 153. 二叉树中和为目标值的路径.md
│       ├── LCR 154. 随机链表的复制.md
│       ├── LCR 155. 将二叉搜索树转化为排序的双向链表.md
│       ├── LCR 156. 序列化与反序列化二叉树.md
│       ├── LCR 157. 套餐内商品的排列顺序.md
│       ├── LCR 158. 库存管理 II.md
│       ├── LCR 159. 库存管理 III.md
│       ├── LCR 160. 数据流中的中位数.md
│       ├── LCR 161. 连续天数的最高销售额.md
│       ├── LCR 162. 数字 1 的个数.md
│       ├── LCR 163. 找到第 k 位数字.md
│       ├── LCR 164. 破解闯关密码.md
│       ├── LCR 165. 解密数字.md
│       ├── LCR 166. 珠宝的最高价值.md
│       ├── LCR 167. 招式拆解 I.md
│       ├── LCR 168. 丑数.md
│       ├── LCR 169. 招式拆解 II.md
│       ├── LCR 170. 交易逆序对的总数.md
│       ├── LCR 171. 训练计划 V.md
│       ├── LCR 172. 统计目标成绩的出现次数.md
│       ├── LCR 173. 点名.md
│       ├── LCR 174. 寻找二叉搜索树中的目标节点.md
│       ├── LCR 175. 计算二叉树的深度.md
│       ├── LCR 176. 判断是否为平衡二叉树.md
│       ├── LCR 177. 撞色搭配.md
│       ├── LCR 178. 训练计划 VI.md
│       ├── LCR 179. 查找总价格为目标值的两个商品.md
│       ├── LCR 180. 文件组合.md
│       ├── LCR 181. 字符串中的单词反转.md
│       ├── LCR 182. 动态口令.md
│       ├── LCR 183. 望远镜中最高的海拔.md
│       ├── LCR 184. 设计自助结算系统.md
│       ├── LCR 185. 统计结果概率.md
│       ├── LCR 186. 文物朝代判断.md
│       ├── LCR 187. 破冰游戏.md
│       ├── LCR 188. 买卖芯片的最佳时机.md
│       ├── LCR 189. 设计机械累加器.md
│       ├── LCR 190. 加密运算.md
│       ├── LCR 191. 按规则计算统计结果.md
│       ├── LCR 192. 把字符串转换成整数 (atoi).md
│       ├── LCR 193. 求二叉搜索树的最近公共祖先.md
│       └── LCR 194. 寻找二叉树的最近公共祖先.md
├── selected_coding_interview/
│   ├── codes/
│   │   ├── cpp/
│   │   │   ├── include/
│   │   │   │   ├── ListNode.hpp
│   │   │   │   ├── PrintUtil.hpp
│   │   │   │   ├── TreeNode.hpp
│   │   │   │   └── include.hpp
│   │   │   ├── lc_101_symmetric_tree/
│   │   │   │   └── lc_101_symmetric_tree_s1.cpp
│   │   │   ├── lc_102_binary_tree_level_order_traversal/
│   │   │   │   └── lc_102_binary_tree_level_order_traversal_s1.cpp
│   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal/
│   │   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal_s1.cpp
│   │   │   │   └── lc_103_binary_tree_zigzag_level_order_traversal_s2.cpp
│   │   │   ├── lc_104_maximum_depth_of_binary_tree/
│   │   │   │   ├── lc_104_maximum_depth_of_binary_tree_s1.cpp
│   │   │   │   └── lc_104_maximum_depth_of_binary_tree_s2.cpp
│   │   │   ├── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal/
│   │   │   │   └── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal_s1.cpp
│   │   │   ├── lc_10_regular_expression_matching/
│   │   │   │   ├── lc_10_regular_expression_matching_s1.cpp
│   │   │   │   └── lc_10_regular_expression_matching_s2.cpp
│   │   │   ├── lc_110_balanced_binary_tree/
│   │   │   │   ├── lc_110_balanced_binary_tree_s1.cpp
│   │   │   │   └── lc_110_balanced_binary_tree_s2.cpp
│   │   │   ├── lc_113_path_sum_ii/
│   │   │   │   └── lc_113_path_sum_ii_s1.cpp
│   │   │   ├── lc_11_container_with_most_water/
│   │   │   │   └── lc_11_container_with_most_water_s1.cpp
│   │   │   ├── lc_121_best_time_to_buy_and_sell_stock/
│   │   │   │   └── lc_121_best_time_to_buy_and_sell_stock_s1.cpp
│   │   │   ├── lc_136_single_number/
│   │   │   │   └── lc_136_single_number_s1.cpp
│   │   │   ├── lc_138_copy_list_with_random_pointer/
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s1.cpp
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s2.cpp
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s3.cpp
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s4.cpp
│   │   │   │   └── lc_138_copy_list_with_random_pointer_s5.cpp
│   │   │   ├── lc_1480_running_sum_of_1d_array/
│   │   │   │   └── lc_1480_running_sum_of_1d_array_s1.cpp
│   │   │   ├── lc_154_find_minimum_in_rotated_sorted_array_ii/
│   │   │   │   ├── lc_154_find_minimum_in_rotated_sorted_array_ii_s1.cpp
│   │   │   │   └── lc_154_find_minimum_in_rotated_sorted_array_ii_s2.cpp
│   │   │   ├── lc_160_intersection_of_two_linked_lists/
│   │   │   │   └── lc_160_intersection_of_two_linked_lists_s1.cpp
│   │   │   ├── lc_167_two_sum_ii_input_array_is_sorted/
│   │   │   │   └── lc_167_two_sum_ii_input_array_is_sorted_s1.cpp
│   │   │   ├── lc_169_majority_element/
│   │   │   │   ├── lc_169_majority_element_s1.cpp
│   │   │   │   └── lc_169_majority_element_s2.cpp
│   │   │   ├── lc_179_largest_number/
│   │   │   │   ├── lc_179_largest_number_s1.cpp
│   │   │   │   └── lc_179_largest_number_s2.cpp
│   │   │   ├── lc_1823_find_the_winner_of_the_circular_game/
│   │   │   │   └── lc_1823_find_the_winner_of_the_circular_game_s1.cpp
│   │   │   ├── lc_191_number_of_1_bits/
│   │   │   │   ├── lc_191_number_of_1_bits_s1.cpp
│   │   │   │   └── lc_191_number_of_1_bits_s2.cpp
│   │   │   ├── lc_205_isomorphic_strings/
│   │   │   │   └── lc_205_isomorphic_strings_s1.cpp
│   │   │   ├── lc_206_reverse_linked_list/
│   │   │   │   ├── lc_206_reverse_linked_list_s1.cpp
│   │   │   │   └── lc_206_reverse_linked_list_s2.cpp
│   │   │   ├── lc_215_kth_largest_element_in_an_array/
│   │   │   │   ├── lc_215_kth_largest_element_in_an_array_s1.cpp
│   │   │   │   └── lc_215_kth_largest_element_in_an_array_s2.cpp
│   │   │   ├── lc_21_merge_two_sorted_lists/
│   │   │   │   └── lc_21_merge_two_sorted_lists_s1.cpp
│   │   │   ├── lc_226_invert_binary_tree/
│   │   │   │   ├── lc_226_invert_binary_tree_s1.cpp
│   │   │   │   └── lc_226_invert_binary_tree_s2.cpp
│   │   │   ├── lc_230_kth_smallest_element_in_a_bst/
│   │   │   │   └── lc_230_kth_smallest_element_in_a_bst_s1.cpp
│   │   │   ├── lc_232_implement_queue_using_stacks/
│   │   │   │   └── lc_232_implement_queue_using_stacks_s1.cpp
│   │   │   ├── lc_233_number_of_digit_one/
│   │   │   │   ├── lc_233_number_of_digit_one_s1.cpp
│   │   │   │   ├── lc_233_number_of_digit_one_s2.cpp
│   │   │   │   └── lc_233_number_of_digit_one_s3.cpp
│   │   │   ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree/
│   │   │   │   ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s1.cpp
│   │   │   │   ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s2.cpp
│   │   │   │   └── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s3.cpp
│   │   │   ├── lc_236_lowest_common_ancestor_of_a_binary_tree/
│   │   │   │   ├── lc_236_lowest_common_ancestor_of_a_binary_tree_s1.cpp
│   │   │   │   └── lc_236_lowest_common_ancestor_of_a_binary_tree_s2.cpp
│   │   │   ├── lc_237_delete_node_in_a_linked_list/
│   │   │   │   ├── lc_237_delete_node_in_a_linked_list_s1.cpp
│   │   │   │   └── lc_237_delete_node_in_a_linked_list_s2.cpp
│   │   │   ├── lc_238_product_of_array_except_self/
│   │   │   │   └── lc_238_product_of_array_except_self_s1.cpp
│   │   │   ├── lc_239_sliding_window_maximum/
│   │   │   │   ├── lc_239_sliding_window_maximum_s1.cpp
│   │   │   │   └── lc_239_sliding_window_maximum_s2.cpp
│   │   │   ├── lc_240_search_a_2d_matrix_ii/
│   │   │   │   └── lc_240_search_a_2d_matrix_ii_s1.cpp
│   │   │   ├── lc_242_valid_anagram/
│   │   │   │   ├── lc_242_valid_anagram_s1.cpp
│   │   │   │   └── lc_242_valid_anagram_s2.cpp
│   │   │   ├── lc_264_ugly_number_ii/
│   │   │   │   └── lc_264_ugly_number_ii_s1.cpp
│   │   │   ├── lc_266_palindrome_permutation/
│   │   │   │   ├── lc_266_palindrome_permutation_s1.cpp
│   │   │   │   └── lc_266_palindrome_permutation_s2.cpp
│   │   │   ├── lc_278_first_bad_version/
│   │   │   │   └── lc_278_first_bad_version_s1.cpp
│   │   │   ├── lc_287_find_the_duplicate_number/
│   │   │   │   ├── lc_287_find_the_duplicate_number_s1.cpp
│   │   │   │   ├── lc_287_find_the_duplicate_number_s2.cpp
│   │   │   │   └── lc_287_find_the_duplicate_number_s3.cpp
│   │   │   ├── lc_295_find_median_from_data_stream/
│   │   │   │   └── lc_295_find_median_from_data_stream_s1.cpp
│   │   │   ├── lc_371_sum_of_two_integers/
│   │   │   │   └── lc_371_sum_of_two_integers_s1.cpp
│   │   │   ├── lc_387_first_unique_character_in_a_string/
│   │   │   │   └── lc_387_first_unique_character_in_a_string_s1.cpp
│   │   │   ├── lc_392_is_subsequence/
│   │   │   │   └── lc_392_is_subsequence_s1.cpp
│   │   │   ├── lc_3_longest_substring_without_repeating_characters/
│   │   │   │   ├── lc_3_longest_substring_without_repeating_characters_s1.cpp
│   │   │   │   └── lc_3_longest_substring_without_repeating_characters_s2.cpp
│   │   │   ├── lc_400_nth_digit/
│   │   │   │   ├── lc_400_nth_digit_s1.cpp
│   │   │   │   ├── lc_400_nth_digit_s2.cpp
│   │   │   │   ├── lc_400_nth_digit_s3.cpp
│   │   │   │   └── lc_400_nth_digit_s4.cpp
│   │   │   ├── lc_409_longest_palindrome/
│   │   │   │   └── lc_409_longest_palindrome_s1.cpp
│   │   │   ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/
│   │   │   │   ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.cpp
│   │   │   │   └── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.cpp
│   │   │   ├── lc_46_permutations/
│   │   │   │   └── lc_46_permutations_s1.cpp
│   │   │   ├── lc_47_permutations_ii/
│   │   │   │   └── lc_47_permutations_ii_s1.cpp
│   │   │   ├── lc_48_rotate_image/
│   │   │   │   ├── lc_48_rotate_image_s1.cpp
│   │   │   │   ├── lc_48_rotate_image_s2.cpp
│   │   │   │   └── lc_48_rotate_image_s3.cpp
│   │   │   ├── lc_509_fibonacci_number/
│   │   │   │   └── lc_509_fibonacci_number_s1.cpp
│   │   │   ├── lc_53_maximum_subarray/
│   │   │   │   └── lc_53_maximum_subarray_s1.cpp
│   │   │   ├── lc_54_spiral_matrix/
│   │   │   │   └── lc_54_spiral_matrix_s1.cpp
│   │   │   ├── lc_65_valid_number/
│   │   │   │   └── lc_65_valid_number_s1.cpp
│   │   │   ├── lc_6_zigzag_conversion/
│   │   │   │   └── lc_6_zigzag_conversion_s1.cpp
│   │   │   ├── lc_704_binary_search/
│   │   │   │   └── lc_704_binary_search_s1.cpp
│   │   │   ├── lc_70_climbing_stairs/
│   │   │   │   └── lc_70_climbing_stairs_s1.cpp
│   │   │   ├── lc_724_find_pivot_index/
│   │   │   │   └── lc_724_find_pivot_index_s1.cpp
│   │   │   ├── lc_796_rotate_string/
│   │   │   │   └── lc_796_rotate_string_s1.cpp
│   │   │   ├── lc_79_word_search/
│   │   │   │   └── lc_79_word_search_s1.cpp
│   │   │   ├── lc_86_partition_list/
│   │   │   │   ├── lc_86_partition_list_s1.cpp
│   │   │   │   └── lc_86_partition_list_s2.cpp
│   │   │   ├── lc_876_middle_of_the_linked_list/
│   │   │   │   └── lc_876_middle_of_the_linked_list_s1.cpp
│   │   │   ├── lc_8_string_to_integer_atoi/
│   │   │   │   └── lc_8_string_to_integer_atoi_s1.cpp
│   │   │   └── lc_946_validate_stack_sequences/
│   │   │       └── lc_946_validate_stack_sequences_s1.cpp
│   │   ├── java/
│   │   │   ├── include/
│   │   │   │   ├── ListNode.java
│   │   │   │   ├── PrintUtil.java
│   │   │   │   └── TreeNode.java
│   │   │   ├── lc_101_symmetric_tree/
│   │   │   │   └── lc_101_symmetric_tree.java
│   │   │   ├── lc_102_binary_tree_level_order_traversal/
│   │   │   │   └── lc_102_binary_tree_level_order_traversal.java
│   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal/
│   │   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal_s1.java
│   │   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal_s2.java
│   │   │   │   └── lc_103_binary_tree_zigzag_level_order_traversal_s3.java
│   │   │   ├── lc_104_maximum_depth_of_binary_tree/
│   │   │   │   ├── lc_104_maximum_depth_of_binary_tree_s1.java
│   │   │   │   └── lc_104_maximum_depth_of_binary_tree_s2.java
│   │   │   ├── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal/
│   │   │   │   └── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal.java
│   │   │   ├── lc_10_regular_expression_matching/
│   │   │   │   ├── lc_10_regular_expression_matching_s1.java
│   │   │   │   └── lc_10_regular_expression_matching_s2.java
│   │   │   ├── lc_110_balanced_binary_tree/
│   │   │   │   ├── lc_110_balanced_binary_tree_s1.java
│   │   │   │   └── lc_110_balanced_binary_tree_s2.java
│   │   │   ├── lc_113_path_sum/
│   │   │   │   └── lc_113_path_sum.java
│   │   │   ├── lc_11_container_with_most_water/
│   │   │   │   └── lc_11_container_with_most_water.java
│   │   │   ├── lc_121_best_time_to_buy_and_sell_stock/
│   │   │   │   └── lc_121_best_time_to_buy_and_sell_stock.java
│   │   │   ├── lc_122_best_time_to_buy_and_sell_stock/
│   │   │   │   └── lc_122_best_time_to_buy_and_sell_stock.java
│   │   │   ├── lc_135_candy/
│   │   │   │   └── lc_135_candy.java
│   │   │   ├── lc_136_single_number/
│   │   │   │   └── lc_136_single_number.java
│   │   │   ├── lc_137_single_number/
│   │   │   │   ├── lc_137_single_number_s1.java
│   │   │   │   └── lc_137_single_number_s2.java
│   │   │   ├── lc_138_copy_list_with_random_pointer/
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s1.java
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s2.java
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s3.java
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s4.java
│   │   │   │   └── lc_138_copy_list_with_random_pointer_s5.java
│   │   │   ├── lc_142_linked_list_cycle/
│   │   │   │   └── lc_142_linked_list_cycle.java
│   │   │   ├── lc_1480_running_sum_of_1d_array/
│   │   │   │   └── lc_1480_running_sum_of_1d_array.java
│   │   │   ├── lc_151_reverse_words_in_a_string/
│   │   │   │   ├── lc_151_reverse_words_in_a_string_s1.java
│   │   │   │   └── lc_151_reverse_words_in_a_string_s2.java
│   │   │   ├── lc_154_find_minimum_in_rotated_sorted_array/
│   │   │   │   ├── lc_154_find_minimum_in_rotated_sorted_array_s1.java
│   │   │   │   └── lc_154_find_minimum_in_rotated_sorted_array_s2.java
│   │   │   ├── lc_155_min_stack/
│   │   │   │   └── lc_155_min_stack.java
│   │   │   ├── lc_15_three_sum/
│   │   │   │   └── lc_15_three_sum.java
│   │   │   ├── lc_160_intersection_of_two_linked_lists/
│   │   │   │   └── lc_160_intersection_of_two_linked_lists.java
│   │   │   ├── lc_167_two_sum/
│   │   │   │   └── lc_167_two_sum.java
│   │   │   ├── lc_169_majority_element/
│   │   │   │   ├── lc_169_majority_element_s1.java
│   │   │   │   └── lc_169_majority_element_s2.java
│   │   │   ├── lc_179_largest_number/
│   │   │   │   ├── lc_179_largest_number_s1.java
│   │   │   │   └── lc_179_largest_number_s2.java
│   │   │   ├── lc_1823_find_the_winner_of_the_circular_game/
│   │   │   │   └── lc_1823_find_the_winner_of_the_circular_game.java
│   │   │   ├── lc_191_number_of_1_bits/
│   │   │   │   ├── lc_191_number_of_1_bits_s1.java
│   │   │   │   └── lc_191_number_of_1_bits_s2.java
│   │   │   ├── lc_198_house_robber/
│   │   │   │   └── lc_198_house_robber.java
│   │   │   ├── lc_205_isomorphic_strings/
│   │   │   │   └── lc_205_isomorphic_strings.java
│   │   │   ├── lc_206_reverse_linked_list/
│   │   │   │   ├── lc_206_reverse_linked_list_s1.java
│   │   │   │   └── lc_206_reverse_linked_list_s2.java
│   │   │   ├── lc_207_course_schedule/
│   │   │   │   ├── lc_207_course_schedule_s1.java
│   │   │   │   └── lc_207_course_schedule_s2.java
│   │   │   ├── lc_20_valid_parentheses/
│   │   │   │   └── lc_20_valid_parentheses.java
│   │   │   ├── lc_213_house_robber/
│   │   │   │   └── lc_213_house_robber.java
│   │   │   ├── lc_215_kth_largest_element_in_an_array/
│   │   │   │   ├── lc_215_kth_largest_element_in_an_array_s1.java
│   │   │   │   └── lc_215_kth_largest_element_in_an_array_s2.java
│   │   │   ├── lc_21_merge_two_sorted_lists/
│   │   │   │   └── lc_21_merge_two_sorted_lists.java
│   │   │   ├── lc_226_invert_binary_tree/
│   │   │   │   ├── lc_226_invert_binary_tree_s1.java
│   │   │   │   └── lc_226_invert_binary_tree_s2.java
│   │   │   ├── lc_230_kth_smallest_element_in_a_bst/
│   │   │   │   └── lc_230_kth_smallest_element_in_a_bst.java
│   │   │   ├── lc_231_power_of_two/
│   │   │   │   └── lc_231_power_of_two.java
│   │   │   ├── lc_232_implement_queue_using_stacks/
│   │   │   │   └── lc_232_implement_queue_using_stacks.java
│   │   │   ├── lc_233_number_of_digit_one/
│   │   │   │   ├── lc_233_number_of_digit_one_s1.java
│   │   │   │   ├── lc_233_number_of_digit_one_s2.java
│   │   │   │   └── lc_233_number_of_digit_one_s3.java
│   │   │   ├── lc_235_lowest_common_ancestor_of_bst/
│   │   │   │   ├── lc_235_lowest_common_ancestor_of_bst_s1.java
│   │   │   │   ├── lc_235_lowest_common_ancestor_of_bst_s2.java
│   │   │   │   └── lc_235_lowest_common_ancestor_of_bst_s3.java
│   │   │   ├── lc_236_lowest_common_ancestor_of_binary_tree/
│   │   │   │   ├── lc_236_lowest_common_ancestor_of_binary_tree_s1.java
│   │   │   │   └── lc_236_lowest_common_ancestor_of_binary_tree_s2.java
│   │   │   ├── lc_237_delete_node_in_linked_list/
│   │   │   │   ├── lc_237_delete_node_in_linked_list_s1.java
│   │   │   │   └── lc_237_delete_node_in_linked_list_s2.java
│   │   │   ├── lc_238_product_of_array_except_self/
│   │   │   │   └── lc_238_product_of_array_except_self.java
│   │   │   ├── lc_239_sliding_window_maximum/
│   │   │   │   ├── lc_239_sliding_window_maximum_s1.java
│   │   │   │   └── lc_239_sliding_window_maximum_s2.java
│   │   │   ├── lc_240_search_a_2d_matrix/
│   │   │   │   └── lc_240_search_a_2d_matrix.java
│   │   │   ├── lc_242_valid_anagram/
│   │   │   │   ├── lc_242_valid_anagram_s1.java
│   │   │   │   └── lc_242_valid_anagram_s2.java
│   │   │   ├── lc_264_ugly_number/
│   │   │   │   └── lc_264_ugly_number.java
│   │   │   ├── lc_266_palindrome_permutation/
│   │   │   │   ├── lc_266_palindrome_permutation_s1.java
│   │   │   │   └── lc_266_palindrome_permutation_s2.java
│   │   │   ├── lc_278_first_bad_version/
│   │   │   │   └── lc_278_first_bad_version.java
│   │   │   ├── lc_287_find_the_duplicate_number/
│   │   │   │   ├── lc_287_find_the_duplicate_number_s1.java
│   │   │   │   ├── lc_287_find_the_duplicate_number_s2.java
│   │   │   │   └── lc_287_find_the_duplicate_number_s3.java
│   │   │   ├── lc_295_find_median_from_data_stream/
│   │   │   │   └── lc_295_find_median_from_data_stream.java
│   │   │   ├── lc_297_serialize_and_deserialize_binary_tree/
│   │   │   │   └── lc_297_serialize_and_deserialize_binary_tree.java
│   │   │   ├── lc_300_longest_increasing_subsequence/
│   │   │   │   ├── lc_300_longest_increasing_subsequence_s1.java
│   │   │   │   └── lc_300_longest_increasing_subsequence_s2.java
│   │   │   ├── lc_343_integer_break/
│   │   │   │   └── lc_343_integer_break.java
│   │   │   ├── lc_371_sum_of_two_integers/
│   │   │   │   └── lc_371_sum_of_two_integers.java
│   │   │   ├── lc_387_first_unique_character_in_a_string/
│   │   │   │   └── lc_387_first_unique_character_in_a_string.java
│   │   │   ├── lc_392_is_subsequence/
│   │   │   │   └── lc_392_is_subsequence.java
│   │   │   ├── lc_394_decode_string/
│   │   │   │   ├── lc_394_decode_string_s1.java
│   │   │   │   └── lc_394_decode_string_s2.java
│   │   │   ├── lc_3_longest_substring_without_repeating_characters/
│   │   │   │   ├── lc_3_longest_substring_without_repeating_characters_s1.java
│   │   │   │   └── lc_3_longest_substring_without_repeating_characters_s2.java
│   │   │   ├── lc_400_nth_digit/
│   │   │   │   ├── lc_400_nth_digit_s1.java
│   │   │   │   ├── lc_400_nth_digit_s2.java
│   │   │   │   ├── lc_400_nth_digit_s3.java
│   │   │   │   └── lc_400_nth_digit_s4.java
│   │   │   ├── lc_409_longest_palindrome/
│   │   │   │   └── lc_409_longest_palindrome.java
│   │   │   ├── lc_415_add_strings/
│   │   │   │   └── lc_415_add_strings.java
│   │   │   ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/
│   │   │   │   ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.java
│   │   │   │   └── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.java
│   │   │   ├── lc_46_permutations/
│   │   │   │   └── lc_46_permutations.java
│   │   │   ├── lc_47_permutations/
│   │   │   │   └── lc_47_permutations.java
│   │   │   ├── lc_48_rotate_image/
│   │   │   │   ├── lc_48_rotate_image_s1.java
│   │   │   │   ├── lc_48_rotate_image_s2.java
│   │   │   │   └── lc_48_rotate_image_s3.java
│   │   │   ├── lc_509_fibonacci_number/
│   │   │   │   └── lc_509_fibonacci_number.java
│   │   │   ├── lc_50_powx_n/
│   │   │   │   └── lc_50_powx_n.java
│   │   │   ├── lc_53_maximum_subarray/
│   │   │   │   └── lc_53_maximum_subarray.java
│   │   │   ├── lc_54_spiral_matrix/
│   │   │   │   └── lc_54_spiral_matrix.java
│   │   │   ├── lc_59_spiral_matrix/
│   │   │   │   └── lc_59_spiral_matrix.java
│   │   │   ├── lc_64_minimum_path_sum/
│   │   │   │   └── lc_64_minimum_path_sum.java
│   │   │   ├── lc_65_valid_number/
│   │   │   │   └── lc_65_valid_number.java
│   │   │   ├── lc_6_zigzag_conversion/
│   │   │   │   └── lc_6_zigzag_conversion.java
│   │   │   ├── lc_704_binary_search/
│   │   │   │   └── lc_704_binary_search.java
│   │   │   ├── lc_70_climbing_stairs/
│   │   │   │   └── lc_70_climbing_stairs.java
│   │   │   ├── lc_724_find_pivot_index/
│   │   │   │   └── lc_724_find_pivot_index.java
│   │   │   ├── lc_796_rotate_string/
│   │   │   │   └── lc_796_rotate_string.java
│   │   │   ├── lc_79_word_search/
│   │   │   │   └── lc_79_word_search.java
│   │   │   ├── lc_86_partition_list/
│   │   │   │   ├── lc_86_partition_list_s1.java
│   │   │   │   └── lc_86_partition_list_s2.java
│   │   │   ├── lc_876_middle_of_the_linked_list/
│   │   │   │   └── lc_876_middle_of_the_linked_list.java
│   │   │   ├── lc_89_gray_code/
│   │   │   │   └── lc_89_gray_code.java
│   │   │   ├── lc_8_string_to_integer_atoi/
│   │   │   │   ├── lc_8_string_to_integer_atoi_s1.java
│   │   │   │   └── lc_8_string_to_integer_atoi_s2.java
│   │   │   └── lc_946_validate_stack_sequences/
│   │   │       └── lc_946_validate_stack_sequences.java
│   │   └── python/
│   │       ├── fix_tests.py
│   │       ├── include/
│   │       │   ├── __init__.py
│   │       │   ├── binary_tree.py
│   │       │   ├── linked_list.py
│   │       │   └── print_util.py
│   │       ├── lc_101_symmetric_tree.py
│   │       ├── lc_102_binary_tree_level_order_traversal.py
│   │       ├── lc_103_binary_tree_zigzag_level_order_traversal_s1.py
│   │       ├── lc_103_binary_tree_zigzag_level_order_traversal_s2.py
│   │       ├── lc_103_binary_tree_zigzag_level_order_traversal_s3.py
│   │       ├── lc_104_maximum_depth_of_binary_tree_s1.py
│   │       ├── lc_104_maximum_depth_of_binary_tree_s2.py
│   │       ├── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal.py
│   │       ├── lc_10_regular_expression_matching_s1.py
│   │       ├── lc_10_regular_expression_matching_s2.py
│   │       ├── lc_110_balanced_binary_tree_s1.py
│   │       ├── lc_110_balanced_binary_tree_s2.py
│   │       ├── lc_113_path_sum_ii.py
│   │       ├── lc_11_container_with_most_water.py
│   │       ├── lc_121_best_time_to_buy_and_sell_stock.py
│   │       ├── lc_122_best_time_to_buy_and_sell_stock_ii.py
│   │       ├── lc_135_candy.py
│   │       ├── lc_136_single_number.py
│   │       ├── lc_137_single_number_ii_s1.py
│   │       ├── lc_137_single_number_ii_s2.py
│   │       ├── lc_138_copy_list_with_random_pointer_s1.py
│   │       ├── lc_138_copy_list_with_random_pointer_s2.py
│   │       ├── lc_138_copy_list_with_random_pointer_s3.py
│   │       ├── lc_138_copy_list_with_random_pointer_s4.py
│   │       ├── lc_138_copy_list_with_random_pointer_s5.py
│   │       ├── lc_142_linked_list_cycle_ii.py
│   │       ├── lc_1480_running_sum_of_1d_array.py
│   │       ├── lc_151_reverse_words_in_a_string_s1.py
│   │       ├── lc_151_reverse_words_in_a_string_s2.py
│   │       ├── lc_151_reverse_words_in_a_string_s3.py
│   │       ├── lc_154_find_minimum_in_rotated_sorted_array_ii_s1.py
│   │       ├── lc_154_find_minimum_in_rotated_sorted_array_ii_s2.py
│   │       ├── lc_155_min_stack.py
│   │       ├── lc_15_three_sum.py
│   │       ├── lc_160_intersection_of_two_linked_lists.py
│   │       ├── lc_167_two_sum_ii.py
│   │       ├── lc_169_majority_element_s1.py
│   │       ├── lc_169_majority_element_s2.py
│   │       ├── lc_179_largest_number_s1.py
│   │       ├── lc_179_largest_number_s2.py
│   │       ├── lc_1823_find_the_winner_of_the_circular_game.py
│   │       ├── lc_191_number_of_1_bits_s1.py
│   │       ├── lc_191_number_of_1_bits_s2.py
│   │       ├── lc_198_house_robber.py
│   │       ├── lc_205_isomorphic_strings.py
│   │       ├── lc_206_reverse_linked_list_s1.py
│   │       ├── lc_206_reverse_linked_list_s2.py
│   │       ├── lc_206_reverse_linked_list_s3.py
│   │       ├── lc_207_course_schedule_s1.py
│   │       ├── lc_207_course_schedule_s2.py
│   │       ├── lc_20_valid_parentheses.py
│   │       ├── lc_213_house_robber_ii.py
│   │       ├── lc_215_kth_largest_element_in_an_array_s1.py
│   │       ├── lc_215_kth_largest_element_in_an_array_s2.py
│   │       ├── lc_21_merge_two_sorted_lists.py
│   │       ├── lc_226_invert_binary_tree_s1.py
│   │       ├── lc_226_invert_binary_tree_s2.py
│   │       ├── lc_226_invert_binary_tree_s3.py
│   │       ├── lc_230_kth_smallest_element_in_a_bst.py
│   │       ├── lc_231_power_of_two.py
│   │       ├── lc_232_implement_queue_using_stacks.py
│   │       ├── lc_233_number_of_digit_one_s1.py
│   │       ├── lc_233_number_of_digit_one_s2.py
│   │       ├── lc_233_number_of_digit_one_s3.py
│   │       ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s1.py
│   │       ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s2.py
│   │       ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s3.py
│   │       ├── lc_236_lowest_common_ancestor_of_a_binary_tree_s1.py
│   │       ├── lc_236_lowest_common_ancestor_of_a_binary_tree_s2.py
│   │       ├── lc_237_delete_node_in_a_linked_list_s1.py
│   │       ├── lc_237_delete_node_in_a_linked_list_s2.py
│   │       ├── lc_238_product_of_array_except_self.py
│   │       ├── lc_239_sliding_window_maximum_s1.py
│   │       ├── lc_239_sliding_window_maximum_s2.py
│   │       ├── lc_240_search_a_2d_matrix_ii.py
│   │       ├── lc_242_valid_anagram_s1.py
│   │       ├── lc_242_valid_anagram_s2.py
│   │       ├── lc_264_ugly_number_ii.py
│   │       ├── lc_266_palindrome_permutation_s1.py
│   │       ├── lc_266_palindrome_permutation_s2.py
│   │       ├── lc_278_first_bad_version.py
│   │       ├── lc_287_find_the_duplicate_number_s1.py
│   │       ├── lc_287_find_the_duplicate_number_s2.py
│   │       ├── lc_287_find_the_duplicate_number_s3.py
│   │       ├── lc_295_find_median_from_data_stream_s1.py
│   │       ├── lc_295_find_median_from_data_stream_s2.py
│   │       ├── lc_297_serialize_and_deserialize_binary_tree.py
│   │       ├── lc_300_longest_increasing_subsequence_s1.py
│   │       ├── lc_300_longest_increasing_subsequence_s2.py
│   │       ├── lc_343_integer_break.py
│   │       ├── lc_371_sum_of_two_integers.py
│   │       ├── lc_387_first_unique_character_in_a_string.py
│   │       ├── lc_392_is_subsequence.py
│   │       ├── lc_394_decode_string_s1.py
│   │       ├── lc_394_decode_string_s2.py
│   │       ├── lc_39_combination_sum_s1.py
│   │       ├── lc_39_combination_sum_s2.py
│   │       ├── lc_3_longest_substring_without_repeating_characters_s1.py
│   │       ├── lc_3_longest_substring_without_repeating_characters_s2.py
│   │       ├── lc_400_nth_digit_s1.py
│   │       ├── lc_400_nth_digit_s2.py
│   │       ├── lc_400_nth_digit_s3.py
│   │       ├── lc_400_nth_digit_s4.py
│   │       ├── lc_409_longest_palindrome.py
│   │       ├── lc_40_combination_sum_ii_s1.py
│   │       ├── lc_40_combination_sum_ii_s2.py
│   │       ├── lc_415_add_strings.py
│   │       ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.py
│   │       ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.py
│   │       ├── lc_46_permutations.py
│   │       ├── lc_47_permutations_ii.py
│   │       ├── lc_48_rotate_image_s1.py
│   │       ├── lc_48_rotate_image_s2.py
│   │       ├── lc_48_rotate_image_s3.py
│   │       ├── lc_509_fibonacci_number.py
│   │       ├── lc_50_powx_n.py
│   │       ├── lc_53_maximum_subarray.py
│   │       ├── lc_54_spiral_matrix.py
│   │       ├── lc_59_spiral_matrix_ii.py
│   │       ├── lc_64_minimum_path_sum.py
│   │       ├── lc_65_valid_number.py
│   │       ├── lc_6_zigzag_conversion.py
│   │       ├── lc_704_binary_search.py
│   │       ├── lc_70_climbing_stairs.py
│   │       ├── lc_724_find_pivot_index.py
│   │       ├── lc_768_max_chunks_to_make_sorted_ii.py
│   │       ├── lc_796_rotate_string.py
│   │       ├── lc_79_word_search.py
│   │       ├── lc_86_partition_list_s1.py
│   │       ├── lc_86_partition_list_s2.py
│   │       ├── lc_876_middle_of_the_linked_list.py
│   │       ├── lc_89_gray_code.py
│   │       ├── lc_8_string_to_integer_atoi_s1.py
│   │       ├── lc_8_string_to_integer_atoi_s2.py
│   │       └── lc_946_validate_stack_sequences.py
│   └── docs/
│       ├── 10. 正则表达式匹配.md
│       ├── 101. 对称二叉树.md
│       ├── 102. 二叉树的层序遍历.md
│       ├── 103. 二叉树的锯齿形层序遍历.md
│       ├── 104. 二叉树的最大深度.md
│       ├── 105. 从前序与中序遍历序列构造二叉树.md
│       ├── 11. 盛最多水的容器.md
│       ├── 110. 平衡二叉树.md
│       ├── 113. 路径总和 II.md
│       ├── 121. 买卖股票的最佳时机.md
│       ├── 122. 买卖股票的最佳时机 II .md
│       ├── 135. 分发糖果.md
│       ├── 136. 只出现一次的数字.md
│       ├── 137. 只出现一次的数字 II.md
│       ├── 138. 复制带随机指针的链表.md
│       ├── 142. 环形链表 II.md
│       ├── 1480. 一维数组的动态和.md
│       ├── 15. 三数之和.md
│       ├── 151. 反转字符串中的单词.md
│       ├── 154. 寻找旋转排序数组中的最小值 II.md
│       ├── 155. 最小栈 .md
│       ├── 160. 相交链表.md
│       ├── 167. 两数之和 II.md
│       ├── 169. 多数元素.md
│       ├── 179. 最大数.md
│       ├── 1823. 找出游戏的获胜者.md
│       ├── 191. 位1的个数.md
│       ├── 198. 打家劫舍.md
│       ├── 20. 有效的括号.md
│       ├── 205. 同构字符串.md
│       ├── 206. 反转链表.md
│       ├── 207. 课程表.md
│       ├── 21. 合并两个有序链表.md
│       ├── 213. 打家劫舍 II.md
│       ├── 215. 数组中的第K个最大元素.md
│       ├── 226. 翻转二叉树.md
│       ├── 230. 二叉搜索树中第K小的元素.md
│       ├── 231. 2 的幂.md
│       ├── 232. 用栈实现队列.md
│       ├── 233. 数字 1 的个数.md
│       ├── 235. 二叉搜索树的最近公共祖先.md
│       ├── 236. 二叉树的最近公共祖先.md
│       ├── 237. 删除链表中的节点.md
│       ├── 238. 除自身以外数组的乘积.md
│       ├── 239. 滑动窗口最大值.md
│       ├── 240. 搜索二维矩阵 II.md
│       ├── 242. 有效的字母异位词.md
│       ├── 264. 丑数 II .md
│       ├── 266. 回文排列.md
│       ├── 278. 第一个错误的版本.md
│       ├── 287. 寻找重复数.md
│       ├── 295. 数据流的中位数.md
│       ├── 297. 二叉树的序列化与反序列化.md
│       ├── 3. 无重复字符的最长子串.md
│       ├── 300. 最长递增子序列.md
│       ├── 343. 整数拆分.md
│       ├── 371. 两整数之和.md
│       ├── 387. 字符串中的第一个唯一字符.md
│       ├── 39. 组合总和.md
│       ├── 392. 判断子序列.md
│       ├── 394. 字符串解码.md
│       ├── 40. 组合总和 II.md
│       ├── 400. 第 N 位数字.md
│       ├── 409. 最长回文串.md
│       ├── 415. 字符串相加.md
│       ├── 426. 将二叉搜索树转化为排序的双向链表.md
│       ├── 46. 全排列.md
│       ├── 47. 全排列 II.md
│       ├── 48. 旋转图像.md
│       ├── 50. Pow(x, n).md
│       ├── 509. 斐波那契数.md
│       ├── 53. 最大子数组和.md
│       ├── 54. 螺旋矩阵.md
│       ├── 59. 螺旋矩阵 II.md
│       ├── 6. N 字形变换.md
│       ├── 64. 最小路径和.md
│       ├── 65. 有效数字.md
│       ├── 70. 爬楼梯.md
│       ├── 704. 二分查找.md
│       ├── 724. 寻找数组的中心下标.md
│       ├── 768. 最多能完成排序的块 II.md
│       ├── 79. 单词搜索.md
│       ├── 796. 旋转字符串.md
│       ├── 8. 字符串转换整数 (atoi).md
│       ├── 86. 分隔链表.md
│       ├── 876. 链表的中间结点.md
│       ├── 89. 格雷编码.md
│       └── 946. 验证栈序列.md
└── sword_for_offer/
    ├── codes/
    │   ├── cpp/
    │   │   ├── include/
    │   │   │   ├── ListNode.hpp
    │   │   │   ├── PrintUtil.hpp
    │   │   │   ├── TreeNode.hpp
    │   │   │   └── include.hpp
    │   │   ├── sfo_03_find_duplicate_numbers_in_an_array_s1/
    │   │   │   └── sfo_03_find_duplicate_numbers_in_an_array_s1.cpp
    │   │   ├── sfo_03_find_duplicate_numbers_in_an_array_s2/
    │   │   │   └── sfo_03_find_duplicate_numbers_in_an_array_s2.cpp
    │   │   ├── sfo_04_find_a_number_in_2d_matrix_s1/
    │   │   │   └── sfo_04_find_a_number_in_2d_matrix_s1.cpp
    │   │   ├── sfo_05_replace_spaces_s1/
    │   │   │   └── sfo_05_replace_spaces_s1.cpp
    │   │   ├── sfo_06_print_a_linked_list_in_reverse_order_s1/
    │   │   │   └── sfo_06_print_a_linked_list_in_reverse_order_s1.cpp
    │   │   ├── sfo_06_print_a_linked_list_in_reverse_order_s2/
    │   │   │   └── sfo_06_print_a_linked_list_in_reverse_order_s2.cpp
    │   │   ├── sfo_07_reconstruct_binary_tree_s1/
    │   │   │   └── sfo_07_reconstruct_binary_tree_s1.cpp
    │   │   ├── sfo_09_implement_a_queue_using_two_stacks_s1/
    │   │   │   └── sfo_09_implement_a_queue_using_two_stacks_s1.cpp
    │   │   ├── sfo_10i_fibonacci_numbers_s1/
    │   │   │   └── sfo_10i_fibonacci_numbers_s1.cpp
    │   │   ├── sfo_10ii_frog_jump_s1/
    │   │   │   └── sfo_10ii_frog_jump_s1.cpp
    │   │   ├── sfo_11_find_minimum_in_rotated_sorted_array_s1/
    │   │   │   └── sfo_11_find_minimum_in_rotated_sorted_array_s1.cpp
    │   │   ├── sfo_11_find_minimum_in_rotated_sorted_array_s2/
    │   │   │   └── sfo_11_find_minimum_in_rotated_sorted_array_s2.cpp
    │   │   ├── sfo_12_word_search_s1/
    │   │   │   └── sfo_12_word_search_s1.cpp
    │   │   ├── sfo_13_range_of_motion_of_a_robot_s1/
    │   │   │   └── sfo_13_range_of_motion_of_a_robot_s1.cpp
    │   │   ├── sfo_13_range_of_motion_of_a_robot_s2/
    │   │   │   └── sfo_13_range_of_motion_of_a_robot_s2.cpp
    │   │   ├── sfo_14i_cut_the_rope_i_s1/
    │   │   │   └── sfo_14i_cut_the_rope_i_s1.cpp
    │   │   ├── sfo_14ii_cut_the_rope_ii_s1/
    │   │   │   └── sfo_14ii_cut_the_rope_ii_s1.cpp
    │   │   ├── sfo_15_number_of_1_bits_s1/
    │   │   │   └── sfo_15_number_of_1_bits_s1.cpp
    │   │   ├── sfo_15_number_of_1_bits_s2/
    │   │   │   └── sfo_15_number_of_1_bits_s2.cpp
    │   │   ├── sfo_16_powers_of_integers_s1/
    │   │   │   └── sfo_16_powers_of_integers_s1.cpp
    │   │   ├── sfo_18_delete_a_node_from_a_linked_list_s1/
    │   │   │   └── sfo_18_delete_a_node_from_a_linked_list_s1.cpp
    │   │   ├── sfo_19_regular_expression_matching_s1/
    │   │   │   └── sfo_19_regular_expression_matching_s1.cpp
    │   │   ├── sfo_19_regular_expression_matching_s2/
    │   │   │   └── sfo_19_regular_expression_matching_s2.cpp
    │   │   ├── sfo_21_adjust_the_order_of_numbers_in_an_array_s1/
    │   │   │   └── sfo_21_adjust_the_order_of_numbers_in_an_array_s1.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
    │   │   ├── 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
    │   │   ├── sfo_24_reverse_a_linked_list_s1/
    │   │   │   └── sfo_24_reverse_a_linked_list_s1.cpp
    │   │   ├── sfo_24_reverse_a_linked_list_s2/
    │   │   │   └── sfo_24_reverse_a_linked_list_s2.cpp
    │   │   ├── sfo_25_combine_two_sorted_linked_lists_s1/
    │   │   │   └── sfo_25_combine_two_sorted_linked_lists_s1.cpp
    │   │   ├── sfo_26_substructure_of_a_binary_tree_s1/
    │   │   │   └── sfo_26_substructure_of_a_binary_tree_s1.cpp
    │   │   ├── sfo_27_mirror_of_a_binary_tree_s1/
    │   │   │   └── sfo_27_mirror_of_a_binary_tree_s1.cpp
    │   │   ├── sfo_27_mirror_of_a_binary_tree_s2/
    │   │   │   └── sfo_27_mirror_of_a_binary_tree_s2.cpp
    │   │   ├── sfo_28_symmetric_binary_tree_s1/
    │   │   │   └── sfo_28_symmetric_binary_tree_s1.cpp
    │   │   ├── sfo_29_print_a_given_matrix_in_spiral_form_s1/
    │   │   │   └── sfo_29_print_a_given_matrix_in_spiral_form_s1.cpp
    │   │   ├── sfo_30_min_stack_s1/
    │   │   │   └── sfo_30_min_stack_s1.cpp
    │   │   ├── sfo_31_validate_stack_sequences_s1/
    │   │   │   └── sfo_31_validate_stack_sequences_s1.cpp
    │   │   ├── sfo_32i_print_a_binary_tree_topbottom_i_s1/
    │   │   │   └── sfo_32i_print_a_binary_tree_topbottom_i_s1.cpp
    │   │   ├── sfo_32ii_print_a_binary_tree_topbottom_ii_s1/
    │   │   │   └── sfo_32ii_print_a_binary_tree_topbottom_ii_s1.cpp
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s1/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s1.cpp
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s2/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s2.cpp
    │   │   ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_33_postorder_traversal_of_a_binary_search_tree_s1.cpp
    │   │   ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s2/
    │   │   │   └── sfo_33_postorder_traversal_of_a_binary_search_tree_s2.cpp
    │   │   ├── sfo_34_all_xsum_paths_in_a_binary_tree_s1/
    │   │   │   └── sfo_34_all_xsum_paths_in_a_binary_tree_s1.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
    │   │   ├── 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
    │   │   ├── sfo_36_binary_search_tree_and_doubly_linked_list_s1/
    │   │   │   └── sfo_36_binary_search_tree_and_doubly_linked_list_s1.cpp
    │   │   ├── sfo_37_serialize_and_deserialize_a_binary_tree_s1/
    │   │   │   └── sfo_37_serialize_and_deserialize_a_binary_tree_s1.cpp
    │   │   ├── sfo_38_all_permutations_of_a_string_s1/
    │   │   │   └── sfo_38_all_permutations_of_a_string_s1.cpp
    │   │   ├── sfo_39_the_majority_element_in_an_array_s1/
    │   │   │   └── sfo_39_the_majority_element_in_an_array_s1.cpp
    │   │   ├── sfo_39_the_majority_element_in_an_array_s2/
    │   │   │   └── sfo_39_the_majority_element_in_an_array_s2.cpp
    │   │   ├── sfo_40_the_smallest_k_numbers_s1/
    │   │   │   └── sfo_40_the_smallest_k_numbers_s1.cpp
    │   │   ├── sfo_40_the_smallest_k_numbers_s2/
    │   │   │   └── sfo_40_the_smallest_k_numbers_s2.cpp
    │   │   ├── sfo_41_find_median_from_data_stream_s1/
    │   │   │   └── sfo_41_find_median_from_data_stream_s1.cpp
    │   │   ├── sfo_42_largest_sum_contiguous_subarray_s1/
    │   │   │   └── sfo_42_largest_sum_contiguous_subarray_s1.cpp
    │   │   ├── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1/
    │   │   │   └── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1.cpp
    │   │   ├── sfo_44_nth_digit_s1/
    │   │   │   └── sfo_44_nth_digit_s1.cpp
    │   │   ├── sfo_45_arrange_an_array_into_the_smallest_number_s1/
    │   │   │   └── sfo_45_arrange_an_array_into_the_smallest_number_s1.cpp
    │   │   ├── sfo_45_arrange_an_array_into_the_smallest_number_s2/
    │   │   │   └── sfo_45_arrange_an_array_into_the_smallest_number_s2.cpp
    │   │   ├── sfo_46_translate_numbers_into_strings_s1/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s1.cpp
    │   │   ├── sfo_46_translate_numbers_into_strings_s2/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s2.cpp
    │   │   ├── sfo_46_translate_numbers_into_strings_s3/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s3.cpp
    │   │   ├── sfo_47_the_maximum_value_of_gifts_s1/
    │   │   │   └── sfo_47_the_maximum_value_of_gifts_s1.cpp
    │   │   ├── sfo_47_the_maximum_value_of_gifts_s2/
    │   │   │   └── sfo_47_the_maximum_value_of_gifts_s2.cpp
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s1/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s1.cpp
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s2/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s2.cpp
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s3/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s3.cpp
    │   │   ├── sfo_49_ugly_numbers_s1/
    │   │   │   └── sfo_49_ugly_numbers_s1.cpp
    │   │   ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1/
    │   │   │   └── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.cpp
    │   │   ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2/
    │   │   │   └── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.cpp
    │   │   ├── sfo_51_reversed_pairs_in_an_array_s1/
    │   │   │   └── sfo_51_reversed_pairs_in_an_array_s1.cpp
    │   │   ├── sfo_52_the_first_common_node_in_two_linked_lists_s1/
    │   │   │   └── sfo_52_the_first_common_node_in_two_linked_lists_s1.cpp
    │   │   ├── sfo_53i_find_a_number_in_a_sorted_array_s1/
    │   │   │   └── sfo_53i_find_a_number_in_a_sorted_array_s1.cpp
    │   │   ├── sfo_53i_find_a_number_in_a_sorted_array_s2/
    │   │   │   └── sfo_53i_find_a_number_in_a_sorted_array_s2.cpp
    │   │   ├── sfo_53ii_the_missing_number_from_0_to_n1_s1/
    │   │   │   └── sfo_53ii_the_missing_number_from_0_to_n1_s1.cpp
    │   │   ├── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.cpp
    │   │   ├── sfo_55i_depth_of_a_binary_tree_s1/
    │   │   │   └── sfo_55i_depth_of_a_binary_tree_s1.cpp
    │   │   ├── sfo_55i_depth_of_a_binary_tree_s2/
    │   │   │   └── sfo_55i_depth_of_a_binary_tree_s2.cpp
    │   │   ├── sfo_55ii_balanced_binary_tree_s1/
    │   │   │   └── sfo_55ii_balanced_binary_tree_s1.cpp
    │   │   ├── sfo_55ii_balanced_binary_tree_s2/
    │   │   │   └── sfo_55ii_balanced_binary_tree_s2.cpp
    │   │   ├── sfo_56i_single_number_i_s1/
    │   │   │   └── sfo_56i_single_number_i_s1.cpp
    │   │   ├── sfo_56ii_single_number_ii_s1/
    │   │   │   └── sfo_56ii_single_number_ii_s1.cpp
    │   │   ├── sfo_56ii_single_number_ii_s2/
    │   │   │   └── sfo_56ii_single_number_ii_s2.cpp
    │   │   ├── sfo_57_two_numbers_with_sum_s_s1/
    │   │   │   └── sfo_57_two_numbers_with_sum_s_s1.cpp
    │   │   ├── sfo_57ii_consecutive_numbers_with_sum_s_s1/
    │   │   │   └── sfo_57ii_consecutive_numbers_with_sum_s_s1.cpp
    │   │   ├── sfo_57ii_consecutive_numbers_with_sum_s_s2/
    │   │   │   └── sfo_57ii_consecutive_numbers_with_sum_s_s2.cpp
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s1/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s1.cpp
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s2/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s2.cpp
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s3/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s3.cpp
    │   │   ├── sfo_59ii_max_queue_s1/
    │   │   │   └── sfo_59ii_max_queue_s1.cpp
    │   │   ├── sfo_60_probabilities_for_rolling_n_dices_s1/
    │   │   │   └── sfo_60_probabilities_for_rolling_n_dices_s1.cpp
    │   │   ├── sfo_61_straight_in_poker_s1/
    │   │   │   └── sfo_61_straight_in_poker_s1.cpp
    │   │   ├── sfo_61_straight_in_poker_s2/
    │   │   │   └── sfo_61_straight_in_poker_s2.cpp
    │   │   ├── sfo_62_josephus_problem_s1/
    │   │   │   └── sfo_62_josephus_problem_s1.cpp
    │   │   ├── sfo_63_the_maximum_profit_of_stocks_s1/
    │   │   │   └── sfo_63_the_maximum_profit_of_stocks_s1.cpp
    │   │   ├── sfo_64_solve_1_2___n_s1/
    │   │   │   └── sfo_64_solve_1_2___n_s1.cpp
    │   │   ├── sfo_65_implement_addition_operation_without_arithmetic_operators_s1/
    │   │   │   └── sfo_65_implement_addition_operation_without_arithmetic_operators_s1.cpp
    │   │   ├── sfo_66_a_product_array_puzzle_s1/
    │   │   │   └── sfo_66_a_product_array_puzzle_s1.cpp
    │   │   ├── sfo_67_convert_string_to_int_s1/
    │   │   │   └── sfo_67_convert_string_to_int_s1.cpp
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.cpp
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.cpp
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.cpp
    │   │   ├── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1/
    │   │   │   └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1.cpp
    │   │   └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2/
    │   │       └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2.cpp
    │   ├── java/
    │   │   ├── include/
    │   │   │   ├── ListNode.java
    │   │   │   ├── PrintUtil.java
    │   │   │   └── TreeNode.java
    │   │   ├── sfo_03_find_duplicate_numbers_in_an_array_s1/
    │   │   │   └── sfo_03_find_duplicate_numbers_in_an_array_s1.java
    │   │   ├── sfo_03_find_duplicate_numbers_in_an_array_s2/
    │   │   │   └── sfo_03_find_duplicate_numbers_in_an_array_s2.java
    │   │   ├── sfo_04_find_a_number_in_2d_matrix_s1/
    │   │   │   └── sfo_04_find_a_number_in_2d_matrix_s1.java
    │   │   ├── sfo_05_replace_spaces_s1/
    │   │   │   └── sfo_05_replace_spaces_s1.java
    │   │   ├── sfo_06_print_a_linked_list_in_reverse_order_s1/
    │   │   │   └── sfo_06_print_a_linked_list_in_reverse_order_s1.java
    │   │   ├── sfo_06_print_a_linked_list_in_reverse_order_s2/
    │   │   │   └── sfo_06_print_a_linked_list_in_reverse_order_s2.java
    │   │   ├── sfo_07_reconstruct_binary_tree_s1/
    │   │   │   └── sfo_07_reconstruct_binary_tree_s1.java
    │   │   ├── sfo_09_implement_a_queue_using_two_stacks_s1/
    │   │   │   └── sfo_09_implement_a_queue_using_two_stacks_s1.java
    │   │   ├── sfo_10i_fibonacci_numbers_s1/
    │   │   │   └── sfo_10i_fibonacci_numbers_s1.java
    │   │   ├── sfo_10ii_frog_jump_s1/
    │   │   │   └── sfo_10ii_frog_jump_s1.java
    │   │   ├── sfo_11_find_minimum_in_rotated_sorted_array_s1/
    │   │   │   └── sfo_11_find_minimum_in_rotated_sorted_array_s1.java
    │   │   ├── sfo_11_find_minimum_in_rotated_sorted_array_s2/
    │   │   │   └── sfo_11_find_minimum_in_rotated_sorted_array_s2.java
    │   │   ├── sfo_12_word_search_s1/
    │   │   │   └── sfo_12_word_search_s1.java
    │   │   ├── sfo_13_range_of_motion_of_a_robot_s1/
    │   │   │   └── sfo_13_range_of_motion_of_a_robot_s1.java
    │   │   ├── sfo_13_range_of_motion_of_a_robot_s2/
    │   │   │   └── sfo_13_range_of_motion_of_a_robot_s2.java
    │   │   ├── sfo_14i_cut_the_rope_i_s1/
    │   │   │   └── sfo_14i_cut_the_rope_i_s1.java
    │   │   ├── sfo_14ii_cut_the_rope_ii_s1/
    │   │   │   └── sfo_14ii_cut_the_rope_ii_s1.java
    │   │   ├── sfo_15_number_of_1_bits_s1/
    │   │   │   └── sfo_15_number_of_1_bits_s1.java
    │   │   ├── sfo_15_number_of_1_bits_s2/
    │   │   │   └── sfo_15_number_of_1_bits_s2.java
    │   │   ├── sfo_16_powers_of_integers_s1/
    │   │   │   └── sfo_16_powers_of_integers_s1.java
    │   │   ├── sfo_17_print_from_1_to_the_largest_n_digits_s1/
    │   │   │   └── sfo_17_print_from_1_to_the_largest_n_digits_s1.java
    │   │   ├── sfo_17_print_from_1_to_the_largest_n_digits_s2/
    │   │   │   └── sfo_17_print_from_1_to_the_largest_n_digits_s2.java
    │   │   ├── sfo_17_print_from_1_to_the_largest_n_digits_s3/
    │   │   │   └── sfo_17_print_from_1_to_the_largest_n_digits_s3.java
    │   │   ├── sfo_17_print_from_1_to_the_largest_n_digits_s4/
    │   │   │   └── sfo_17_print_from_1_to_the_largest_n_digits_s4.java
    │   │   ├── sfo_18_delete_a_node_from_a_linked_list_s1/
    │   │   │   └── sfo_18_delete_a_node_from_a_linked_list_s1.java
    │   │   ├── sfo_19_regular_expression_matching_s1/
    │   │   │   └── sfo_19_regular_expression_matching_s1.java
    │   │   ├── sfo_19_regular_expression_matching_s2/
    │   │   │   └── sfo_19_regular_expression_matching_s2.java
    │   │   ├── sfo_20_a_string_representing_a_numeric_value_s1/
    │   │   │   └── sfo_20_a_string_representing_a_numeric_value_s1.java
    │   │   ├── sfo_21_adjust_the_order_of_numbers_in_an_array_s1/
    │   │   │   └── sfo_21_adjust_the_order_of_numbers_in_an_array_s1.java
    │   │   ├── 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.java
    │   │   ├── 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.java
    │   │   ├── sfo_24_reverse_a_linked_list_s1/
    │   │   │   └── sfo_24_reverse_a_linked_list_s1.java
    │   │   ├── sfo_24_reverse_a_linked_list_s2/
    │   │   │   └── sfo_24_reverse_a_linked_list_s2.java
    │   │   ├── sfo_25_combine_two_sorted_linked_lists_s1/
    │   │   │   └── sfo_25_combine_two_sorted_linked_lists_s1.java
    │   │   ├── sfo_26_substructure_of_a_binary_tree_s1/
    │   │   │   └── sfo_26_substructure_of_a_binary_tree_s1.java
    │   │   ├── sfo_27_mirror_of_a_binary_tree_s1/
    │   │   │   └── sfo_27_mirror_of_a_binary_tree_s1.java
    │   │   ├── sfo_27_mirror_of_a_binary_tree_s2/
    │   │   │   └── sfo_27_mirror_of_a_binary_tree_s2.java
    │   │   ├── sfo_28_symmetric_binary_tree_s1/
    │   │   │   └── sfo_28_symmetric_binary_tree_s1.java
    │   │   ├── sfo_29_print_a_given_matrix_in_spiral_form_s1/
    │   │   │   └── sfo_29_print_a_given_matrix_in_spiral_form_s1.java
    │   │   ├── sfo_30_min_stack_s1/
    │   │   │   └── sfo_30_min_stack_s1.java
    │   │   ├── sfo_31_validate_stack_sequences_s1/
    │   │   │   └── sfo_31_validate_stack_sequences_s1.java
    │   │   ├── sfo_32i_print_a_binary_tree_topbottom_i_s1/
    │   │   │   └── sfo_32i_print_a_binary_tree_topbottom_i_s1.java
    │   │   ├── sfo_32ii_print_a_binary_tree_topbottom_ii_s1/
    │   │   │   └── sfo_32ii_print_a_binary_tree_topbottom_ii_s1.java
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s1/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s1.java
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s2/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s2.java
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s3/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s3.java
    │   │   ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_33_postorder_traversal_of_a_binary_search_tree_s1.java
    │   │   ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s2/
    │   │   │   └── sfo_33_postorder_traversal_of_a_binary_search_tree_s2.java
    │   │   ├── sfo_34_all_xsum_paths_in_a_binary_tree_s1/
    │   │   │   └── sfo_34_all_xsum_paths_in_a_binary_tree_s1.java
    │   │   ├── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1/
    │   │   │   └── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1.java
    │   │   ├── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2/
    │   │   │   └── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2.java
    │   │   ├── sfo_36_binary_search_tree_and_doubly_linked_list_s1/
    │   │   │   └── sfo_36_binary_search_tree_and_doubly_linked_list_s1.java
    │   │   ├── sfo_37_serialize_and_deserialize_a_binary_tree_s1/
    │   │   │   └── sfo_37_serialize_and_deserialize_a_binary_tree_s1.java
    │   │   ├── sfo_38_all_permutations_of_a_string_s1/
    │   │   │   └── sfo_38_all_permutations_of_a_string_s1.java
    │   │   ├── sfo_39_the_majority_element_in_an_array_s1/
    │   │   │   └── sfo_39_the_majority_element_in_an_array_s1.java
    │   │   ├── sfo_39_the_majority_element_in_an_array_s2/
    │   │   │   └── sfo_39_the_majority_element_in_an_array_s2.java
    │   │   ├── sfo_40_the_smallest_k_numbers_s1/
    │   │   │   └── sfo_40_the_smallest_k_numbers_s1.java
    │   │   ├── sfo_40_the_smallest_k_numbers_s2/
    │   │   │   └── sfo_40_the_smallest_k_numbers_s2.java
    │   │   ├── sfo_41_find_median_from_data_stream_s1/
    │   │   │   └── sfo_41_find_median_from_data_stream_s1.java
    │   │   ├── sfo_42_largest_sum_contiguous_subarray_s1/
    │   │   │   └── sfo_42_largest_sum_contiguous_subarray_s1.java
    │   │   ├── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1/
    │   │   │   └── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1.java
    │   │   ├── sfo_44_nth_digit_s1/
    │   │   │   └── sfo_44_nth_digit_s1.java
    │   │   ├── sfo_45_arrange_an_array_into_the_smallest_number_s1/
    │   │   │   └── sfo_45_arrange_an_array_into_the_smallest_number_s1.java
    │   │   ├── sfo_45_arrange_an_array_into_the_smallest_number_s2/
    │   │   │   └── sfo_45_arrange_an_array_into_the_smallest_number_s2.java
    │   │   ├── sfo_46_translate_numbers_into_strings_s1/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s1.java
    │   │   ├── sfo_46_translate_numbers_into_strings_s2/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s2.java
    │   │   ├── sfo_46_translate_numbers_into_strings_s3/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s3.java
    │   │   ├── sfo_47_the_maximum_value_of_gifts_s1/
    │   │   │   └── sfo_47_the_maximum_value_of_gifts_s1.java
    │   │   ├── sfo_47_the_maximum_value_of_gifts_s2/
    │   │   │   └── sfo_47_the_maximum_value_of_gifts_s2.java
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s1/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s1.java
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s2/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s2.java
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s3/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s3.java
    │   │   ├── sfo_49_ugly_numbers_s1/
    │   │   │   └── sfo_49_ugly_numbers_s1.java
    │   │   ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1/
    │   │   │   └── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.java
    │   │   ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2/
    │   │   │   └── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.java
    │   │   ├── sfo_51_reversed_pairs_in_an_array_s1/
    │   │   │   └── sfo_51_reversed_pairs_in_an_array_s1.java
    │   │   ├── sfo_52_the_first_common_node_in_two_linked_lists_s1/
    │   │   │   └── sfo_52_the_first_common_node_in_two_linked_lists_s1.java
    │   │   ├── sfo_53i_find_a_number_in_a_sorted_array_s1/
    │   │   │   └── sfo_53i_find_a_number_in_a_sorted_array_s1.java
    │   │   ├── sfo_53i_find_a_number_in_a_sorted_array_s2/
    │   │   │   └── sfo_53i_find_a_number_in_a_sorted_array_s2.java
    │   │   ├── sfo_53ii_the_missing_number_from_0_to_n1_s1/
    │   │   │   └── sfo_53ii_the_missing_number_from_0_to_n1_s1.java
    │   │   ├── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.java
    │   │   ├── sfo_55i_depth_of_a_binary_tree_s1/
    │   │   │   └── sfo_55i_depth_of_a_binary_tree_s1.java
    │   │   ├── sfo_55i_depth_of_a_binary_tree_s2/
    │   │   │   └── sfo_55i_depth_of_a_binary_tree_s2.java
    │   │   ├── sfo_55ii_balanced_binary_tree_s1/
    │   │   │   └── sfo_55ii_balanced_binary_tree_s1.java
    │   │   ├── sfo_55ii_balanced_binary_tree_s2/
    │   │   │   └── sfo_55ii_balanced_binary_tree_s2.java
    │   │   ├── sfo_56i_single_number_i_s1/
    │   │   │   └── sfo_56i_single_number_i_s1.java
    │   │   ├── sfo_56ii_single_number_ii_s1/
    │   │   │   └── sfo_56ii_single_number_ii_s1.java
    │   │   ├── sfo_56ii_single_number_ii_s2/
    │   │   │   └── sfo_56ii_single_number_ii_s2.java
    │   │   ├── sfo_57_two_numbers_with_sum_s_s1/
    │   │   │   └── sfo_57_two_numbers_with_sum_s_s1.java
    │   │   ├── sfo_57ii_consecutive_numbers_with_sum_s_s1/
    │   │   │   └── sfo_57ii_consecutive_numbers_with_sum_s_s1.java
    │   │   ├── sfo_57ii_consecutive_numbers_with_sum_s_s2/
    │   │   │   └── sfo_57ii_consecutive_numbers_with_sum_s_s2.java
    │   │   ├── sfo_58i_reverse_order_of_words_s1/
    │   │   │   └── sfo_58i_reverse_order_of_words_s1.java
    │   │   ├── sfo_58i_reverse_order_of_words_s2/
    │   │   │   └── sfo_58i_reverse_order_of_words_s2.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s1/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s1.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s2/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s2.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s3/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s3.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s4/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s4.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s5/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s5.java
    │   │   ├── sfo_59i_sliding_window_maximum_s1/
    │   │   │   └── sfo_59i_sliding_window_maximum_s1.java
    │   │   ├── sfo_59i_sliding_window_maximum_s2/
    │   │   │   └── sfo_59i_sliding_window_maximum_s2.java
    │   │   ├── sfo_59ii_max_queue_s1/
    │   │   │   └── sfo_59ii_max_queue_s1.java
    │   │   ├── sfo_60_probabilities_for_rolling_n_dices_s1/
    │   │   │   └── sfo_60_probabilities_for_rolling_n_dices_s1.java
    │   │   ├── sfo_61_straight_in_poker_s1/
    │   │   │   └── sfo_61_straight_in_poker_s1.java
    │   │   ├── sfo_61_straight_in_poker_s2/
    │   │   │   └── sfo_61_straight_in_poker_s2.java
    │   │   ├── sfo_62_josephus_problem_s1/
    │   │   │   └── sfo_62_josephus_problem_s1.java
    │   │   ├── sfo_63_the_maximum_profit_of_stocks_s1/
    │   │   │   └── sfo_63_the_maximum_profit_of_stocks_s1.java
    │   │   ├── sfo_64_solve_1_2___n_s1/
    │   │   │   └── sfo_64_solve_1_2___n_s1.java
    │   │   ├── sfo_64_solve_1_2___n_s2/
    │   │   │   └── sfo_64_solve_1_2___n_s2.java
    │   │   ├── sfo_65_implement_addition_operation_without_arithmetic_operators_s1/
    │   │   │   └── sfo_65_implement_addition_operation_without_arithmetic_operators_s1.java
    │   │   ├── sfo_66_a_product_array_puzzle_s1/
    │   │   │   └── sfo_66_a_product_array_puzzle_s1.java
    │   │   ├── sfo_67_convert_string_to_int_s1/
    │   │   │   └── sfo_67_convert_string_to_int_s1.java
    │   │   ├── sfo_67_convert_string_to_int_s2/
    │   │   │   └── sfo_67_convert_string_to_int_s2.java
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.java
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.java
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.java
    │   │   ├── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1/
    │   │   │   └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1.java
    │   │   └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2/
    │   │       └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2.java
    │   └── python/
    │       ├── include/
    │       │   ├── __init__.py
    │       │   ├── binary_tree.py
    │       │   ├── linked_list.py
    │       │   └── print_util.py
    │       ├── sfo_03_find_duplicate_numbers_in_an_array_s1.py
    │       ├── sfo_03_find_duplicate_numbers_in_an_array_s2.py
    │       ├── sfo_04_find_a_number_in_2d_matrix_s1.py
    │       ├── sfo_05_replace_spaces_s1.py
    │       ├── sfo_06_print_a_linked_list_in_reverse_order_s1.py
    │       ├── sfo_06_print_a_linked_list_in_reverse_order_s2.py
    │       ├── sfo_07_reconstruct_binary_tree_s1.py
    │       ├── sfo_09_implement_a_queue_using_two_stacks_s1.py
    │       ├── sfo_10i_fibonacci_numbers_s1.py
    │       ├── sfo_10i_fibonacci_numbers_s2.py
    │       ├── sfo_10ii_frog_jump_s1.py
    │       ├── sfo_10ii_frog_jump_s2.py
    │       ├── sfo_11_find_minimum_in_rotated_sorted_array_s1.py
    │       ├── sfo_11_find_minimum_in_rotated_sorted_array_s2.py
    │       ├── sfo_12_word_search_s1.py
    │       ├── sfo_13_range_of_motion_of_a_robot_s1.py
    │       ├── sfo_13_range_of_motion_of_a_robot_s2.py
    │       ├── sfo_14i_cut_the_rope_i_s1.py
    │       ├── sfo_14ii_cut_the_rope_ii_s1.py
    │       ├── sfo_14ii_cut_the_rope_ii_s2.py
    │       ├── sfo_15_number_of_1_bits_s1.py
    │       ├── sfo_15_number_of_1_bits_s2.py
    │       ├── sfo_16_powers_of_integers_s1.py
    │       ├── sfo_17_print_from_1_to_the_largest_n_digits_s1.py
    │       ├── sfo_17_print_from_1_to_the_largest_n_digits_s2.py
    │       ├── sfo_17_print_from_1_to_the_largest_n_digits_s3.py
    │       ├── sfo_17_print_from_1_to_the_largest_n_digits_s4.py
    │       ├── sfo_18_delete_a_node_from_a_linked_list_s1.py
    │       ├── sfo_19_regular_expression_matching_s1.py
    │       ├── sfo_19_regular_expression_matching_s2.py
    │       ├── sfo_20_a_string_representing_a_numeric_value_s1.py
    │       ├── sfo_21_adjust_the_order_of_numbers_in_an_array_s1.py
    │       ├── sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1.py
    │       ├── sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2.py
    │       ├── sfo_24_reverse_a_linked_list_s1.py
    │       ├── sfo_24_reverse_a_linked_list_s2.py
    │       ├── sfo_24_reverse_a_linked_list_s3.py
    │       ├── sfo_25_combine_two_sorted_linked_lists_s1.py
    │       ├── sfo_26_substructure_of_a_binary_tree_s1.py
    │       ├── sfo_27_mirror_of_a_binary_tree_s1.py
    │       ├── sfo_27_mirror_of_a_binary_tree_s2.py
    │       ├── sfo_27_mirror_of_a_binary_tree_s3.py
    │       ├── sfo_28_symmetric_binary_tree_s1.py
    │       ├── sfo_29_print_a_given_matrix_in_spiral_form_s1.py
    │       ├── sfo_30_min_stack_s1.py
    │       ├── sfo_31_validate_stack_sequences_s1.py
    │       ├── sfo_32i_print_a_binary_tree_topbottom_i_s1.py
    │       ├── sfo_32ii_print_a_binary_tree_topbottom_ii_s1.py
    │       ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s1.py
    │       ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s2.py
    │       ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s3.py
    │       ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s1.py
    │       ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s2.py
    │       ├── sfo_34_all_xsum_paths_in_a_binary_tree_s1.py
    │       ├── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1.py
    │       ├── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2.py
    │       ├── sfo_36_binary_search_tree_and_doubly_linked_list_s1.py
    │       ├── sfo_37_serialize_and_deserialize_a_binary_tree_s1.py
    │       ├── sfo_38_all_permutations_of_a_string_s1.py
    │       ├── sfo_39_the_majority_element_in_an_array_s1.py
    │       ├── sfo_39_the_majority_element_in_an_array_s2.py
    │       ├── sfo_40_the_smallest_k_numbers_s1.py
    │       ├── sfo_40_the_smallest_k_numbers_s2.py
    │       ├── sfo_41_find_median_from_data_stream_s1.py
    │       ├── sfo_41_find_median_from_data_stream_s2.py
    │       ├── sfo_42_largest_sum_contiguous_subarray_s1.py
    │       ├── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1.py
    │       ├── sfo_44_nth_digit_s1.py
    │       ├── sfo_45_arrange_an_array_into_the_smallest_number_s1.py
    │       ├── sfo_45_arrange_an_array_into_the_smallest_number_s2.py
    │       ├── sfo_46_translate_numbers_into_strings_s1.py
    │       ├── sfo_46_translate_numbers_into_strings_s2.py
    │       ├── sfo_46_translate_numbers_into_strings_s3.py
    │       ├── sfo_46_translate_numbers_into_strings_s4.py
    │       ├── sfo_46_translate_numbers_into_strings_s5.py
    │       ├── sfo_47_the_maximum_value_of_gifts_s1.py
    │       ├── sfo_47_the_maximum_value_of_gifts_s2.py
    │       ├── sfo_48_the_longest_substring_without_repeated_characters_s1.py
    │       ├── sfo_48_the_longest_substring_without_repeated_characters_s2.py
    │       ├── sfo_48_the_longest_substring_without_repeated_characters_s3.py
    │       ├── sfo_49_ugly_numbers_s1.py
    │       ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.py
    │       ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.py
    │       ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s3.py
    │       ├── sfo_51_reversed_pairs_in_an_array_s1.py
    │       ├── sfo_52_the_first_common_node_in_two_linked_lists_s1.py
    │       ├── sfo_53i_find_a_number_in_a_sorted_array_s1.py
    │       ├── sfo_53i_find_a_number_in_a_sorted_array_s2.py
    │       ├── sfo_53ii_the_missing_number_from_0_to_n1_s1.py
    │       ├── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.py
    │       ├── sfo_55i_depth_of_a_binary_tree_s1.py
    │       ├── sfo_55i_depth_of_a_binary_tree_s2.py
    │       ├── sfo_55ii_balanced_binary_tree_s1.py
    │       ├── sfo_55ii_balanced_binary_tree_s2.py
    │       ├── sfo_56i_single_number_i_s1.py
    │       ├── sfo_56ii_single_number_ii_s1.py
    │       ├── sfo_56ii_single_number_ii_s2.py
    │       ├── sfo_57_two_numbers_with_sum_s_s1.py
    │       ├── sfo_57ii_consecutive_numbers_with_sum_s_s1.py
    │       ├── sfo_57ii_consecutive_numbers_with_sum_s_s2.py
    │       ├── sfo_58i_reverse_order_of_words_s1.py
    │       ├── sfo_58i_reverse_order_of_words_s2.py
    │       ├── sfo_58i_reverse_order_of_words_s3.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s1.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s2.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s3.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s4.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s5.py
    │       ├── sfo_59i_sliding_window_maximum_s1.py
    │       ├── sfo_59i_sliding_window_maximum_s2.py
    │       ├── sfo_59ii_max_queue_s1.py
    │       ├── sfo_60_probabilities_for_rolling_n_dices_s1.py
    │       ├── sfo_61_straight_in_poker_s1.py
    │       ├── sfo_61_straight_in_poker_s2.py
    │       ├── sfo_62_josephus_problem_s1.py
    │       ├── sfo_63_the_maximum_profit_of_stocks_s1.py
    │       ├── sfo_64_solve_1_2___n_s1.py
    │       ├── sfo_65_implement_addition_operation_without_arithmetic_operators_s1.py
    │       ├── sfo_66_a_product_array_puzzle_s1.py
    │       ├── sfo_67_convert_string_to_int_s1.py
    │       ├── sfo_67_convert_string_to_int_s2.py
    │       ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.py
    │       ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.py
    │       ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.py
    │       ├── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1.py
    │       └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2.py
    ├── docs/
    │   ├── 剑指 Offer 03. 数组中重复的数字.md
    │   ├── 剑指 Offer 04. 二维数组中的查找.md
    │   ├── 剑指 Offer 05. 替换空格.md
    │   ├── 剑指 Offer 06. 从尾到头打印链表.md
    │   ├── 剑指 Offer 07. 重建二叉树.md
    │   ├── 剑指 Offer 09. 用两个栈实现队列.md
    │   ├── 剑指 Offer 10- I. 斐波那契数列.md
    │   ├── 剑指 Offer 10- II. 青蛙跳台阶问题.md
    │   ├── 剑指 Offer 11. 旋转数组的最小数字.md
    │   ├── 剑指 Offer 12. 矩阵中的路径.md
    │   ├── 剑指 Offer 13. 机器人的运动范围.md
    │   ├── 剑指 Offer 14- I. 剪绳子.md
    │   ├── 剑指 Offer 14- II. 剪绳子 II.md
    │   ├── 剑指 Offer 15. 二进制中 1 的个数.md
    │   ├── 剑指 Offer 16. 数值的整数次方.md
    │   ├── 剑指 Offer 17. 打印从 1 到最大的 n 位数.md
    │   ├── 剑指 Offer 18. 删除链表的节点.md
    │   ├── 剑指 Offer 19. 正则表达式匹配.md
    │   ├── 剑指 Offer 20. 表示数值的字符串.md
    │   ├── 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面.md
    │   ├── 剑指 Offer 22. 链表中倒数第 k 个节点.md
    │   ├── 剑指 Offer 24. 反转链表.md
    │   ├── 剑指 Offer 25. 合并两个排序的链表.md
    │   ├── 剑指 Offer 26. 树的子结构.md
    │   ├── 剑指 Offer 27. 二叉树的镜像.md
    │   ├── 剑指 Offer 28. 对称的二叉树.md
    │   ├── 剑指 Offer 29. 顺时针打印矩阵.md
    │   ├── 剑指 Offer 30. 包含 min 函数的栈.md
    │   ├── 剑指 Offer 31. 栈的压入、弹出序列.md
    │   ├── 剑指 Offer 32 - I. 从上到下打印二叉树.md
    │   ├── 剑指 Offer 32 - II. 从上到下打印二叉树 II.md
    │   ├── 剑指 Offer 32 - III. 从上到下打印二叉树 III.md
    │   ├── 剑指 Offer 33. 二叉搜索树的后序遍历序列.md
    │   ├── 剑指 Offer 34. 二叉树中和为某一值的路径.md
    │   ├── 剑指 Offer 35. 复杂链表的复制.md
    │   ├── 剑指 Offer 36. 二叉搜索树与双向链表.md
    │   ├── 剑指 Offer 37. 序列化二叉树.md
    │   ├── 剑指 Offer 38. 字符串的排列.md
    │   ├── 剑指 Offer 39. 数组中出现次数超过一半的数字.md
    │   ├── 剑指 Offer 40. 最小的 k 个数.md
    │   ├── 剑指 Offer 41. 数据流中的中位数.md
    │   ├── 剑指 Offer 42. 连续子数组的最大和.md
    │   ├── 剑指 Offer 43. 1~n 整数中 1 出现的次数.md
    │   ├── 剑指 Offer 44. 数字序列中某一位的数字.md
    │   ├── 剑指 Offer 45. 把数组排成最小的数.md
    │   ├── 剑指 Offer 46. 把数字翻译成字符串.md
    │   ├── 剑指 Offer 47. 礼物的最大价值.md
    │   ├── 剑指 Offer 48. 最长不含重复字符的子字符串.md
    │   ├── 剑指 Offer 49. 丑数.md
    │   ├── 剑指 Offer 50. 第一个只出现一次的字符.md
    │   ├── 剑指 Offer 51. 数组中的逆序对.md
    │   ├── 剑指 Offer 52. 两个链表的第一个公共节点.md
    │   ├── 剑指 Offer 53 - I. 在排序数组中查找数字 I.md
    │   ├── 剑指 Offer 53 - II. 0~n-1 中缺失的数字.md
    │   ├── 剑指 Offer 54. 二叉搜索树的第 k 大节点.md
    │   ├── 剑指 Offer 55 - I. 二叉树的深度.md
    │   ├── 剑指 Offer 55 - II. 平衡二叉树.md
    │   ├── 剑指 Offer 56 - I. 数组中数字出现的次数.md
    │   ├── 剑指 Offer 56 - II. 数组中数字出现的次数 II.md
    │   ├── 剑指 Offer 57 - II. 和为 s 的连续正数序列.md
    │   ├── 剑指 Offer 57. 和为 s 的两个数字.md
    │   ├── 剑指 Offer 58 - I. 翻转单词顺序.md
    │   ├── 剑指 Offer 58 - II. 左旋转字符串.md
    │   ├── 剑指 Offer 59 - I. 滑动窗口的最大值.md
    │   ├── 剑指 Offer 59 - II. 队列的最大值.md
    │   ├── 剑指 Offer 60. n 个骰子的点数.md
    │   ├── 剑指 Offer 61. 扑克牌中的顺子.md
    │   ├── 剑指 Offer 62. 圆圈中最后剩下的数字.md
    │   ├── 剑指 Offer 63. 股票的最大利润.md
    │   ├── 剑指 Offer 64. 求 1 + 2 + … + n.md
    │   ├── 剑指 Offer 65. 不用加减乘除做加法.md
    │   ├── 剑指 Offer 66. 构建乘积数组.md
    │   ├── 剑指 Offer 67. 把字符串转换成整数.md
    │   ├── 剑指 Offer 68 - I. 二叉搜索树的最近公共祖先.md
    │   └── 剑指 Offer 68 - II. 二叉树的最近公共祖先.md
    ├── 剑指 Offer 刷题计划.md
    └── 剑指 Offer 题目分类.md

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
__pycache__
.DS_Store
.vscode
*.xlsx


================================================
FILE: LICENSE
================================================
Attribution-NonCommercial-ShareAlike 4.0 International

=======================================================================

Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.

Using Creative Commons Public Licenses

Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.

     Considerations for licensors: Our public licenses are
     intended for use by those authorized to give the public
     permission to use material in ways otherwise restricted by
     copyright and certain other rights. Our licenses are
     irrevocable. Licensors should read and understand the terms
     and conditions of the license they choose before applying it.
     Licensors should also secure all rights necessary before
     applying our licenses so that the public can reuse the
     material as expected. Licensors should clearly mark any
     material not subject to the license. This includes other CC-
     licensed material, or material used under an exception or
     limitation to copyright. More considerations for licensors:
    wiki.creativecommons.org/Considerations_for_licensors

     Considerations for the public: By using one of our public
     licenses, a licensor grants the public permission to use the
     licensed material under specified terms and conditions. If
     the licensor's permission is not necessary for any reason--for
     example, because of any applicable exception or limitation to
     copyright--then that use is not regulated by the license. Our
     licenses grant only permissions under copyright and certain
     other rights that a licensor has authority to grant. Use of
     the licensed material may still be restricted for other
     reasons, including because others have copyright or other
     rights in the material. A licensor may make special requests,
     such as asking that all changes be marked or described.
     Although not required by our licenses, you are encouraged to
     respect those requests where reasonable. More considerations
     for the public:
    wiki.creativecommons.org/Considerations_for_licensees

=======================================================================

Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
Public License

By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 International Public License
("Public License"). To the extent this Public License may be
interpreted as a contract, You are granted the Licensed Rights in
consideration of Your acceptance of these terms and conditions, and the
Licensor grants You such rights in consideration of benefits the
Licensor receives from making the Licensed Material available under
these terms and conditions.


Section 1 -- Definitions.

  a. Adapted Material means material subject to Copyright and Similar
     Rights that is derived from or based upon the Licensed Material
     and in which the Licensed Material is translated, altered,
     arranged, transformed, or otherwise modified in a manner requiring
     permission under the Copyright and Similar Rights held by the
     Licensor. For purposes of this Public License, where the Licensed
     Material is a musical work, performance, or sound recording,
     Adapted Material is always produced where the Licensed Material is
     synched in timed relation with a moving image.

  b. Adapter's License means the license You apply to Your Copyright
     and Similar Rights in Your contributions to Adapted Material in
     accordance with the terms and conditions of this Public License.

  c. BY-NC-SA Compatible License means a license listed at
     creativecommons.org/compatiblelicenses, approved by Creative
     Commons as essentially the equivalent of this Public License.

  d. Copyright and Similar Rights means copyright and/or similar rights
     closely related to copyright including, without limitation,
     performance, broadcast, sound recording, and Sui Generis Database
     Rights, without regard to how the rights are labeled or
     categorized. For purposes of this Public License, the rights
     specified in Section 2(b)(1)-(2) are not Copyright and Similar
     Rights.

  e. Effective Technological Measures means those measures that, in the
     absence of proper authority, may not be circumvented under laws
     fulfilling obligations under Article 11 of the WIPO Copyright
     Treaty adopted on December 20, 1996, and/or similar international
     agreements.

  f. Exceptions and Limitations means fair use, fair dealing, and/or
     any other exception or limitation to Copyright and Similar Rights
     that applies to Your use of the Licensed Material.

  g. License Elements means the license attributes listed in the name
     of a Creative Commons Public License. The License Elements of this
     Public License are Attribution, NonCommercial, and ShareAlike.

  h. Licensed Material means the artistic or literary work, database,
     or other material to which the Licensor applied this Public
     License.

  i. Licensed Rights means the rights granted to You subject to the
     terms and conditions of this Public License, which are limited to
     all Copyright and Similar Rights that apply to Your use of the
     Licensed Material and that the Licensor has authority to license.

  j. Licensor means the individual(s) or entity(ies) granting rights
     under this Public License.

  k. NonCommercial means not primarily intended for or directed towards
     commercial advantage or monetary compensation. For purposes of
     this Public License, the exchange of the Licensed Material for
     other material subject to Copyright and Similar Rights by digital
     file-sharing or similar means is NonCommercial provided there is
     no payment of monetary compensation in connection with the
     exchange.

  l. Share means to provide material to the public by any means or
     process that requires permission under the Licensed Rights, such
     as reproduction, public display, public performance, distribution,
     dissemination, communication, or importation, and to make material
     available to the public including in ways that members of the
     public may access the material from a place and at a time
     individually chosen by them.

  m. Sui Generis Database Rights means rights other than copyright
     resulting from Directive 96/9/EC of the European Parliament and of
     the Council of 11 March 1996 on the legal protection of databases,
     as amended and/or succeeded, as well as other essentially
     equivalent rights anywhere in the world.

  n. You means the individual or entity exercising the Licensed Rights
     under this Public License. Your has a corresponding meaning.


Section 2 -- Scope.

  a. License grant.

       1. Subject to the terms and conditions of this Public License,
          the Licensor hereby grants You a worldwide, royalty-free,
          non-sublicensable, non-exclusive, irrevocable license to
          exercise the Licensed Rights in the Licensed Material to:

            a. reproduce and Share the Licensed Material, in whole or
               in part, for NonCommercial purposes only; and

            b. produce, reproduce, and Share Adapted Material for
               NonCommercial purposes only.

       2. Exceptions and Limitations. For the avoidance of doubt, where
          Exceptions and Limitations apply to Your use, this Public
          License does not apply, and You do not need to comply with
          its terms and conditions.

       3. Term. The term of this Public License is specified in Section
          6(a).

       4. Media and formats; technical modifications allowed. The
          Licensor authorizes You to exercise the Licensed Rights in
          all media and formats whether now known or hereafter created,
          and to make technical modifications necessary to do so. The
          Licensor waives and/or agrees not to assert any right or
          authority to forbid You from making technical modifications
          necessary to exercise the Licensed Rights, including
          technical modifications necessary to circumvent Effective
          Technological Measures. For purposes of this Public License,
          simply making modifications authorized by this Section 2(a)
          (4) never produces Adapted Material.

       5. Downstream recipients.

            a. Offer from the Licensor -- Licensed Material. Every
               recipient of the Licensed Material automatically
               receives an offer from the Licensor to exercise the
               Licensed Rights under the terms and conditions of this
               Public License.

            b. Additional offer from the Licensor -- Adapted Material.
               Every recipient of Adapted Material from You
               automatically receives an offer from the Licensor to
               exercise the Licensed Rights in the Adapted Material
               under the conditions of the Adapter's License You apply.

            c. No downstream restrictions. You may not offer or impose
               any additional or different terms or conditions on, or
               apply any Effective Technological Measures to, the
               Licensed Material if doing so restricts exercise of the
               Licensed Rights by any recipient of the Licensed
               Material.

       6. No endorsement. Nothing in this Public License constitutes or
          may be construed as permission to assert or imply that You
          are, or that Your use of the Licensed Material is, connected
          with, or sponsored, endorsed, or granted official status by,
          the Licensor or others designated to receive attribution as
          provided in Section 3(a)(1)(A)(i).

  b. Other rights.

       1. Moral rights, such as the right of integrity, are not
          licensed under this Public License, nor are publicity,
          privacy, and/or other similar personality rights; however, to
          the extent possible, the Licensor waives and/or agrees not to
          assert any such rights held by the Licensor to the limited
          extent necessary to allow You to exercise the Licensed
          Rights, but not otherwise.

       2. Patent and trademark rights are not licensed under this
          Public License.

       3. To the extent possible, the Licensor waives any right to
          collect royalties from You for the exercise of the Licensed
          Rights, whether directly or through a collecting society
          under any voluntary or waivable statutory or compulsory
          licensing scheme. In all other cases the Licensor expressly
          reserves any right to collect such royalties, including when
          the Licensed Material is used other than for NonCommercial
          purposes.


Section 3 -- License Conditions.

Your exercise of the Licensed Rights is expressly made subject to the
following conditions.

  a. Attribution.

       1. If You Share the Licensed Material (including in modified
          form), You must:

            a. retain the following if it is supplied by the Licensor
               with the Licensed Material:

                 i. identification of the creator(s) of the Licensed
                    Material and any others designated to receive
                    attribution, in any reasonable manner requested by
                    the Licensor (including by pseudonym if
                    designated);

                ii. a copyright notice;

               iii. a notice that refers to this Public License;

                iv. a notice that refers to the disclaimer of
                    warranties;

                 v. a URI or hyperlink to the Licensed Material to the
                    extent reasonably practicable;

            b. indicate if You modified the Licensed Material and
               retain an indication of any previous modifications; and

            c. indicate the Licensed Material is licensed under this
               Public License, and include the text of, or the URI or
               hyperlink to, this Public License.

       2. You may satisfy the conditions in Section 3(a)(1) in any
          reasonable manner based on the medium, means, and context in
          which You Share the Licensed Material. For example, it may be
          reasonable to satisfy the conditions by providing a URI or
          hyperlink to a resource that includes the required
          information.
       3. If requested by the Licensor, You must remove any of the
          information required by Section 3(a)(1)(A) to the extent
          reasonably practicable.

  b. ShareAlike.

     In addition to the conditions in Section 3(a), if You Share
     Adapted Material You produce, the following conditions also apply.

       1. The Adapter's License You apply must be a Creative Commons
          license with the same License Elements, this version or
          later, or a BY-NC-SA Compatible License.

       2. You must include the text of, or the URI or hyperlink to, the
          Adapter's License You apply. You may satisfy this condition
          in any reasonable manner based on the medium, means, and
          context in which You Share Adapted Material.

       3. You may not offer or impose any additional or different terms
          or conditions on, or apply any Effective Technological
          Measures to, Adapted Material that restrict exercise of the
          rights granted under the Adapter's License You apply.


Section 4 -- Sui Generis Database Rights.

Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:

  a. for the avoidance of doubt, Section 2(a)(1) grants You the right
     to extract, reuse, reproduce, and Share all or a substantial
     portion of the contents of the database for NonCommercial purposes
     only;

  b. if You include all or a substantial portion of the database
     contents in a database in which You have Sui Generis Database
     Rights, then the database in which You have Sui Generis Database
     Rights (but not its individual contents) is Adapted Material,
     including for purposes of Section 3(b); and

  c. You must comply with the conditions in Section 3(a) if You Share
     all or a substantial portion of the contents of the database.

For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.


Section 5 -- Disclaimer of Warranties and Limitation of Liability.

  a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
     EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
     AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
     ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
     IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
     WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
     PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
     ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
     KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
     ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.

  b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
     TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
     NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
     INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
     COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
     USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
     ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
     DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
     IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.

  c. The disclaimer of warranties and limitation of liability provided
     above shall be interpreted in a manner that, to the extent
     possible, most closely approximates an absolute disclaimer and
     waiver of all liability.


Section 6 -- Term and Termination.

  a. This Public License applies for the term of the Copyright and
     Similar Rights licensed here. However, if You fail to comply with
     this Public License, then Your rights under this Public License
     terminate automatically.

  b. Where Your right to use the Licensed Material has terminated under
     Section 6(a), it reinstates:

       1. automatically as of the date the violation is cured, provided
          it is cured within 30 days of Your discovery of the
          violation; or

       2. upon express reinstatement by the Licensor.

     For the avoidance of doubt, this Section 6(b) does not affect any
     right the Licensor may have to seek remedies for Your violations
     of this Public License.

  c. For the avoidance of doubt, the Licensor may also offer the
     Licensed Material under separate terms or conditions or stop
     distributing the Licensed Material at any time; however, doing so
     will not terminate this Public License.

  d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
     License.


Section 7 -- Other Terms and Conditions.

  a. The Licensor shall not be bound by any additional or different
     terms or conditions communicated by You unless expressly agreed.

  b. Any arrangements, understandings, or agreements regarding the
     Licensed Material not stated herein are separate from and
     independent of the terms and conditions of this Public License.


Section 8 -- Interpretation.

  a. For the avoidance of doubt, this Public License does not, and
     shall not be interpreted to, reduce, limit, restrict, or impose
     conditions on any use of the Licensed Material that could lawfully
     be made without permission under this Public License.

  b. To the extent possible, if any provision of this Public License is
     deemed unenforceable, it shall be automatically reformed to the
     minimum extent necessary to make it enforceable. If the provision
     cannot be reformed, it shall be severed from this Public License
     without affecting the enforceability of the remaining terms and
     conditions.

  c. No term or condition of this Public License will be waived and no
     failure to comply consented to unless expressly agreed to by the
     Licensor.

  d. Nothing in this Public License constitutes or may be interpreted
     as a limitation upon, or waiver of, any privileges and immunities
     that apply to the Licensor or You, including from the legal
     processes of any jurisdiction or authority.

=======================================================================

Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.

Creative Commons may be contacted at creativecommons.org.


================================================
FILE: README.md
================================================
<p align="center">
  <a href="https://leetcode-cn.com/leetbook/detail/illustration-of-algorithm/">
    <img src="https://pic.leetcode-cn.com/1599187248-gDiWnC-image.png" width="490">
  </a>
</p>

<p align="center">
  <img src="https://img.shields.io/badge/LeetCode%20tests-75%20accepted-brightgreen">
  <img src="https://img.shields.io/badge/Language-Python-teal">
  <img src="https://img.shields.io/badge/Language-Java-orange">
  <img src="https://img.shields.io/badge/Language-C++-blue">
</p>

[《图解算法数据结构》](https://leetcode-cn.com/leetbook/detail/illustration-of-algorithm/)是一本面向算法初学者和互联网求职者编写的 LeetBook 手册。

- 图文详解 75 道题目,覆盖主要算法知识点。
- 题目活跃于各大互联网公司招聘中,可使笔面试准备事半功倍。
- 致力于行文深入浅出、图文搭配,提供简洁的 Python, Java, C++ 解题代码。

> [!NOTE]  
>
> 本仓库包含:
> 
> ```python
> LeetCode-Book
> ├── sword_for_offer            # 《剑指 Offer》题目解析、配套代码、刷题计划
> ├── selected_coding_interview  # 《Krahets 笔面试精选 88 题》题目解析、配套代码
> └── leetbook_ioa               # 《图解算法数据结构》题目解析
> ```

> 若本仓库对您有所帮助,请在页面右上角点个 **Star** :star: 支持一下,谢谢!

## 如何学习算法

### 第一步:看入门书

<p align="center" href="https://github.com/krahets/hello-algo">
  <img src="https://www.hello-algo.com/index.assets/hello_algo_header.png" width="550">
</p>

<p align="center">
  <a href="https://github.com/krahets/hello-algo">《Hello 算法》</a> —— 动画图解、一键运行的数据结构与算法教程
</p>

此书旨在引导初学者探索数据结构与算法的知识地图,掌握刷题需要的前置知识与工具库。

> [!TIP]
> 建议先读完这本书(概括且全面地了解数据结构与算法),再开始刷题(深入探索各类算法和数据结构)。

### 第二步:刷算法题

推荐以下 LeetCode 题单:

1. [Krahets 笔面试精选 88 题](https://leetcode.cn/studyplan/selected-coding-interview/):从“剑指 Offer”和“热题 100”精选出的 88 道高频算法笔试题,适合初学者入门。
2. [LeetCode 热题 100](https://leetcode.cn/studyplan/top-100-liked/):力扣用户最喜爱的 100 道题。
3. [面试经典 150 题](https://leetcode.cn/studyplan/top-interview-150/):150 道经典面试力扣题。
4. [LeetCode-75](https://leetcode.cn/studyplan/leetcode-75/):精选 75 道面试核心题目。

对初学者刷题的一些建议:

1. 建议每日刷 2~3 题。若能轻松完成,可以尝试增加至 5~8 题。
2. 刷题的质量比数量更加重要。请确保你真正理解了每个题目的解法及背后的算法原理。
3. 建议你按照题单目录的顺序做题。如果感觉一道题很难,可以先跳过,后续再攻克。
4. 题目通常有不止一种解法,请你注意比较和探讨各种方法的特点和适用情况。
5. 如果你发现自己遗忘了题目解法,不必灰心;我们通常需要复习三次以上,才能真正掌握一个知识点。
6. 行百里者半九十。坚持至关重要,加油!

## License

The texts, code, and images in this repository are licensed under [CC BY-NC-SA-4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/).


================================================
FILE: leetbook_ioa/docs/# 0 引言.md
================================================
# 引言

《图解算法数据结构》面向算法初学者、互联网求职者设计,主要内容包括:

### 精选面试题图文解析

- 图文详解 75 道题目,覆盖主要算法知识点,非常适合作为算法学习的 **第一份题库**。
- 题库活跃于各大互联网公司招聘中,可使笔面试准备事半功倍。
- 致力于行文深入浅出、图文搭配,提供简洁的 **Python, Java, C++** 解题代码。
- 笔者整理了 **题目分类** 和 **刷题计划** ,让刷题有迹可循。

### 数据结构与算法专栏

- **基础知识:** 时间复杂度、空间复杂度等算法知识。
- **数据结构:** 数组、链表、字符串、栈、队列、哈希表、树、图、堆。
- **算法专题:** 搜索与回溯、分治、动态规划、贪心、排序、位运算、模拟、数学。

## 配套代码

为方便各位 Debug 算法题目,笔者整理了本 LeetBook 的配套代码,包括:

- 「题解代码」提供 Python, Java, C++ 语言。
- 「测试样例」与运行调用代码。
- 「数据结构」封装,提升 LeetCode 刷题效率。

与本 LeetBook 配合食用更佳,仓库链接:https://github.com/krahets/LeetCode-Book


================================================
FILE: leetbook_ioa/docs/# 0.1 刷题建议.md
================================================
# 刷题建议

本书专为算法初学者设计,特别针对有意进入互联网行业的求职者。内容覆盖如下主题:

- **算法**:搜索、查找、排序、双指针、回溯、分治、动态规划、贪心、位运算、数学等。
- **数据结构**:数组、栈、队列、字符串、链表、树、图、堆、哈希表等。

所有题目已经进行分类,并按照难易程度排序。对于初学者,这里提供几条刷题建议:

1. 建议每日刷 2~3 题。若能轻松完成,可以尝试增加至 5~8 题,但请记住:刷题的质量远重要于数量。务必确保你真正理解了每个题目的解法及背后的算法原理。
2. 建议你按照目录顺序逐题解答。如果碰到某些难以解决的题目,可以先跳过,稍后回顾时再挑战。
3. 很多题目都有不止一种解法,请你注意比较和探讨各种方法的特点和适用情况。
4. 如果你发现自己忘记了某个题目的解法,不必灰心。艾宾浩斯遗忘曲线指出,为了真正掌握一个知识点,通常需要复习至少3次。
5. 行百里者半九十。坚持至关重要,加油,相信你可以做到!


================================================
FILE: leetbook_ioa/docs/# 0.2 题目分类.md
================================================
# 题目分类

题目可能存在多种解法,下表仅列举最优解法(时间与空间复杂度最低)的算法和数据结构分类。

| 题目                             | 算法分类         | 数据结构分类   |
| -------------------------------- | ---------------- | -------------- |
| 寻找文件副本                     | 查找             | 数组           |
| 寻找目标值 - 二维数组            | 查找             | 数组           |
| 路径加密                         |                  | 字符串         |
| 图书整理 I                       |                  | 栈与队列,链表 |
| 推理二叉树                       | 分治             | 树,哈希表     |
| 图书整理 II                      |                  | 栈与队列       |
| 斐波那契数                       | 动态规划         | 数组           |
| 跳跃训练                         | 动态规划         | 数组           |
| 库存管理 I                       | 查找             | 数组           |
| 字母迷宫                         | 回溯,搜索       | 数组,图       |
| 衣橱整理                         | 回溯,搜索       | 数组,图       |
| 砍竹子 I                         | 贪心,数学       |                |
| 砍竹子 II                        | 贪心,分治,数学 |                |
| 位 1 的个数                      | 位运算           |                |
| Pow(x, n)                        | 分治,位运算     |                |
| 报数                             |                  | 数组           |
| 删除链表节点                     | 双指针           | 链表           |
| 模糊搜索验证                     | 动态规划         | 字符串         |
| 有效数字                         |                  | 字符串         |
| 训练计划 I                       | 双指针           | 数组           |
| 训练计划 II                      | 双指针           | 链表           |
| 训练计划 III                     | 双指针           | 链表           |
| 训练计划 IV                      | 双指针           | 链表           |
| 子结构判断                       | 搜索             | 树             |
| 翻转二叉树                       | 搜索             | 栈与队列,树   |
| 判断对称二叉树                   | 搜索             | 树             |
| 螺旋遍历二维数组                 | 模拟             | 数组           |
| 最小栈                           | 排序             | 栈与队列       |
| 验证图书取出顺序                 | 模拟             | 栈与队列       |
| 彩灯装饰记录 I                   | 搜索             | 栈与队列,树   |
| 彩灯装饰记录 II                  | 搜索             | 栈与队列,树   |
| 彩灯装饰记录 III                 | 搜索             | 栈与队列,树   |
| 验证二叉搜索树的后序遍历序列     | 分治             | 栈与队列,树   |
| 二叉树中和为目标值的路径         | 回溯,搜索       | 树             |
| 随机链表的复制                   |                  | 链表           |
| 将二叉搜索树转化为排序的双向链表 | 搜索,双指针     | 树             |
| 序列化与反序列化二叉树           | 搜索             | 树             |
| 套餐内商品的排列顺序             | 回溯             | 字符串,哈希表 |
| 库存管理 II                      |                  | 数组           |
| 库存管理 III                     | 排序             | 数组,堆       |
| 数据流中的中位数                 | 排序             | 堆             |
| 连续天数的最高销售额             | 动态规划         | 数组           |
| 数字 1 的个数                    | 数学             |                |
| 找到第 k 位数字                  | 数学             |                |
| 破解闯关密码                     | 排序             | 字符串         |
| 解密数字                         | 动态规划         | 字符串         |
| 珠宝的最高价值                   | 动态规划         | 数组           |
| 招式拆解 I                       | 动态规划,双指针 | 哈希表         |
| 丑数                             | 动态规划         |                |
| 招式拆解 II                      |                  | 哈希表         |
| 交易逆序对的总数                 | 分治             | 数组           |
| 训练计划 V                       | 双指针           | 链表           |
| 统计目标成绩的出现次数           | 查找             | 数组           |
| 点名                             | 查找             | 数组           |
| 寻找二叉搜索树中的目标节点       | 搜索             | 树             |
| 计算二叉树的深度                 | 搜索             | 树             |
| 判断是否为平衡二叉树             | 搜索             | 树             |
| 撞色搭配                         | 位运算           | 数组           |
| 训练计划 VI                      | 位运算           | 数组           |
| 查找总价格为目标值的两个商品     | 双指针           | 数组           |
| 文件组合                         | 双指针           | 数组           |
| 字符串中的单词反转               | 双指针           | 字符串         |
| 动态口令                         |                  | 字符串         |
| 望远镜中最高的海拔               | 排序             | 数组,栈与队列 |
| 设计自助结算系统                 | 排序             | 数组,栈与队列 |
| 统计结果概率                     | 动态规划         |                |
| 文物朝代判断                     | 排序             | 数组,哈希表   |
| 破冰游戏                         | 数学             |                |
| 买卖芯片的最佳时机               | 动态规划         | 数组           |
| 设计机械累加器                   |                  |                |
| 加密运算                         | 位运算           |                |
| 按规则计算统计结果               | 数学             | 数组           |
| 不使用库函数的字符串转整数       |                  | 字符串         |
| 求二叉搜索树的最近公共祖先       | 搜索             | 树             |
| 寻找二叉树的最近公共祖先         | 搜索             | 树             |


================================================
FILE: leetbook_ioa/docs/# 1.1 数据结构简介.md
================================================
# 数据结构简介

数据结构是为实现对计算机数据有效使用的各种数据组织形式,服务于各类计算机操作。不同的数据结构具有各自对应的适用场景,旨在降低各种算法计算的时间与空间复杂度,达到最佳的任务执行效率。

如下图所示,常见的数据结构可分为「线性数据结构」与「非线性数据结构」,具体为:「数组」、「链表」、「栈」、「队列」、「树」、「图」、「散列表」、「堆」。

![Picture1.png](https://pic.leetcode-cn.com/1599638810-SZDwfK-Picture1.png){:width=500}

从零开始学习算法的同学对数据结构的使用方法可能尚不熟悉,本节将初步介绍各数据结构的基本特点,与 Python3 , Java , C++ 语言中各数据结构的初始化与构建方法。

> 代码运行可使用本地 IDE 或 [力扣 PlayGround](https://leetcode-cn.com/playground/) 。

---

## 数组

数组是将相同类型的元素存储于连续内存空间的数据结构,其长度不可变。

如下图所示,构建此数组需要在初始化时给定长度,并对数组每个索引元素赋值,代码如下:

```Java []
// 初始化一个长度为 5 的数组 array
int[] array = new int[5];
// 元素赋值
array[0] = 2;
array[1] = 3;
array[2] = 1;
array[3] = 0;
array[4] = 2;
```

```C++ []
// 初始化一个长度为 5 的数组 array
int array[5];
// 元素赋值
array[0] = 2;
array[1] = 3;
array[2] = 1;
array[3] = 0;
array[4] = 2;
```

或者可以使用直接赋值的初始化方式,代码如下:

```Java []
int[] array = {2, 3, 1, 0, 2};
```

```C++ []
int array[] = {2, 3, 1, 0, 2};
```

![Picture2.png](https://pic.leetcode-cn.com/1599587176-JAxwpf-Picture2.png){:width=500}

「可变数组」是经常使用的数据结构,其基于数组和扩容机制实现,相比普通数组更加灵活。常用操作有:访问元素、添加元素、删除元素。

```Java []
// 初始化可变数组
List<Integer> array = new ArrayList<>();

// 向尾部添加元素
array.add(2);
array.add(3);
array.add(1);
array.add(0);
array.add(2);
```

```Python []
# 初始化可变数组
array = []

# 向尾部添加元素
array.append(2)
array.append(3)
array.append(1)
array.append(0)
array.append(2)
```

```C++ []
// 初始化可变数组
vector<int> array;

// 向尾部添加元素
array.push_back(2);
array.push_back(3);
array.push_back(1);
array.push_back(0);
array.push_back(2);
```

---

## 链表

链表以节点为单位,每个元素都是一个独立对象,在内存空间的存储是非连续的。链表的节点对象具有两个成员变量:「值 `val`」,「后继节点引用 `next`」 。

```Java []
class ListNode {
    int val;       // 节点值
    ListNode next; // 后继节点引用
    ListNode(int x) { val = x; }
}
```

```Python []
class ListNode:
    def __init__(self, x):
        self.val = x     # 节点值
        self.next = None # 后继节点引用
```

```C++ []
struct ListNode {
    int val;        // 节点值
    ListNode *next; // 后继节点引用
    ListNode(int x) : val(x), next(NULL) {}
};
```

如下图所示,建立此链表需要实例化每个节点,并构建各节点的引用指向。

```Java []
// 实例化节点
ListNode n1 = new ListNode(4); // 节点 head
ListNode n2 = new ListNode(5);
ListNode n3 = new ListNode(1);

// 构建引用指向
n1.next = n2;
n2.next = n3;
```

```Python []
# 实例化节点
n1 = ListNode(4) # 节点 head
n2 = ListNode(5)
n3 = ListNode(1)

# 构建引用指向
n1.next = n2
n2.next = n3
```

```C++ []
// 实例化节点
ListNode *n1 = new ListNode(4); // 节点 head
ListNode *n2 = new ListNode(5);
ListNode *n3 = new ListNode(1);

// 构建引用指向
n1->next = n2;
n2->next = n3;
```

![Picture3.png](https://pic.leetcode-cn.com/1599578767-zgLjYw-Picture3.png){:width=500}

---

## 栈

栈是一种具有 「先入后出」 特点的抽象数据结构,可使用数组或链表实现。

```Java []
Stack<Integer> stack = new Stack<>();
```

```Python []
stack = [] # Python 可将列表作为栈使用
```

```C++ []
stack<int> stk;
```

如下图所示,通过常用操作「入栈 `push()`」,「出栈 `pop()`」,展示了栈的先入后出特性。

```Java []
stack.push(1); // 元素 1 入栈
stack.push(2); // 元素 2 入栈
stack.pop();   // 出栈 -> 元素 2
stack.pop();   // 出栈 -> 元素 1
```

```Python []
stack.append(1) # 元素 1 入栈
stack.append(2) # 元素 2 入栈
stack.pop()     # 出栈 -> 元素 2
stack.pop()     # 出栈 -> 元素 1
```

```C++ []
stk.push(1); // 元素 1 入栈
stk.push(2); // 元素 2 入栈
stk.pop();   // 出栈 -> 元素 2
stk.pop();   // 出栈 -> 元素 1
```

![Picture4.png](https://pic.leetcode-cn.com/1599578767-ZifMEX-Picture4.png){:width=500}

> 注意:通常情况下,不推荐使用 Java 的 `Vector` 以及其子类 `Stack` ,而一般将 `LinkedList` 作为栈来使用。详细说明请见:[Stack,ArrayDeque,LinkedList 的区别](https://blog.csdn.net/cartoon_/article/details/87992743) 。

```Java []
LinkedList<Integer> stack = new LinkedList<>();

stack.addLast(1);   // 元素 1 入栈
stack.addLast(2);   // 元素 2 入栈
stack.removeLast(); // 出栈 -> 元素 2
stack.removeLast(); // 出栈 -> 元素 1
```

---

## 队列

队列是一种具有 「先入先出」 特点的抽象数据结构,可使用链表实现。

```Java []
Queue<Integer> queue = new LinkedList<>();
```

```Python []
# Python 通常使用双端队列 collections.deque
from collections import deque

queue = deque()
```

```C++ []
queue<int> que;
```

如下图所示,通过常用操作「入队 `push()`」,「出队 `pop()`」,展示了队列的先入先出特性。

```Java []
queue.offer(1); // 元素 1 入队
queue.offer(2); // 元素 2 入队
queue.poll();   // 出队 -> 元素 1
queue.poll();   // 出队 -> 元素 2
```

```Python []
queue.append(1) # 元素 1 入队
queue.append(2) # 元素 2 入队
queue.popleft() # 出队 -> 元素 1
queue.popleft() # 出队 -> 元素 2
```

```C++ []
que.push(1); // 元素 1 入队
que.push(2); // 元素 2 入队
que.pop();   // 出队 -> 元素 1
que.pop();   // 出队 -> 元素 2
```

![Picture5.png](https://pic.leetcode-cn.com/1599588416-Majmwh-Picture5.png){:width=500}

---

## 树

树是一种非线性数据结构,根据子节点数量可分为 「二叉树」 和 「多叉树」,最顶层的节点称为「根节点 `root`」。以二叉树为例,每个节点包含三个成员变量:「值  `val`」、「左子节点  `left`」、「右子节点  `right`」 。

```Java []
class TreeNode {
    int val;        // 节点值
    TreeNode left;  // 左子节点
    TreeNode right; // 右子节点
    TreeNode(int x) { val = x; }
}
```

```Python []
class TreeNode:
    def __init__(self, x):
        self.val = x      # 节点值
        self.left = None  # 左子节点
        self.right = None # 右子节点
```

```C++ []
struct TreeNode {
    int val;         // 节点值
    TreeNode *left;  // 左子节点
    TreeNode *right; // 右子节点
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
```

如下图所示,建立此二叉树需要实例化每个节点,并构建各节点的引用指向。

```Java []
// 初始化节点
TreeNode n1 = new TreeNode(3); // 根节点 root
TreeNode n2 = new TreeNode(4);
TreeNode n3 = new TreeNode(5);
TreeNode n4 = new TreeNode(1);
TreeNode n5 = new TreeNode(2);

// 构建引用指向
n1.left = n2;
n1.right = n3;
n2.left = n4;
n2.right = n5;
```

```Python []
# 初始化节点
n1 = TreeNode(3) # 根节点 root
n2 = TreeNode(4)
n3 = TreeNode(5)
n4 = TreeNode(1)
n5 = TreeNode(2)

# 构建引用指向
n1.left = n2
n1.right = n3
n2.left = n4
n2.right = n5
```

```C++ []
// 初始化节点
TreeNode *n1 = new TreeNode(3); // 根节点 root
TreeNode *n2 = new TreeNode(4);
TreeNode *n3 = new TreeNode(5);
TreeNode *n4 = new TreeNode(1);
TreeNode *n5 = new TreeNode(2);

// 构建引用指向
n1->left = n2;
n1->right = n3;
n2->left = n4;
n2->right = n5;
```

![Picture6.png](https://pic.leetcode-cn.com/1599579136-bBARpC-Picture6.png){:width=500}

---

## 图

图是一种非线性数据结构,由「节点(顶点)`vertex`」和「边  `edge`」组成,每条边连接一对顶点。根据边的方向有无,图可分为「有向图」和「无向图」。本文 **以无向图为例** 开展介绍。

如下图所示,此无向图的 **顶点** 和 **边** 集合分别为:

- 顶点集合: `vertices = {1, 2, 3, 4, 5}`
- 边集合: `edges = {(1, 2), (1, 3), (1, 4), (1, 5), (2, 4), (3, 5), (4, 5)}`

![Picture7.png](https://pic.leetcode-cn.com/1599579136-Fxseew-Picture7.png){:width=500}

表示图的方法通常有两种:

1. **邻接矩阵:** 使用数组 $vertices$ 存储顶点,邻接矩阵 $edges$ 存储边; $edges[i][j]$ 代表节点 $i + 1$ 和 节点 $j + 1$ 之间是否有边。

$$
vertices = [1, 2, 3, 4, 5] \\

edges =  \left[ \begin{matrix} 0 & 1 & 1 & 1 & 1 \\ 1 & 0 & 0 & 1 & 0 \\ 1 & 0 & 0 & 0 & 1 \\ 1 & 1 & 0 & 0 & 1 \\ 1 & 0 & 1 & 1 & 0 \\ \end{matrix} \right]
$$

```Python []
vertices = [1, 2, 3, 4, 5]
edges = [[0, 1, 1, 1, 1],
         [1, 0, 0, 1, 0],
         [1, 0, 0, 0, 1],
         [1, 1, 0, 0, 1],
         [1, 0, 1, 1, 0]]
```

```Java []
int[] vertices = {1, 2, 3, 4, 5};
int[][] edges = {{0, 1, 1, 1, 1},
                 {1, 0, 0, 1, 0},
                 {1, 0, 0, 0, 1},
                 {1, 1, 0, 0, 1},
                 {1, 0, 1, 1, 0}};
```

```C++ []
int vertices[5] = {1, 2, 3, 4, 5};
int edges[5][5] = {{0, 1, 1, 1, 1},
                   {1, 0, 0, 1, 0},
                   {1, 0, 0, 0, 1},
                   {1, 1, 0, 0, 1},
                   {1, 0, 1, 1, 0}};
```

2. **邻接表:** 使用数组 $vertices$ 存储顶点,邻接表 $edges$ 存储边。 $edges$ 为一个二维容器,第一维 $i$ 代表顶点索引,第二维 $edges[i]$ 存储此顶点对应的边集和;例如 $edges[0] = [1, 2, 3, 4]$ 代表 $vertices[0]$ 的边集合为 $[1, 2, 3, 4]$ 。

$$
vertices = [1, 2, 3, 4, 5] \\

edges =  \left[ \begin{matrix} [ & 1 & 2 & 3 & 4 & ] \\ [ & 0 & 3 & ] \\ [ & 0 & 4 & ] \\ [ & 0 & 1 & 4 & ] \\ [ & 0 & 2 & 3 & ] \end{matrix} \right]
$$

```Python []
vertices = [1, 2, 3, 4, 5]
edges = [[1, 2, 3, 4],
         [0, 3],
         [0, 4],
         [0, 1, 4],
         [0, 2, 3]]
```

```Java []
int[] vertices = {1, 2, 3, 4, 5};
List<List<Integer>> edges = new ArrayList<>();

List<Integer> edge_1 = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
List<Integer> edge_2 = new ArrayList<>(Arrays.asList(0, 3));
List<Integer> edge_3 = new ArrayList<>(Arrays.asList(0, 4));
List<Integer> edge_4 = new ArrayList<>(Arrays.asList(0, 1, 4));
List<Integer> edge_5 = new ArrayList<>(Arrays.asList(0, 2, 3));
edges.add(edge_1);
edges.add(edge_2);
edges.add(edge_3);
edges.add(edge_4);
edges.add(edge_5);
```

```C++ []
int vertices[5] = {1, 2, 3, 4, 5};
vector<vector<int>> edges;

vector<int> edge_1 = {1, 2, 3, 4};
vector<int> edge_2 = {0, 3};
vector<int> edge_3 = {0, 4};
vector<int> edge_4 = {0, 1, 4};
vector<int> edge_5 = {0, 2, 3};
edges.push_back(edge_1);
edges.push_back(edge_2);
edges.push_back(edge_3);
edges.push_back(edge_4);
edges.push_back(edge_5);
```

> **邻接矩阵 VS 邻接表 :**
> 
> 邻接矩阵的大小只与节点数量有关,即 $N^2$ ,其中 $N$ 为节点数量。因此,当边数量明显少于节点数量时,使用邻接矩阵存储图会造成较大的内存浪费。
> 因此,**邻接表** 适合存储稀疏图(顶点较多、边较少); **邻接矩阵** 适合存储稠密图(顶点较少、边较多)。

---

## 散列表

散列表是一种非线性数据结构,通过利用 Hash 函数将指定的「键 `key`」映射至对应的「值 `value`」,以实现高效的元素查找。

> 设想一个简单场景:小力、小特、小扣的学号分别为 10001, 10002, 10003 。
> 现需求从「姓名」查找「学号」。

则可通过建立姓名为 `key` ,学号为 `value` 的散列表实现此需求,代码如下:

```Java []
// 初始化散列表
Map<String, Integer> dic = new HashMap<>();

// 添加 key -> value 键值对
dic.put("小力", 10001);
dic.put("小特", 10002);
dic.put("小扣", 10003);

// 从姓名查找学号
dic.get("小力"); // -> 10001
dic.get("小特"); // -> 10002
dic.get("小扣"); // -> 10003
```

```Python []
# 初始化散列表
dic = {}

# 添加 key -> value 键值对
dic["小力"] = 10001
dic["小特"] = 10002
dic["小扣"] = 10003

# 从姓名查找学号
dic["小力"] # -> 10001
dic["小特"] # -> 10002
dic["小扣"] # -> 10003
```

```C++ []
// 初始化散列表
unordered_map<string, int> dic;

// 添加 key -> value 键值对
dic["小力"] = 10001;
dic["小特"] = 10002;
dic["小扣"] = 10003;

// 从姓名查找学号
dic.find("小力")->second; // -> 10001
dic.find("小特")->second; // -> 10002
dic.find("小扣")->second; // -> 10003
```

![Picture8.png](https://pic.leetcode-cn.com/1599811794-ruXMOV-Picture8.png){:width=550}

### Hash 函数设计示例 :

> 假设需求:从「学号」查找「姓名」。

将三人的姓名存储至以下数组中,则各姓名在数组中的索引分别为 0, 1, 2 。

```Java []
String[] names = { "小力", "小特", "小扣" };
```

```Python []
names = [ "小力", "小特", "小扣" ]
```

```C++ []
string names[] = { "小力", "小特", "小扣" };
```

此时,我们构造一个简单的 Hash 函数( $\%$ 为取余符号 ),公式和封装函数如下所示:

$$
hash(key) = (key - 1) \% 10000
$$

```Java []
int hash(int id) {
    int index = (id - 1) % 10000;
    return index;
}
```

```Python []
def hash(id):
    index = (id - 1) % 10000
    return index
```

```C++ []
int hash(int id) {
    int index = (id - 1) % 10000;
    return index;
}
```

则我们构建了以学号为 `key` 、姓名对应的数组索引为 `value` 的散列表。利用此 Hash 函数,则可在 $O(1)$ 时间复杂度下通过学号查找到对应姓名,即:

```Java
names[hash(10001)] // 小力
names[hash(10002)] // 小特
names[hash(10003)] // 小扣
```

![Picture8-1.png](https://pic.leetcode-cn.com/1599811794-NfbpfW-Picture8-1.png){:width=550}

以上设计只适用于此示例,实际的 Hash 函数需保证低碰撞率、 高鲁棒性等,以适用于各类数据和场景。

---

## 堆:

堆是一种基于「完全二叉树」的数据结构,可使用数组实现。以堆为原理的排序算法称为「堆排序」,基于堆实现的数据结构为「优先队列」。堆分为「大顶堆」和「小顶堆」,大(小)顶堆:任意节点的值不大于(小于)其父节点的值。

> **完全二叉树定义:** 设二叉树深度为 $k$ ,若二叉树除第 $k$ 层外的其它各层(第 $1$ 至 $k-1$ 层)的节点达到最大个数,且处于第 $k$  层的节点都连续集中在最左边,则称此二叉树为完全二叉树。

如下图所示,为包含 `1, 4, 2, 6, 8` 元素的小顶堆。将堆(完全二叉树)中的结点按层编号,即可映射到右边的数组存储形式。

![Picture9.png](https://pic.leetcode-cn.com/1599584901-xoiGEQ-Picture9.png){:width=550}

通过使用「优先队列」的「压入 `push()`」和「弹出 `pop()`」操作,即可完成堆排序,实现代码如下:

```Java []
// 初始化小顶堆
Queue<Integer> heap = new PriorityQueue<>();

// 元素入堆
heap.add(1);
heap.add(4);
heap.add(2);
heap.add(6);
heap.add(8);

// 元素出堆(从小到大)
heap.poll(); // -> 1
heap.poll(); // -> 2
heap.poll(); // -> 4
heap.poll(); // -> 6
heap.poll(); // -> 8
```

```Python []
from heapq import heappush, heappop

# 初始化小顶堆
heap = []

# 元素入堆
heappush(heap, 1)
heappush(heap, 4)
heappush(heap, 2)
heappush(heap, 6)
heappush(heap, 8)

# 元素出堆(从小到大)
heappop(heap) # -> 1
heappop(heap) # -> 2
heappop(heap) # -> 4
heappop(heap) # -> 6
heappop(heap) # -> 8
```

```C++ []
// 初始化小顶堆
priority_queue<int, vector<int>, greater<int>> heap;

// 元素入堆
heap.push(1);
heap.push(4);
heap.push(2);
heap.push(6);
heap.push(8);

// 元素出堆(从小到大)
heap.pop(); // -> 1
heap.pop(); // -> 2
heap.pop(); // -> 4
heap.pop(); // -> 6
heap.pop(); // -> 8
```


================================================
FILE: leetbook_ioa/docs/# 1.2 算法复杂度.md
================================================
# 算法复杂度

算法复杂度旨在计算在输入数据量 $N$ 的情况下,算法的「时间使用」和「空间使用」情况;体现算法运行使用的时间和空间随「数据大小 $N$ 」而增大的速度。

算法复杂度主要可从 **时间** 、**空间** 两个角度评价:

- **时间:** 假设各操作的运行时间为固定常数,统计算法运行的「计算操作的数量」 ,以代表算法运行所需时间;
- **空间:** 统计在最差情况下,算法运行所需使用的「最大空间」;

「输入数据大小 $N$ 」指算法处理的输入数据量;根据不同算法,具有不同定义,例如:

- **排序算法:** $N$ 代表需要排序的元素数量;
- **搜索算法:** $N$ 代表搜索范围的元素总数,例如数组大小、矩阵大小、二叉树节点数、图节点和边数等;

接下来,我们将分别从概念定义、符号表示、常见种类、时空权衡、示例解析、示例题目等角度入手,学习「时间复杂度」和「空间复杂度」。


================================================
FILE: leetbook_ioa/docs/# 1.3 时间复杂度.md
================================================
# 时间复杂度

根据定义,时间复杂度指输入数据大小为 $N$ 时,算法运行所需花费的时间。需要注意:

- 统计的是算法的「计算操作数量」,而不是「运行的绝对时间」。计算操作数量和运行绝对时间呈正相关关系,并不相等。算法运行时间受到「编程语言 、计算机处理器速度、运行环境」等多种因素影响。例如,同样的算法使用 Python 或 C++ 实现、使用 CPU 或 GPU 、使用本地 IDE 或力扣平台提交,运行时间都不同。
- 体现的是计算操作随数据大小 $N$ 变化时的变化情况。假设算法运行总共需要「 $1$ 次操作」、「 $100$ 次操作」,此两情况的时间复杂度都为常数级 $O(1)$ ;需要「 $N$ 次操作」、「 $100N$ 次操作」的时间复杂度都为 $O(N)$ 。

---

## 符号表示

根据输入数据的特点,时间复杂度具有「最差」、「平均」、「最佳」三种情况,分别使用 $O$ , $\Theta$ , $\Omega$ 三种符号表示。以下借助一个查找算法的示例题目帮助理解。

> **题目:** 输入长度为 $N$ 的整数数组 `nums` ,判断此数组中是否有数字 $7$ ,若有则返回 `true` ,否则返回 $\text{false}$ 。
>
> **解题算法:** 线性查找,即遍历整个数组,遇到 $7$ 则返回 `true` 。
>
> **代码:**
>
> ```Python []
> def find_seven(nums):
>     for num in nums:
>         if num == 7:
>             return True
>     return False
> ```
>
> ```Java []
> boolean findSeven(int[] nums) {
>     for (int num : nums) {
>         if (num == 7)
>             return true;
>     }
>     return false;
> }
> ```
>
> ```C++ []
> bool findSeven(vector<int>& nums) {
>     for (int num : nums) {
>         if (num == 7)
>             return true;
>     }
>     return false;
> }
> ```

- **最佳情况 $\Omega(1)$ :** `nums = [7, a, b, c, ...]` ,即当数组首个数字为 $7$ 时,无论 `nums` 有多少元素,线性查找的循环次数都为 $1$ 次;
- **最差情况 $O(N)$ :** `nums = [a, b, c, ...]` 且 `nums` 中所有数字都不为 $7$ ,此时线性查找会遍历整个数组,循环 $N$ 次;
- **平均情况 $\Theta$ :** 需要考虑输入数据的分布情况,计算所有数据情况下的平均时间复杂度;例如本题目,需要考虑数组长度、数组元素的取值范围等;

> 大 $O$ 是最常使用的时间复杂度评价渐进符号,下文示例与本 LeetBook 题目解析皆使用 $O$ 。

---

## 常见种类

根据从小到大排列,常见的算法时间复杂度主要有:

$$
O(1) < O(\log N) < O(N) < O(N\log N) < O(N^2) < O(2^N) < O(N!)
$$

![Picture1.png](https://pic.leetcode-cn.com/1623519242-UTNefQ-Picture1.png)

对于以下所有示例,设输入数据大小为 $N$ ,计算操作数量为 $count$ 。图中每个「**蓝色方块**」代表一个单元计算操作。

### 常数 $O(1)$ :

运行次数与 $N$ 大小呈常数关系,即不随输入数据大小 $N$ 的变化而变化。

```Python []
def algorithm(N):
    a = 1
    b = 2
    x = a * b + N
    return 1
```

```Java []
int algorithm(int N) {
    int a = 1;
    int b = 2;
    int x = a * b + N;
    return 1;
}
```

```C++ []
int algorithm(int N) {
    int a = 1;
    int b = 2;
    int x = a * b + N;
    return 1;
}
```

对于以下代码,无论 $a$ 取多大,都与输入数据大小 $N$ 无关,因此时间复杂度仍为 $O(1)$ 。

```Python []
def algorithm(N):
    count = 0
    a = 10000
    for i in range(a):
        count += 1
    return count
```

```Java []
int algorithm(int N) {
    int count = 0;
    int a = 10000;
    for (int i = 0; i < a; i++) {
        count++;
    }
    return count;
}
```

```C++ []
int algorithm(int N) {
    int count = 0;
    int a = 10000;
    for (int i = 0; i < a; i++) {
        count++;
    }
    return count;
}
```

![Picture2.png](https://pic.leetcode-cn.com/1623779241-lViysV-Picture2.png){:width=500}

### 线性 $O(N)$ :

循环运行次数与 $N$ 大小呈线性关系,时间复杂度为 $O(N)$ 。

```Python []
def algorithm(N):
    count = 0
    for i in range(N):
        count += 1
    return count
```

```Java []
int algorithm(int N) {
    int count = 0;
    for (int i = 0; i < N; i++)
        count++;
    return count;
}
```

```C++ []
int algorithm(int N) {
    int count = 0;
    for (int i = 0; i < N; i++)
        count++;
    return count;
}
```

对于以下代码,虽然是两层循环,但第二层与 $N$ 大小无关,因此整体仍与 $N$ 呈线性关系。

```Python []
def algorithm(N):
    count = 0
    a = 10000
    for i in range(N):
        for j in range(a):
            count += 1
    return count
```

```Java []
int algorithm(int N) {
    int count = 0;
    int a = 10000;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < a; j++) {
            count++;
        }
    }
    return count;
}
```

```C++ []
int algorithm(int N) {
    int count = 0;
    int a = 10000;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < a; j++) {
            count++;
        }
    }
    return count;
}
```

![Picture3.png](https://pic.leetcode-cn.com/1623519242-AhnqvJ-Picture3.png){:width=500}

### 平方 $O(N^2)$ :

两层循环相互独立,都与 $N$ 呈线性关系,因此总体与 $N$ 呈平方关系,时间复杂度为 $O(N^2)$ 。

```Python []
def algorithm(N):
    count = 0
    for i in range(N):
        for j in range(N):
            count += 1
    return count
```

```Java []
int algorithm(int N) {
    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            count++;
        }
    }
    return count;
}
```

```C++ []
int algorithm(int N) {
    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            count++;
        }
    }
    return count;
}
```

以「冒泡排序」为例,其包含两层独立循环:

1. 第一层复杂度为 $O(N)$ ;
2. 第二层平均循环次数为 $\frac{N}{2}$ ,复杂度为 $O(N)$ ,推导过程如下:

$$
O(\frac{N}{2}) = O(\frac{1}{2})O(N) = O(1)O(N) = O(N)
$$

因此,冒泡排序的总体时间复杂度为 $O(N^2)$ ,代码如下所示。

```Python []
def bubble_sort(nums):
    N = len(nums)
    for i in range(N - 1):
        for j in range(N - 1 - i):
            if nums[j] > nums[j + 1]:
                nums[j], nums[j + 1] = nums[j + 1], nums[j]
    return nums
```

```Java []
int[] bubbleSort(int[] nums) {
    int N = nums.length;
    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j < N - 1 - i; j++) {
            if (nums[j] > nums[j + 1]) {
                int tmp = nums[j];
                nums[j] = nums[j + 1];
                nums[j + 1] = tmp;
            }
        }
    }
    return nums;
}
```

```C++ []
vector<int> bubbleSort(vector<int>& nums) {
    int N = nums.size();
    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j < N - 1 - i; j++) {
            if (nums[j] > nums[j + 1]) {
                swap(nums[j], nums[j + 1]);
            }
        }
    }
    return nums;
}
```

![Picture4.png](https://pic.leetcode-cn.com/1623519242-piiPrs-Picture4.png){:width=450}

### 指数 $O(2^N)$ :

生物学科中的 “细胞分裂” 即是指数级增长。初始状态为 $1$ 个细胞,分裂一轮后为 $2$ 个,分裂两轮后为 $4$ 个,……,分裂 $N$ 轮后有 $2^N$ 个细胞。

算法中,指数阶常出现于递归,算法原理图与代码如下所示。

```Python []
def algorithm(N):
    if N <= 0: return 1
    count_1 = algorithm(N - 1)
    count_2 = algorithm(N - 1)
    return count_1 + count_2
```

```Java []
int algorithm(int N) {
    if (N <= 0) return 1;
    int count_1 = algorithm(N - 1);
    int count_2 = algorithm(N - 1);
    return count_1 + count_2;
}
```

```C++ []
int algorithm(int N) {
    if (N <= 0) return 1;
    int count_1 = algorithm(N - 1);
    int count_2 = algorithm(N - 1);
    return count_1 + count_2;
}
```

![Picture5.png](https://pic.leetcode-cn.com/1623519242-XLBkIT-Picture5.png){:width=600}

### 阶乘 $O(N!)$ :

阶乘阶对应数学上常见的 “全排列” 。即给定 $N$ 个互不重复的元素,求其所有可能的排列方案,则方案数量为:

$$
N \times (N - 1) \times (N - 2) \times \cdots \times 2 \times 1 = N!
$$

如下图与代码所示,阶乘常使用递归实现,算法原理:第一层分裂出 $N$ 个,第二层分裂出 $N - 1$ 个,…… ,直至到第 $N$ 层时终止并回溯。

```Python []
def algorithm(N):
    if N <= 0: return 1
    count = 0
    for _ in range(N):
        count += algorithm(N - 1)
    return count
```

```Java []
int algorithm(int N) {
    if (N <= 0) return 1;
    int count = 0;
    for (int i = 0; i < N; i++) {
        count += algorithm(N - 1);
    }
    return count;
}
```

```C++ []
int algorithm(int N) {
    if (N <= 0) return 1;
    int count = 0;
    for (int i = 0; i < N; i++) {
        count += algorithm(N - 1);
    }
    return count;
}
```

![Picture6.png](https://pic.leetcode-cn.com/1623519242-AFSqrK-Picture6.png){:width=600}

### 对数 $O(\log N)$ :

对数阶与指数阶相反,指数阶为 “每轮分裂出两倍的情况” ,而对数阶是 “每轮排除一半的情况” 。对数阶常出现于「二分法」、「分治」等算法中,体现着 “一分为二” 或 “一分为多” 的算法思想。

设循环次数为 $m$ ,则输入数据大小 $N$ 与 $2 ^ m$ 呈线性关系,两边同时取 $log_2$ 对数,则得到循环次数 $m$ 与 $\log_2 N$ 呈线性关系,即时间复杂度为 $O(\log N)$ 。

```Python []
def algorithm(N):
    count = 0
    i = N
    while i > 1:
        i = i / 2
        count += 1
    return count
```

```Java []
int algorithm(int N) {
    int count = 0;
    float i = N;
    while (i > 1) {
        i = i / 2;
        count++;
    }
    return count;
}
```

```C++ []
int algorithm(int N) {
    int count = 0;
    float i = N;
    while (i > 1) {
        i = i / 2;
        count++;
    }
    return count;
}
```

如以下代码所示,对于不同 $a$ 的取值,循环次数 $m$ 与 $\log_a N$ 呈线性关系 ,时间复杂度为 $O(\log_a N)$ 。而无论底数 $a$ 取值,时间复杂度都可记作 $O(\log N)$ ,根据对数换底公式的推导如下:

$$
O(\log_a N) = \frac{O(\log_2 N)}{O(\log_2 a)} = O(\log N)
$$

```Python []
def algorithm(N):
    count = 0
    i = N
    a = 3
    while i > 1:
        i = i / a
        count += 1
    return count
```

```Java []
int algorithm(int N) {
    int count = 0;
    float i = N;
    int a = 3;
    while (i > 1) {
        i = i / a;
        count++;
    }
    return count;
}
```

```C++ []
int algorithm(int N) {
    int count = 0;
    float i = N;
    int a = 3;
    while (i > 1) {
        i = i / a;
        count++;
    }
    return count;
}
```

> 如下图所示,为二分查找的时间复杂度示意图,每次二分将搜索区间缩小一半。

![Picture7.png](https://pic.leetcode-cn.com/1623519242-WthaZa-Picture7.png){:width=600}

### 线性对数 $O(N \log N)$ :

两层循环相互独立,第一层和第二层时间复杂度分别为 $O(\log N)$ 和 $O(N)$ ,则总体时间复杂度为 $O(N \log N)$ ;

```Python []
def algorithm(N):
    count = 0
    i = N
    while i > 1:
        i = i / 2
        for j in range(N):
            count += 1
```

```Java []
int algorithm(int N) {
    int count = 0;
    float i = N;
    while (i > 1) {
        i = i / 2;
        for (int j = 0; j < N; j++)
            count++;
    }
    return count;
}
```

```C++ []
int algorithm(int N) {
    int count = 0;
    float i = N;
    while (i > 1) {
        i = i / 2;
        for (int j = 0; j < N; j++)
            count++;
    }
    return count;
}
```

线性对数阶常出现于排序算法,例如「快速排序」、「归并排序」、「堆排序」等,其时间复杂度原理如下图所示。

![Picture8.png](https://pic.leetcode-cn.com/1623519242-rhCOIh-Picture8.png)

---

## 示例题目

以下列举本 LeetBook 中各时间复杂度的对应示例题解,以帮助加深理解。

| 时间复杂度    | 示例题解                                                                                                                                                                                       |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| $O(1)$        | [砍竹子 I](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/5vyva2/)、[文物朝代判断](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/572x9r/)                   |
| $O(\log N)$   | [Pow(x, n)](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/57p2pv/)、[统计目标成绩的出现次数](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/58lgr7/)        |
| $O(N)$        | [训练计划 III](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/9p7s17/)、[斐波那契数](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/50fji7/)                 |
| $O(N \log N)$ | [破解闯关密码](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/59ceyt/)、[交易逆序对的总数](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/o53yjd/)           |
| $O(N^2)$      | [验证二叉搜索树的后序遍历序列](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/5vwbf6/)、[招式拆解 I](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/5dz9di/) |
| $O(N!)$       | [套餐内商品的排列顺序](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/50hah3/)                                                                                                |


================================================
FILE: leetbook_ioa/docs/# 1.4 空间复杂度.md
================================================
# 空间复杂度

空间复杂度涉及的空间类型有:

- **输入空间:** 存储输入数据所需的空间大小;
- **暂存空间:** 算法运行过程中,存储所有中间变量和对象等数据所需的空间大小;
- **输出空间:** 算法运行返回时,存储输出数据所需的空间大小;

通常情况下,空间复杂度指在输入数据大小为 $N$ 时,算法运行所使用的「暂存空间」+「输出空间」的总体大小。

![Picture1.png](https://pic.leetcode-cn.com/1623769147-NnmTbL-Picture1.png){:width=500}

而根据不同来源,算法使用的内存空间分为三类:

**指令空间:**

编译后,程序指令所使用的内存空间。

**数据空间:**

算法中的各项变量使用的空间,包括:声明的常量、变量、动态数组、动态对象等使用的内存空间。

```Python []
class Node:
    def __init__(self, val):
        self.val = val
        self.next = None

def algorithm(N):
    num = N         # 变量
    nums = [0] * N  # 动态数组
    node = Node(N)  # 动态对象
```

```Java []
class Node {
    int val;
    Node next;
    Node(int x) { val = x; }
}

void algorithm(int N) {
    int num = N;             // 变量
    int[] nums = new int[N]; // 动态数组
    Node node = new Node(N); // 动态对象
}
```

```C++ []
struct Node {
    int val;
    Node *next;
    Node(int x) : val(x), next(NULL) {}
};

void algorithm(int N) {
    int num = N;              // 变量
    int nums[N];              // 动态数组
    Node* node = new Node(N); // 动态对象
}
```

**栈帧空间:**

程序调用函数是基于栈实现的,函数在调用期间,占用常量大小的栈帧空间,直至返回后释放。如以下代码所示,在循环中调用函数,每轮调用 `test()` 返回后,栈帧空间已被释放,因此空间复杂度仍为 $O(1)$  。

```Python []
def test():
    return 0

def algorithm(N):
    for _ in range(N):
        test()
```

```Java []
int test() {
    return 0;
}

void algorithm(int N) {
    for (int i = 0; i < N; i++) {
        test();
    }
}
```

```C++ []
int test() {
    return 0;
}

void algorithm(int N) {
    for (int i = 0; i < N; i++) {
        test();
    }
}
```

算法中,栈帧空间的累计常出现于递归调用。如以下代码所示,通过递归调用,会同时存在 $N$ 个未返回的函数 `algorithm()` ,此时累计使用 $O(N)$ 大小的栈帧空间。

```Python []
def algorithm(N):
    if N <= 1: return 1
    return algorithm(N - 1) + 1
```

```Java []
int algorithm(int N) {
    if (N <= 1) return 1;
    return algorithm(N - 1) + 1;
}
```

```C++ []
int algorithm(int N) {
    if (N <= 1) return 1;
    return algorithm(N - 1) + 1;
}
```

---

## 符号表示

通常情况下,空间复杂度统计算法在 “最差情况” 下使用的空间大小,以体现算法运行所需预留的空间量,使用符号 $O$ 表示。

最差情况有两层含义,分别为「最差输入数据」、算法运行中的「最差运行点」。例如以下代码:

> 输入整数 $N$ ,取值范围 $N \geq 1$ ;

- **最差输入数据:** 当 $N \leq 10$ 时,数组 `nums` 的长度恒定为 10 ,空间复杂度为 $O(10) = O(1)$ ;当 $N > 10$ 时,数组 $nums$ 长度为 $N$ ,空间复杂度为 $O(N)$ ;因此,空间复杂度应为最差输入数据情况下的 $O(N)$ 。
- **最差运行点:** 在执行 `nums = [0] * 10` 时,算法仅使用 $O(1)$ 大小的空间;而当执行 `nums = [0] * N` 时,算法使用 $O(N)$ 的空间;因此,空间复杂度应为最差运行点的 $O(N)$ 。

```Python []
def algorithm(N):
    num = 5             # O(1)
    nums = [0] * 10     # O(1)
    if N > 10:
        nums = [0] * N  # O(N)
```

```Java []
void algorithm(int N) {
    int num = 5;              // O(1)
    int[] nums = new int[10]; // O(1)
    if (N > 10) {
        nums = new int[N];    // O(N)
    }
}
```

```C++ []
void algorithm(int N) {
    int num = 5;           // O(1)
    vector<int> nums(10);  // O(1)
    if (N > 10) {
        nums.resize(N);    // O(N)
    }
}
```

---

## 常见种类

根据从小到大排列,常见的算法空间复杂度有:

$$
O(1) < O(\log N) < O(N) < O(N^2) < O(2^N)
$$

![Picture2.png](https://pic.leetcode-cn.com/1623769147-SyWGvV-Picture2.png)

对于以下所有示例,设输入数据大小为正整数 $N$ ,节点类 `Node` 、函数 `test()` 如以下代码所示。

```Python []
# 节点类 Node
class Node:
    def __init__(self, val):
        self.val = val
        self.next = None

# 函数 test()
def test():
    return 0
```

```Java []
// 节点类 Node
class Node {
    int val;                 // 变量
    Node next;               // 动态数组
    Node(int x) { val = x; } // 动态对象
}

// 函数 test()
int test() {
    return 0;
}
```

```C++ []
// 节点类 Node
struct Node {
    int val;
    Node *next;
    Node(int x) : val(x), next(NULL) {}
};

// 函数 test()
int test() {
    return 0;
}
```

### 常数 $O(1)$ :

普通常量、变量、对象、元素数量与输入数据大小 $N$ 无关的集合,皆使用常数大小的空间。

```Python []
def algorithm(N):
    num = 0
    nums = [0] * 10000
    node = Node(0)
    dic = { 0: '0' }
```

```Java []
void algorithm(int N) {
    int num = 0;
    int[] nums = new int[10000];
    Node node = new Node(0);
    Map<Integer, String> dic = new HashMap<>() {{ put(0, "0"); }};
}
```

```C++ []
void algorithm(int N) {
    int num = 0;
    int nums[10000];
    Node* node = new Node(0);
    unordered_map<int, string> dic;
    dic.emplace(0, "0");
}
```

如以下代码所示,虽然函数 `test()` 调用了 $N$ 次,但每轮调用后 `test()` 已返回,无累计栈帧空间使用,因此空间复杂度仍为 $O(1)$ 。

```Python []
def algorithm(N):
    for _ in range(N):
        test()
```

```Java []
void algorithm(int N) {
    for (int i = 0; i < N; i++) {
        test();
    }
}
```

```C++ []
void algorithm(int N) {
    for (int i = 0; i < N; i++) {
        test();
    }
}
```

### 线性 $O(N)$ :

元素数量与 $N$ 呈线性关系的任意类型集合(常见于一维数组、链表、哈希表等),皆使用线性大小的空间。

```Python []
def algorithm(N):
    nums_1 = [0] * N
    nums_2 = [0] * (N // 2)

    nodes = [Node(i) for i in range(N)]
    
    dic = {}
    for i in range(N):
        dic[i] = str(i)
```

```Java []
void algorithm(int N) {
    int[] nums_1 = new int[N];
    int[] nums_2 = new int[N / 2];

    List<Node> nodes = new ArrayList<>();
    for (int i = 0; i < N; i++) {
        nodes.add(new Node(i));
    }

    Map<Integer, String> dic = new HashMap<>();
    for (int i = 0; i < N; i++) {
        dic.put(i, String.valueOf(i));
    }
}
```

```C++ []
void algorithm(int N) {
    int nums_1[N];
    int nums_2[N / 2 + 1];

    vector<Node*> nodes;
    for (int i = 0; i < N; i++) {
        nodes.push_back(new Node(i));
    }

    unordered_map<int, string> dic;
    for (int i = 0; i < N; i++) {
        dic.emplace(i, to_string(i));
    }
}
```

如下图与代码所示,此递归调用期间,会同时存在 $N$ 个未返回的 `algorithm()` 函数,因此使用 $O(N)$ 大小的栈帧空间。

```Python []
def algorithm(N):
    if N <= 1: return 1
    return algorithm(N - 1) + 1
```

```Java []
int algorithm(int N) {
    if (N <= 1) return 1;
    return algorithm(N - 1) + 1;
}
```

```C++ []
int algorithm(int N) {
    if (N <= 1) return 1;
    return algorithm(N - 1) + 1;
}
```

![Picture3.png](https://pic.leetcode-cn.com/1623771937-urjBWX-Picture3.png)

### 平方 $O(N^2)$ :

元素数量与 $N$ 呈平方关系的任意类型集合(常见于矩阵),皆使用平方大小的空间。

```Python []
def algorithm(N):
    num_matrix = [[0 for j in range(N)] for i in range(N)]
    node_matrix = [[Node(j) for j in range(N)] for i in range(N)]
```

```Java []
void algorithm(int N) {
    int num_matrix[][] = new int[N][N];

    List<List<Node>> node_matrix = new ArrayList<>();
    for (int i = 0; i < N; i++) {
        List<Node> nodes = new ArrayList<>();
        for (int j = 0; j < N; j++) {
            nodes.add(new Node(j));
        }
        node_matrix.add(nodes);
    }
}
```

```C++ []
void algorithm(int N) {
    vector<vector<int>> num_matrix;
    for (int i = 0; i < N; i++) {
        vector<int> nums;
        for (int j = 0; j < N; j++) {
            nums.push_back(0);
        }
        num_matrix.push_back(nums);
    }

    vector<vector<Node*>> node_matrix;
    for (int i = 0; i < N; i++) {
        vector<Node*> nodes;
        for (int j = 0; j < N; j++) {
            nodes.push_back(new Node(j));
        }
        node_matrix.push_back(nodes);
    }
}
```

如下图与代码所示,递归调用时同时存在 $N$ 个未返回的 `algorithm()` 函数,使用 $O(N)$ 栈帧空间;每层递归函数中声明了数组,平均长度为 $\frac{N}{2}$ ,使用 $O(N)$ 空间;因此总体空间复杂度为 $O(N^2)$ 。

```Python []
def algorithm(N):
    if N <= 0: return 0
    nums = [0] * N
    return algorithm(N - 1)
```

```Java []
int algorithm(int N) {
    if (N <= 0) return 0;
    int[] nums = new int[N];
    return algorithm(N - 1);
}
```

```C++ []
int algorithm(int N) {
    if (N <= 0) return 0;
    int nums[N];
    return algorithm(N - 1);
}
```

![Picture4.png](https://pic.leetcode-cn.com/1623769147-PYKjhh-Picture4.png)

### 指数 $O(2^N)$ :

指数阶常见于二叉树、多叉树。例如,高度为 $N$ 的「满二叉树」的节点数量为 $2^N$ ,占用 $O(2^N)$ 大小的空间;同理,高度为 $N$ 的「满 $m$ 叉树」的节点数量为 $m^N$ ,占用 $O(m^N) = O(2^N)$ 大小的空间。

![Picture5.png](https://pic.leetcode-cn.com/1623769147-FLxBQi-Picture5.png){:width=600}

### 对数 $O(\log N)$ :

对数阶常出现于分治算法的栈帧空间累计、数据类型转换等,例如:

- **快速排序** ,平均空间复杂度为 $\Theta(\log N)$ ,最差空间复杂度为 $O(N)$ 。拓展知识:通过应用 [尾递归优化](https://stackoverflow.com/questions/310974/what-is-tail-call-optimization) ,可以将快速排序的最差空间复杂度限定至 $O(N)$ 。
- **数字转化为字符串** ,设某正整数为 $N$ ,则字符串的空间复杂度为 $O(\log N)$ 。推导如下:正整数 $N$ 的位数为 $log_{10} N$ ,即转化的字符串长度为 $\log_{10} N$ ,因此空间复杂度为 $O(\log N)$ 。

---

## 时空权衡

对于算法的性能,需要从时间和空间的使用情况来综合评价。优良的算法应具备两个特性,即时间和空间复杂度皆较低。而实际上,对于某个算法问题,同时优化时间复杂度和空间复杂度是非常困难的。降低时间复杂度,往往是以提升空间复杂度为代价的,反之亦然。

> 由于当代计算机的内存充足,通常情况下,算法设计中一般会采取「空间换时间」的做法,即牺牲部分计算机存储空间,来提升算法的运行速度。

以 LeetCode 全站第一题 [两数之和](https://leetcode-cn.com/problems/two-sum/) 为例,「暴力枚举」和「辅助哈希表」分别为「空间最优」和「时间最优」的两种算法。

### 方法一:暴力枚举

时间复杂度 $O(N^2)$ ,空间复杂度 $O(1)$ ;属于「时间换空间」,虽然仅使用常数大小的额外空间,但运行速度过慢。

```Python []
class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for i in range(len(nums) - 1):
            for j in range(i + 1, len(nums)):
                if nums[i] + nums[j] == target:
                    return i, j
        return
```

```Java []
class Solution {
    public int[] twoSum(int[] nums, int target) {
        int size = nums.length;
        for (int i = 0; i < size - 1; i++) {
            for (int j = i + 1; j < size; j++) {
                if (nums[i] + nums[j] == target)
                    return new int[] { i, j };
            }
        }
        return new int[0];
    }
}
```

```C++ []
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int size = nums.size();
        for (int i = 0; i < size - 1; i++) {
            for (int j = i + 1; j < size; j++) {
                if (nums[i] + nums[j] == target)
                    return { i, j };
            }
        }
        return {};
    }
};
```

### 方法二:辅助哈希表

时间复杂度 $O(N)$ ,空间复杂度 $O(N)$ ;属于「空间换时间」,借助辅助哈希表 `dic` ,通过保存数组元素值与索引的映射来提升算法运行效率,是本题的最佳解法。

```Python []
class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        dic = {}
        for i in range(len(nums)):
            if target - nums[i] in dic:
                return dic[target - nums[i]], i
            dic[nums[i]] = i
        return []
```

```Java []
class Solution {
    public int[] twoSum(int[] nums, int target) {
        int size = nums.length;
        Map<Integer, Integer> dic = new HashMap<>();
        for (int i = 0; i < size; i++) {
            if (dic.containsKey(target - nums[i])) {
                return new int[] { dic.get(target - nums[i]), i };
            }
            dic.put(nums[i], i);
        }
        return new int[0];
    }
}
```

```C++ []
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int size = nums.size();
        unordered_map<int, int> dic;
        for (int i = 0; i < size; i++) {
            if (dic.find(target - nums[i]) != dic.end()) {
                return { dic[target - nums[i]], i };
            }
            dic.emplace(nums[i], i);
        }
        return {};
    }
};
```

---

## 示例题目

在 LeetCode 题目中,「输入空间」和「输出空间」往往是固定的,是必须使用的内存空间。因希望专注于算法性能对比,本 LeetBook 的题目解析的空间复杂度仅统计「暂存空间」大小。

| 空间复杂度  | 示例题解                                                                                                                                                                             |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| $O(1)$      | [斐波那契数](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/50fji7/)、[训练计划 III](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/9p7s17/)       |
| $O(\log N)$ | [库存管理 III](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/ohwddh/)、[找到第 k 位数字](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/57w6b3/)  |
| $O(N)$      | [图书整理 I](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/5d8831/)、[动态口令](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/58eckc/)           |
| $O(N^2)$    | [衣橱整理](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/9hka9c/)、[套餐内商品的排列顺序](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/50hah3/) |


================================================
FILE: leetbook_ioa/docs/# 11.1 动态规划解题框架.md
================================================
# 动态规划解题框架

动态规划是算法与数据结构的重难点之一,其包含了「分治思想」、「空间换时间」、「最优解」等多种基石算法思想,常作为笔面试中的中等困难题出现。为帮助读者全面理解动态规划,知晓其来龙去脉,本文将从以下几个角度切入介绍:

1. 动态规划问题特点,**动态规划**和**分治算法**的联系与区别;
2. 借助例题介绍**重叠子问题**和**最优子结构**分别是什么,以及动态规划是如何解决它们的;
3. 动态规划的**解题框架**总结;
4. 动态规划的**练习例题**,从易到难排序;

---

## 动态规划特点

「分治」是算法中的一种基本思想,其通过**将原问题分解为子问题**,不断递归地将子问题分解为更小的子问题,并通过**组合子问题的解**来得到原问题的解。

类似于分治算法,「动态规划」也通过组合子问题的解得到原问题的解。不同的是,适合用动态规划解决的问题具有「重叠子问题」和「最优子结构」两大特性。

### 重叠子问题

动态规划的子问题是有**重叠的**,即各个子问题中包含**重复的更小子问题**。若使用暴力法穷举,求解这些相同子问题会产生大量的重复计算,效率低下。

动态规划在第一次求解某子问题时,会将子问题的解保存;后续遇到重叠子问题时,则直接通过查表获取解,保证每个**独立子问题只被计算一次**,从而降低算法的时间复杂度。

### 最优子结构

如果一个问题的最优解可以由其子问题的最优解组合构成,并且这些子问题可以独立求解,那么称此问题具有最优子结构。

动态规划从基础问题的解开始,不断迭代**组合、选择子问题的最优解**,最终得到原问题最优解。

---

## 重叠子问题示例:斐波那契数列

> 斐波那契数形成的数列为 $[0, 1, 1, 2, 3, 5, 8, 13, \cdots]$ ,数学定义如下:
> $$
> \begin{aligned}
> & F_0 = 0 \\
> & F_1 = 1 \\
> & F_n = F_{n-1} + F_{n-2}
> \end{aligned}
> $$
> **题目:** 求取第 $n$ 个斐波那契数(从第 0 个斐波那契数开始)。

以下,本文从「暴力递归」$\rightarrow$「记忆化递归」$\rightarrow$「动态规划」三种解法,介绍**重叠子问题**的概念与解决方案。

### 方法一:暴力递归

设斐波那契数列第 $n$ 个数字为 $f(n)$ 。根据数列定义,可得 $f(n) = f(n - 1) + f(n - 2)$ ,且第 0 , 1 个斐波那契数分别为 $f(0) = 0$ , $f(1) = 1$ 。

我们很容易联想到使用分治思想来求取 $f(n)$ ,即将求原问题 $f(n)$ 分解为求子问题 $f(n-1)$ 和 $f(n-2)$ ,向下递归直至已知的 $f(0)$ 和 $f(1)$ ,最终组合这些子问题求取原问题 $f(n)$ 。

```Python []
# 求第 n 个斐波那契数
def fibonacci(n):
    if n == 0: return 0 # 返回 f(0)
    if n == 1: return 1 # 返回 f(1)
    return fibonacci(n - 1) + fibonacci(n - 2) # 分解为两个子问题求解
```

```Java []
// 求第 n 个斐波那契数
int fibonacci(int n) {
    if (n == 0) return 0; // 返回 f(0)
    if (n == 1) return 1; // 返回 f(1)
    return fibonacci(n - 1) + fibonacci(n - 2); // 分解为两个子问题求解
}
```

```C++ []
int fibonacci(int n) {
    if (n == 0) return 0; // 返回 f(0)
    if (n == 1) return 1; // 返回 f(1)
    return fibonacci(n - 1) + fibonacci(n - 2); // 分解为两个子问题求解
}
```

![Picture1.png](https://pic.leetcode-cn.com/1635075778-GADtbi-Picture1.png)

如上图所示,为暴力递归求斐波那契数 $f(5)$ 形成的二叉树,树中的每个节点代表着执行了一次 `fibonacci()` 函数,且有:

- 执行一次 `fibonacci()` 函数的时间复杂度为 $O(1)$ ;
- 二叉树节点数为指数级 $O(2^n)$ ;

因此,暴力递归的总体时间复杂度为 $O(2^n)$ 。此方法效率低下,随着 $n$ 的增长产生指数级爆炸。

### 方法二:记忆化递归

观察发现,暴力递归中的子问题多数都是**重叠子问题**,即:

$$
\begin{aligned}
& f(n) = f(n - 1) + f(n - 2) & 包含 f(n - 2) \\
& f(n - 1) = f(n - 2) + f(n - 3) & 重复 f(n - 2) \\
& f(n - 2) = f(n - 3) + f(n - 4) & 重复 f(n - 3) \\
& \cdots &以此类推
\end{aligned}
$$

这些重叠子问题产生了大量的递归树节点,其**不应被重复计算**。实际上,可以在递归中**第一次求解子问题**时,就将它们**保存**;后续递归中再次遇到相同子问题时,直接访问内存赋值即可。记忆化递归的代码如下所示。

```Python []
def fibonacci(n, dp):
    if n == 0: return 0           # 返回 f(0)
    if n == 1: return 1           # 返回 f(1)
    if dp[n] != 0: return dp[n]   # 若 f(n) 以前已经计算过,则直接返回记录的解
    dp[n] = fibonacci(n - 1, dp) + fibonacci(n - 2, dp) # 将 f(n) 则记录至 dp
    return dp[n]

# 求第 n 个斐波那契数
def fibonacci_memorized(n):
    dp = [0] * (n + 1) # 用于保存 f(0) 至 f(n) 问题的解
    return fibonacci(n, dp)
```

```Java []
int fibonacci(int n, int[] dp) {
    if (n == 0) return 0;           // 返回 f(0)
    if (n == 1) return 1;           // 返回 f(1)
    if (dp[n] != 0) return dp[n];   // 若 f(n) 以前已经计算过,则直接返回记录的解
    dp[n] = fibonacci(n - 1, dp) + fibonacci(n - 2, dp); // 将 f(n) 则记录至 dp
    return dp[n];
}


// 求第 n 个斐波那契数
int fibonacciMemorized(int n) {
    int[] dp = new int[n + 1]; // 用于保存 f(0) 至 f(n) 问题的解
    return fibonacci(n, dp);
}
```

```C++ []
int fibonacci(int n, vector<int> dp) {
    if (n == 0) return 0;           // 返回 f(0)
    if (n == 1) return 1;           // 返回 f(1)
    if (dp[n] != 0) return dp[n];   // 若 f(n) 以前已经计算过,则直接返回记录的解
    dp[n] = fibonacci(n - 1, dp) + fibonacci(n - 2, dp); // 将 f(n) 则记录至 dp
    return dp[n];
}


// 求第 n 个斐波那契数
int fibonacciMemorized(int n) {
    vector<int> dp(n + 1, 0); // 用于保存 f(0) 至 f(n) 问题的解
    return fibonacci(n, dp);
}
```

如下图所示,应用记忆化递归方法后,递归树中绝大部分节点被**剪枝**。此时,`fibonacci()` 函数的调用次数从 $O(2^n)$ 指数级别降低至 $O(n)$ 线性级别,时间复杂度大大降低。

![Picture2.png](https://pic.leetcode-cn.com/1635075778-pJXkPc-Picture2.png)

### 方法三:动态规划

递归本质上是基于分治思想的从顶至底的解法。借助记忆化递归思想,可应用动态规划从底至顶求取 $f(n)$ ,代码如下所示。

```Python []
# 求第 n 个斐波那契数
def fibonacci(n):
    if n == 0: return 0       # 若求 f(0) 则直接返回 0
    dp = [0] * (n + 1)        # 初始化 dp 列表
    dp[0], dp[1] = 0, 1       # 初始化 f(0), f(1)
    for i in range(2, n + 1): # 状态转移求取 f(2), f(3), ..., f(n) 
        dp[i] = dp[i - 1] + dp[i - 2]
    return dp[n]              # 返回 f(n)
```

```Java []
// 求第 n 个斐波那契数
int fibonacci(int n) {
    if (n == 0) return 0;          // 若求 f(0) 则直接返回 0
    int[] dp = new int[n + 1];     // 初始化 dp 列表
    dp[1] = 1;                     // 初始化 f(0), f(1)
    for (int i = 2; i <= n; i++) { // 状态转移求取 f(2), f(3), ..., f(n) 
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    return dp[n];                  // 返回 f(n)
}
```

```C++ []
// 求第 n 个斐波那契数
int fibonacci(int n) {
    if (n == 0) return 0;          // 若求 f(0) 则直接返回 0
    vector<int> dp(n + 1, 0);      // 初始化 dp 列表
    dp[1] = 1;                     // 初始化 f(0), f(1)
    for (int i = 2; i <= n; i++) { // 状态转移求取 f(2), f(3), ..., f(n) 
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    return dp[n];                  // 返回 f(n)
}
```

如下图所示,为动态规划求解 $f(5)$ 的迭代流程,其是转移方程 $f(n) = f(n - 1) + f(n - 2)$ 的体现。

![Picture3.png](https://pic.leetcode-cn.com/1635075778-EeBEoS-Picture3.png)

上述动态规划解法借助了一个 `dp` 数组保存子问题的解,其空间复杂度为 $O(N)$ 。而由于 $f(n)$ 只与 $f(n - 1)$ 和 $f(n - 2)$ 有关,因此我们可以仅使用两个变量 $a$ , $b$ 交替前进计算即可。此时动态规划的空间复杂度降低至 $O(1)$ ,代码如下所示。

```Python []
# 求第 n 个斐波那契数
def fibonacci(n):
    if n == 0: return 0       # 若求 f(0) 则直接返回 0
    a, b = 0, 1               # 初始化 f(0), f(1)
    for i in range(2, n + 1): # 状态转移求取 f(2), f(3), ..., f(n) 
        a, b = b, a + b
    return b                  # 返回 f(n)
```

```Java []
// 求第 n 个斐波那契数
int fibonacci(int n) {
    if (n == 0) return 0;           // 若求 f(0) 则直接返回 0
    int a = 0, b = 1;               // 初始化 f(0), f(1)
    for (int i = 2; i <= n; i++) {  // 状态转移求取 f(2), f(3), ..., f(n) 
        int tmp = a;
        a = b;
        b = tmp + b;
    }
    return b;                       // 返回 f(n)
}
```

```C++ []
// 求第 n 个斐波那契数
int fibonacci(int n) {
    if (n == 0) return 0;           // 若求 f(0) 则直接返回 0
    int a = 0, b = 1;               // 初始化 f(0), f(1)
    for (int i = 2; i <= n; i++) {  // 状态转移求取 f(2), f(3), ..., f(n) 
        int tmp = a;
        a = b;
        b = tmp + b;
    }
    return b;                       // 返回 f(n)
}
```

### 示例小结

记忆化递归和动态规划的本质思想是一致的,是对斐波那契数列定义的不同表现形式:

- **记忆化递归 — 从顶至低:** 求 $f(n)$ 需要 $f(n - 1)$ 和 $f(n - 2)$ ; $\cdots$ ;求 $f(2)$ 需要 $f(1)$ 和 $f(0)$ ;而 $f(1)$ 和 $f(0)$ 已知;
- **动态规划 — 从底至顶:** 将已知 $f(0)$ 和 $f(1)$ 组合得到 $f(2)$ ;$\cdots$ ;将 $f(n - 2)$ 和 $f(n - 1)$ 组合得到 $f(n)$ ;

斐波那契数列问题不包含「最优子结构」,只需计算每个子问题的解,避免重复计算即可,并不需要从子问题组合中**选择最优组合**。接下来,本文借助「最高蛋糕售价方案」,介绍动态规划的**最优子结构**概念。

---

## 最优子结构示例:蛋糕最高售价

> 小力开了一家蛋糕店,并针对不同重量的蛋糕设定了不同售价,分别为:
>
> | 蛋糕重量 |  0   |  1   |  2   |  3   |  4   |  5   |  6   |
> | :------: | :--: | :--: | :--: | :--: | :--: | :--: | :--: |
> |   售价   |  0   |  2   |  3   |  6   |  7   |  11  |  15  |
>
> **问题:** 现给定一个重量为 $n$ 的蛋糕,问小力应该如何切分蛋糕,达到最高的蛋糕总售价。

设重量为 $n$ 蛋糕的售价为 $p(n)$ ,切分的最高总售价为 $f(n)$ 。

- **子问题:** $f(n)$ 的子问题包括 $f(0), f(1), f(2), \cdots, f(n - 1)$ ,分别代表重量为 $0, 1, 2, \cdots, n - 1$ 蛋糕的最高售价。 已知无蛋糕时 $f(0) = 0$ ,蛋糕重量为 1 时不可切分 $f(1) = p(1)$ ;
- **最优子结构:** 
  - **定义:** 如果一个问题最优解可以由其子问题最优解组合构成,那么称此问题具有最优子结构。
  - **对于本题:** 重量为 $n$ 的蛋糕的总售价可切分为 $n$ 种组合,即重量为 $0, 1, 2, ..., n - 1$ 蛋糕**最高售价**加上 $n, n - 1, n - 2, \cdots, 1$ 剩余重量蛋糕的**售价**;从这些组合中,售价最高的组合便是原问题的解 $f(n)$ ,这便是本题的最优子结构。

- **状态转移方程:** 找出最优子结构后,易构建出如下的状态转移方程。

$$
f(n) = \max_{0 \leq i < n} (f(i) + p(n - i))
$$

根据以上推导,本题也能使用「暴力递归」$\rightarrow$「记忆化递归」$\rightarrow$「动态规划」三种方法解决。

### 方法一:暴力递归

暴力递归解法的代码如下,其时间复杂度为指数级 $O(2^n)$ 。

```Python []
# 输入蛋糕价格列表 price_list ,求重量为 n 蛋糕的最高售价
def max_cake_price(n, price_list):
    if n <= 1: return price_list[n] # 蛋糕重量 <= 1 时直接返回
    f_n = 0
    for i in range(n):  # 从 n 种组合种选择最高售价的组合作为 f(n)
        f_n = max(f_n, max_cake_price(i, price_list) + price_list[n - i])
    return f_n          # 返回 f(n)

max_cake_price(4, [0, 2, 3, 6, 7, 11, 15])
```

```Java []
// 输入蛋糕价格列表 priceList ,求重量为 n 蛋糕的最高售价
int maxCakePrice(int n, int[] priceList) {
    if (n <= 1) return priceList[n]; // 蛋糕重量 <= 1 时直接返回
    int f_n = 0;
    for (int i = 0; i < n; i++)      // 从 n 种组合种选择最高售价的组合作为 f(n)
        f_n = Math.max(f_n, maxCakePrice(i, priceList) + priceList[n - i]);
    return f_n;                      // 返回 f(n)
}
```

```C++ []
// 输入蛋糕价格列表 priceList ,求重量为 n 蛋糕的最高售价
int maxCakePrice(int n, vector<int> priceList) {
    if (n <= 1) return priceList[n]; // 蛋糕重量 <= 1 时直接返回
    int f_n = 0;
    for (int i = 0; i < n; i++)      // 从 n 种组合种选择最高售价的组合作为 f(n)
        f_n = max(f_n, maxCakePrice(i, priceList) + priceList[n - i]);
    return f_n;                      // 返回 f(n)
}
```

如下图所示,为暴力递归求解 $f(4)$ 形成的多叉树。

![Picture4.png](https://pic.leetcode-cn.com/1635075778-AljQEJ-Picture4.png)

### 方法二:记忆化递归

观察发现,递归树中存在大量**重叠子问题**,可通过记忆化处理避免重复计算。记忆化递归的算法的时间复杂度为 $O(n^2)$ ,包括:

- $f(2)$ 至 $f(n)$ 共 $n - 1$ 个待计算子问题,使用 $O(n)$ 时间;
- 计算某 $f(i)$ 需遍历 $i - 1$ 种子问题组合,使用 $O(n)$ 时间;

```Python []
# 输入蛋糕价格列表 price_list ,求重量为 n 蛋糕的最高售价
def max_cake_price(n, price_list, dp):
    if n <= 1: return price_list[n] # 蛋糕重量 <= 1 时直接返回
    f_n = 0
    for i in range(n):  # 从 n 种组合种选择最高售价的组合作为 f(n)
        # 若 f(i) 以前已经计算过,则调取记录的解;否则,递归计算 f(i)
        f_i = dp[i] if dp[i] != 0 else max_cake_price(i, price_list, dp)
        f_n = max(f_n, f_i + price_list[n - i])
    dp[n] = f_n         # 记录 f(n) 至 dp 数组
    return f_n          # 返回 f(n)

def max_cake_price_memorized(n, price_list):
    dp = [0] * (n + 1)
    return max_cake_price(n, price_list, dp)
```

```Java []
// 输入蛋糕价格列表 priceList ,求重量为 n 蛋糕的最高售价
int maxCakePrice(int n, int[] priceList, int[] dp) {
    if (n <= 1) return priceList[n]; // 蛋糕重量 <= 1 时直接返回
    int f_n = 0;
    for (int i = 0; i < n; i++) {    // 从 n 种组合种选择最高售价的组合作为 f(n)
        int f_i = dp[i] != 0 ? dp[i] : maxCakePrice(i, priceList, dp);
        f_n = Math.max(f_n, f_i + priceList[n - i]);
    }
    dp[n] = f_n;                     // 记录 f(n) 至 dp 数组
    return f_n;                      // 返回 f(n)
}

int maxCakePriceMemorized(int n, int[] priceList) {
    int[] dp = new int[n + 1];
    return maxCakePrice(n, priceList, dp);
}
```

```C++ []
// 输入蛋糕价格列表 priceList ,求重量为 n 蛋糕的最高售价
int maxCakePrice(int n, vector<int> &priceList, vector<int> dp) {
    if (n <= 1) return priceList[n]; // 蛋糕重量 <= 1 时直接返回
    int f_n = 0;
    for (int i = 0; i < n; i++) {    // 从 n 种组合种选择最高售价的组合作为 f(n)
        int f_i = dp[i] != 0 ? dp[i] : maxCakePrice(i, priceList, dp);
        f_n = max(f_n, f_i + priceList[n - i]);
    }
    dp[n] = f_n;                     // 记录 f(n) 至 dp 数组
    return f_n;                      // 返回 f(n)
}

int maxCakePriceMemorized(int n, vector<int> priceList) {
    vector<int> dp(n + 1, 0);
    return maxCakePrice(n, priceList, dp);
}
```

如下图所示,为记忆化递归求解 $f(4)$ 形成的多叉树。观察得知,重叠子问题皆被**剪枝**。

![Picture5.png](https://pic.leetcode-cn.com/1635075778-tsDBrs-Picture5.png)

### 方法三:动态规划

相较于记忆化递归的从顶至底方法,易得动态规划的从底至顶方法,代码如下所示。

```Python []
# 输入蛋糕价格列表 price_list ,求重量为 n 蛋糕的最高售价
def max_cake_price(n, price_list):
    if n <= 1: return price_list[n] # 蛋糕重量 <= 1 时直接返回
    dp = [0] * (n + 1)              # 初始化 dp 列表
    for j in range(1, n + 1):       # 按顺序计算 f(1), f(2), ..., f(n)
        for i in range(j):          # 从 j 种组合种选择最高售价的组合作为 f(j)
            dp[j] = max(dp[j], dp[i] + price_list[j - i])
    return dp[n]
```

```Java []
// 输入蛋糕价格列表 priceList ,求重量为 n 蛋糕的最高售价
int maxCakePrice(int n, int[] priceList) {
    if (n <= 1) return priceList[n];  // 蛋糕重量 <= 1 时直接返回
    int[] dp = new int[n + 1];        // 初始化 dp 列表
    for (int j = 1; j <= n; j++) {    // 按顺序计算 f(1), f(2), ..., f(n)
        for (int i = 0; i < j; i++)   // 从 j 种组合种选择最高售价的组合作为 f(j)
            dp[j] = Math.max(dp[j], dp[i] + priceList[j - i]);
    }
    return dp[n];
}
```

```C++ []
// 输入蛋糕价格列表 priceList ,求重量为 n 蛋糕的最高售价
int maxCakePrice(int n, vector<int> priceList) {
    if (n <= 1) return priceList[n];  // 蛋糕重量 <= 1 时直接返回
    vector<int> dp(n + 1, 0);         // 初始化 dp 列表
    for (int j = 1; j <= n; j++) {    // 按顺序计算 f(1), f(2), ..., f(n)
        for (int i = 0; i < j; i++)   // 从 j 种组合种选择最高售价的组合作为 f(j)
            dp[j] = max(dp[j], dp[i] + priceList[j - i]);
    }
    return dp[n];
}
```

如下图所示,为动态规划求解 $f(4)$ 的迭代流程,其是转移方程 $f(n) = \max_{0 \leq i < n} (f(i) + p(n - i))$ 的体现。

![Picture6.png](https://pic.leetcode-cn.com/1635075778-PBtyyB-Picture6.png)

### 示例小结

本题同时包含「重叠子问题」和「最优子结构」,为动态规划的典型问题。动态规划通过填表避免了重复计算问题,并通过状态转移方程、初始状态实现对问题的迭代求解。

普遍来看,**求最值** 的问题一般都具有「重叠子问题」和「最优子结构」特点,因此此类问题往往适合用动态规划解决。

---

## 动态规划解题框架

若确定给定问题具有重叠子问题和最优子结构,那么就可以使用动态规划求解。总体上看,求解可分为四步:

1. **状态定义:** 构建问题最优解模型,包括问题**最优解的定义**、有哪些**计算解的自变量**;
2. **初始状态:** 确定**基础子问题的解**(即已知解),原问题和子问题的解都是以基础子问题的解为起始点,在迭代计算中得到的;
3. **转移方程:** 确定原问题的解与子问题的解之间的关系是什么,以及使用何种**选择规则**从子问题最优解组合中选出原问题最优解;
4. **返回值:** 确定应返回的问题的解是什么,即动态规划**在何处停止迭代**;

完成以上步骤后,便容易写出对应的解题代码。

### 示例:斐波那契数列

- 状态定义:一维 $dp$ 列表,设第 $i$ 个斐波那契数为 $dp[i]$ ;
- 初始状态:已知第 $0$ , $1$ 个斐波那契数分别为 $dp[0] = 0$ , $dp[1] = 1$ ;
- 转移方程:后一个数字等于前两个数字之和,即

$$
dp[i] = dp[i - 1] + dp[i - 2]
$$

- 返回值:需求取的第 $n$ 个斐波那契数 $dp[n]$ ;

### 示例:蛋糕最高售价

- 状态定义:一维 $dp$ 列表,设重量为 $i$ 蛋糕的售价为 $p(i)$ ,重量为 $i$ 蛋糕切分后的最高售价为 $dp[i]$ ;
- 初始状态:已知重量为 0 蛋糕的最高售价为 0 ,重量为 1 的蛋糕最高售价为 $p(1)$ ;
- 转移方程:$dp[n]$ 为 $n$ 种切分组合中的最高售价组合,即

$$
dp[n] = \max_{0 \leq i < n} (dp[i] + p(n - i))
$$

- 返回值:需求取的重量为 $n$ 的蛋糕最高售价 $dp[n]$ ;

---

## 例题练习

动态规划的问题种类多,难度跨度较大,需要充足练习、熟能生巧。以下给出若干典型例题,供读者巩固理解本文内容。

| 题目                                                                                            | 难度 | 描述                                                                    |
| ----------------------------------------------------------------------------------------------- | ---- | ----------------------------------------------------------------------- |
| [跳跃训练](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/57hyl5/)             | 简单 | 与本文的斐波那契数列例题等价                                            |
| [连续天数的最高销售额](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/59gq9c/) | 简单 | 求最大值问题,关键点在于状态定义                                        |
| [珠宝的最高价值](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/5vokvr/)       | 简单 | 求最大值问题,特点是其 $dp$ 列表是二维的                                |
| [统计结果概率](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/ozzl1r/)         | 中等 | 容易想到暴力枚举方法,难点为列出状态转移方程,且正向递推方法比较 tricky |
| [模糊搜索验证](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/9a1ypc/)         | 困难 | 状态定义容易得出,但状态转移方程复杂、选择规则分支多                    |


================================================
FILE: leetbook_ioa/docs/# 7.1 排序算法简介.md
================================================
# 排序算法简介

排序算法用作实现列表的排序,列表元素可以是整数,也可以是浮点数、字符串等其他数据类型。生活中有许多需要排序算法的场景,例如:

- **整数排序:** 对于一个整数数组,我们希望将所有数字从小到大排序;
- **字符串排序:** 对于一个姓名列表,我们希望将所有单词按照字符先后排序;
- **自定义排序:** 对于任意一个 **已定义比较规则** 的集合,我们希望将其按规则排序;

![Picture1.png](https://pic.leetcode-cn.com/1629483616-HHvvqY-Picture1.png)

同时,某些算法需要在排序算法的基础上使用(即在排序数组上运行),例如:

- **二分查找:** 根据数组已排序的特性,才能每轮确定排除两部分中的哪一部分;
- **双指针:** 例如合并两个排序链表,根据已排序特性,才能通过双指针移动在线性时间内将其合并为一个排序链表。

> 接下来,本文将从「常见排序算法」、「分类方法」、「时间与空间复杂度」三方面入手,简要介绍排序算法。「各排序算法详细介绍」请见后续专栏文章。

---

## 常见算法

常见排序算法包括「冒泡排序」、「插入排序」、「选择排序」、「快速排序」、「归并排序」、「堆排序」、「基数排序」、「桶排ss序」。如下图所示,为各排序算法的核心特性与时空复杂度总结。

![Picture2.png](https://pic.leetcode-cn.com/1629483637-tmENTT-Picture2.png)

如下图所示,为在 「随机乱序」、「接近有序」、「完全倒序」、「少数独特」四类输入数据下,各常见排序算法的排序过程。

![krahets-bubble-sort.gif](https://pic.leetcode-cn.com/1629482805-alxVCi-krahets-bubble-sort.gif)

![krahets-insertion-sort.gif](https://pic.leetcode-cn.com/1629482805-MMIXPp-krahets-insertion-sort.gif)

![krahets-selection-sort.gif](https://pic.leetcode-cn.com/1629482805-vdWamx-krahets-selection-sort.gif)

![krahets-quick-sort.gif](https://pic.leetcode-cn.com/1629482805-DYNZPE-krahets-quick-sort.gif)

![krahets-merge-sort.gif](https://pic.leetcode-cn.com/1629482805-IjWwSz-krahets-merge-sort.gif)

![krahets-heap-sort.gif](https://pic.leetcode-cn.com/1629482805-apljJY-krahets-heap-sort.gif)

---

## 分类方法

排序算法主要可根据 **稳定性** 、**就地性** 、**自适应性** 分类。理想的排序算法具有以下特性:

- 具有稳定性,即相等元素的相对位置不变化;
- 具有就地性,即不使用额外的辅助空间;
- 具有自适应性,即时间复杂度受元素分布影响;

特别地,任意排序算法都 **不同时具有以上所有特性** 。因此,排序算法的选型使用取决于具体的列表类型、元素数量、元素分布情况等应用场景特点。

### 稳定性:

根据 **相等元素** 在数组中的 **相对顺序** 是否被改变,排序算法可分为「稳定排序」和「非稳定排序」两类。

- 「稳定排序」在完成排序后,**不改变** 相等元素在数组中的相对顺序。例如:冒泡排序、插入排序、归并排序、基数排序、桶排序。
- 「非稳定排序」在完成排序后,相等素在数组中的相对位置 **可能被改变**。例如:选择排序、快速排序、堆排序。

> **何时需考虑排序算法的稳定性?**
>
> 数组排序中,由于元素皆为数字,因此稳定和非稳定排序皆可输出相同结果,此时无需考虑排序算法的稳定性。
>
> 非稳定排序会改变相等元素的相对次序,这在实际应用场景中可能是不能接受的。如以下代码所示,非稳定排序破坏了输入列表 `people` 按姓名排序的性质。
>
> ```Python
> # 人 = (姓名, 年龄) ,按姓名排序
> people = [
>     ('A', 19),
>     ('B', 18),
>     ('C', 21),
>     ('D', 19),
>     ('E', 23)
> ]
> 
> # 非稳定排序(按年龄)
> sort_by_age(people)
> 
> # 人 = (姓名, 年龄) ,按年龄排序
> people = [
>     ('B', 18),
>     ('D', 19), # ('D', 19) 和 ('A', 19) 的相对位置改变,输入时按姓名排序的性质丢失
>     ('A', 19),
>     ('C', 21),
>     ('E', 23)
> ]
> ```

### 就地性:

根据排序过程中 **是否使用额外内存(辅助数组)**,排序算法可分为「原地排序」和「异地排序」两类。一般地,由于不使用外部内存,原地排序相比非原地排序的执行效率更高。

- 「原地排序」不使用额外辅助数组,例如:冒泡排序、插入排序、选择排序、快速排序、堆排序。
- 「非原地排序」使用额外辅助数组,例如:归并排序、基数排序、桶排序。

### 自适应性:

根据算法 **时间复杂度** 是否 **受待排序数组的元素分布影响** ,排序算法可分为「自适应排序」和「非自适应排序」两类。

- 「自适应排序」的时间复杂度受元素分布影响;例如:冒泡排序、插入排序、快速排序、桶排序。
- 「非自适应排序」的时间复杂度恒定;例如:选择排序、归并排序、堆排序、基数排序。

### 是否基于比较:

比较类排序基于元素之间的 **比较算子**(小于、相等、大于)来决定元素的相对顺序;相对的,非比较排序则不基于比较算子实现。

- 「基于比较排序」基于元素之间的比较完成排序,例如:冒泡排序、插入排序、选择排序、快速排序、归并排序、堆排序。
- 「非基于比较排序」不基于元素之间的比较完成排序,例如:基数排序、桶排序。

> 基于比较的排序算法的平均时间复杂度最优为 $O(N \log N)$ ,而非比较排序算法可以达到线性级别的时间复杂度。

---

## 时空复杂度

总体上看,排序算法追求时间与空间复杂度最低。而即使某些排序算法的时间复杂度相等,但实际性能还受 **输入列表性质、元素数量、元素分布等** 等因素影响。

> 设输入列表元素数量为 $N$ ,常见排序算法的「时间复杂度」和「空间复杂度」如下图所示。

|   算法   |      最佳时间       |      平均时间      |   最差时间    |  最差空间   |
| :------: | :-----------------: | :----------------: | :-----------: | :---------: |
| 冒泡排序 |     $\Omega(N)$     |   $\Theta(N^2)$    |   $O(N^2)$    |   $O(1)$    |
| 插入排序 |     $\Omega(N)$     |   $\Theta(N^2)$    |   $O(N^2)$    |   $O(1)$    |
| 选择排序 |    $\Omega(N^2)$    |   $\Theta(N^2)$    |   $O(N^2)$    |   $O(1)$    |
| 快速排序 | $\Omega(N \log N )$ | $\Theta(N \log N)$ |   $O(N^2)$    | $O(\log N)$ |
| 归并排序 | $\Omega(N \log N)$  | $\Theta(N \log N)$ | $O(N \log N)$ |   $O(N)$    |
|  堆排序  | $\Omega(N \log N)$  | $\Theta(N \log N)$ | $O(N \log N)$ |   $O(1)$    |
| 基数排序 |    $\Omega(Nk)$     |    $\Theta(Nk)$    |    $O(Nk)$    | $O(N + k)$  |
|  桶排序  |   $\Omega(N + k)$   |  $\Theta(N + k)$   |   $O(N^2)$    |   $O(N)$    |

对于上表,需要特别注意:

- 「基数排序」适用于正整数、字符串、特定格式的浮点数排序,$k$ 为最大数字的位数;「桶排序」中 $k$ 为桶的数量。
- 普通「冒泡排序」的最佳时间复杂度为 $O(N^2)$ ,通过增加标志位实现 **提前返回** ,可以将最佳时间复杂度降低至 $O(N)$ 。
- 在输入列表完全倒序下,普通「快速排序」的空间复杂度劣化至 $O(N)$ ,通过代码优化 **尾递归优化** 保持算法递归较短子数组,可以将最差递归深度降低至 $\log N$ 。
- 普通「快速排序」总以最左或最右元素为基准数,因此在输入列表有序或倒序下,时间复杂度劣化至 $O(N^2)$ ;通过 **随机选择基准数** ,可极大减少此类最差情况发生,尽可能地保持 $O(N \log N)$ 的时间复杂度。
- 若输入列表是数组,则归并排序的空间复杂度为 $O(N)$ ;而若排序 **链表** ,则「归并排序」不需要借助额外辅助空间,空间复杂度可以降低至 $O(1)$ 。


================================================
FILE: leetbook_ioa/docs/# 7.2 冒泡排序.md
================================================
# 冒泡排序

冒泡排序是最基础的排序算法,由于其直观性,经常作为首个介绍的排序算法。其原理为:

- **内循环:** 使用相邻双指针 `j` , `j + 1` 从左至右遍历,依次比较相邻元素大小,若左元素大于右元素则将它们交换;遍历完成时,**最大元素会被交换至数组最右边** 。
- **外循环:** 不断重复「内循环」,每轮将当前最大元素交换至 **剩余未排序数组最右边** ,直至所有元素都被交换至正确位置时结束。

如下图所示,首轮「内循环」后,数组最大元素已被交换至数组最右边;接下来,只需要完成数组剩余 $N - 1$ 个元素的排序即可(设数组元素数量为 $N$ )。同理,对剩余 $N - 1$ 个元素执行「内循环」,可将第二大元素交换至剩余数组最右端,以此类推……

<![Picture41.png](https://pic.leetcode-cn.com/1628617783-TRYTrM-Picture41.png),![Picture32.png](https://pic.leetcode-cn.com/1628617558-qhIrsx-Picture32.png),![Picture33.png](https://pic.leetcode-cn.com/1628617558-ittLRv-Picture33.png),![Picture34.png](https://pic.leetcode-cn.com/1628617558-BksXHQ-Picture34.png),![Picture35.png](https://pic.leetcode-cn.com/1628617558-KwAJiL-Picture35.png),![Picture36.png](https://pic.leetcode-cn.com/1628617558-DeEUpW-Picture36.png),![Picture37.png](https://pic.leetcode-cn.com/1628617558-zFJvRA-Picture37.png),![Picture38.png](https://pic.leetcode-cn.com/1628617558-aIxOzm-Picture38.png),![Picture39.png](https://pic.leetcode-cn.com/1628617558-FPPYAH-Picture39.png),![Picture40.png](https://pic.leetcode-cn.com/1628617558-ZGLsvZ-Picture40.png)>

如下图所示,冒泡排序的「外循环」共 $N - 1$ 轮,每轮「内循环」都将当前最大元素交换至数组最右边,从而完成对整个数组的排序。

![Picture1.png](https://pic.leetcode-cn.com/1628616643-PvqWBM-Picture1.png){:width=550}

如下图所示,为示例数组 `nums = [4, 1, 3, 1, 5, 2]` 的冒泡排序算法运行过程。

<![Picture2.png](https://pic.leetcode-cn.com/1628616643-WpzPBX-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1628616643-TtwECa-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1628616643-sCpIbT-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1628616643-dwjmfo-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1628616643-UqsBRU-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1628616643-zuIEGr-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1628616643-ZHOCyb-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1628616643-MrkmoX-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1628616643-tGgDta-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/1628616643-wapMMy-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/1628616643-hQjyzQ-Picture12.png),![Picture13.png](https://pic.leetcode-cn.com/1628616643-UNVHcU-Picture13.png),![Picture14.png](https://pic.leetcode-cn.com/1628616643-bXSWDP-Picture14.png),![Picture15.png](https://pic.leetcode-cn.com/1628616643-UPLFgg-Picture15.png),![Picture16.png](https://pic.leetcode-cn.com/1628616643-aKpsRI-Picture16.png),![Picture17.png](https://pic.leetcode-cn.com/1628616643-GmDQBC-Picture17.png),![Picture18.png](https://pic.leetcode-cn.com/1628616643-iHXhIo-Picture18.png),![Picture19.png](https://pic.leetcode-cn.com/1628616643-kXamhB-Picture19.png),![Picture20.png](https://pic.leetcode-cn.com/1628616643-wiIbgD-Picture20.png),![Picture21.png](https://pic.leetcode-cn.com/1628616643-TUaEPM-Picture21.png),![Picture22.png](https://pic.leetcode-cn.com/1628616643-ovdBtR-Picture22.png),![Picture23.png](https://pic.leetcode-cn.com/1628616643-lotSjf-Picture23.png),![Picture24.png](https://pic.leetcode-cn.com/1628616643-FCYmSX-Picture24.png),![Picture25.png](https://pic.leetcode-cn.com/1628616643-gdaGaw-Picture25.png),![Picture26.png](https://pic.leetcode-cn.com/1628616643-iWnCmb-Picture26.png),![Picture27.png](https://pic.leetcode-cn.com/1628616643-YPjzsI-Picture27.png),![Picture28.png](https://pic.leetcode-cn.com/1628616643-AFSnYn-Picture28.png),![Picture29.png](https://pic.leetcode-cn.com/1628616643-yCLeAx-Picture29.png),![Picture30.png](https://pic.leetcode-cn.com/1628616643-HikxcK-Picture30.png)>

## 代码

```Python []
def bubble_sort(nums):
    N = len(nums)
    for i in range(N - 1):           # 外循环
        for j in range(N - i - 1):   # 内循环
            if nums[j] > nums[j + 1]:
                # 交换 nums[j], nums[j + 1]
                nums[j], nums[j + 1] = nums[j + 1], nums[j]
```

```Java []
void bubbleSort(int[] nums) {
    int N = nums.length;
    for (int i = 0; i < N - 1; i++) {          // 外循环
        for (int j = 0; j < N - i - 1; j++) {  // 内循环
            if (nums[j] > nums[j + 1]) {
                // 交换 nums[j], nums[j + 1]
                int tmp = nums[j];
                nums[j] = nums[j + 1];
                nums[j + 1] = tmp;
            }
        }
    }
}
```

```C++ []
void bubbleSort(vector<int> &nums) {
    int N = nums.size();
    for (int i = 0; i < N - 1; i++) {          // 外循环
        for (int j = 0; j < N - i - 1; j++) {  // 内循环
            if (nums[j] > nums[j + 1]) {
                // 交换 nums[j], nums[j + 1]
                swap(nums[j], nums[j + 1]);
            }
        }
    }
}
```

## 算法特性

- **时间复杂度 $O(N^2)$ :**
  - **最佳 $\Omega(N)$ :** 普通冒泡排序的时间复杂度恒为 $O(N^2)$ ,对于近似排序数组,通过加入标志位可实现提前返回(详情请见下文)。
  - **平均与最差 $O(N^2)$ :**「外循环」共 $N - 1$ 轮,使用 $O(N)$ 时间;每轮「内循环」分别遍历 $N - 1$ , $N - 2$ , $\cdots$ , $2$ , $1$ 次,平均 $\frac{N}{2}$ 次,使用 $O(\frac{N}{2}) = O(N)$ 时间;因此,总体时间复杂度为 $O(N^2)$  。
- **空间复杂度 $O(1)$ :** 只需原地交换元素,使用常数大小的额外空间。
- 冒泡排序是通过不断 **交换元素** 实现排序(交换 2 个元素需要 3 次赋值操作),因此速度较慢;
- **原地:** 指针变量仅使用常数大小额外空间,空间复杂度为 $O(1)$ ;
- **稳定:** 元素值相同时不交换,因此不会改变相同元素的相对位置;
- **自适应:** 通过增加一个标志位 `flag` ,若某轮内循环未执行任何交换操作时,说明已经完成排序,因此直接返回。此优化使冒泡排序的最优时间复杂度达到 $O(N)$(当输入数组已排序时);

## 标志位优化

> 普通冒泡排序的时间复杂度恒为 $O(N^2)$​ ,与输入数组的元素分布无关。

通过增加一个标志位 `flag` ,若在某轮「内循环」中未执行任何交换操作,则说明数组已经完成排序,直接返回结果即可。

优化后的冒泡排序的最差和平均时间复杂度仍为 $O(N^2)$ ;在输入数组 **已排序** 时,达到 **最佳时间复杂度** $\Omega(N)$ 。 

```Python []
def bubble_sort(nums):
    N = len(nums)
    for i in range(N - 1):
        flag = False         #  初始化标志位
        for j in range(N - i - 1):
            if nums[j] > nums[j + 1]:
                nums[j], nums[j + 1] = nums[j + 1], nums[j]
                flag = True  # 记录交换元素
        if not flag: break   # 内循环未交换任何元素,则跳出
```

```Java []
void bubbleSort(int[] nums) {
    int N = nums.length;
    for (int i = 0; i < N - 1; i++) {
        boolean flag = false; // 初始化标志位
        for (int j = 0; j < N - i - 1; j++) {
            if (nums[j] > nums[j + 1]) {
                int tmp = nums[j];
                nums[j] = nums[j + 1];
                nums[j + 1] = tmp;
                flag = true;  // 记录交换元素
            }
        }
        if (!flag) break;     // 内循环未交换任何元素,则跳出
    }
}
```

```C++ []
void bubbleSort(vector<int> &nums) {
    int N = nums.size();
    for (int i = 0; i < N - 1; i++) {
        bool flag = false;   // 初始化标志位
        for (int j = 0; j < N - i - 1; j++) {
            if (nums[j] > nums[j + 1]) {
                swap(nums[j], nums[j + 1]);
                flag = true; // 记录交换元素
            }
        }
        if (!flag) break;    // 内循环未交换任何元素,则跳出
    }
}
```


================================================
FILE: leetbook_ioa/docs/# 7.3 快速排序.md
================================================
# 快速排序

快速排序算法有两个核心点,分别为 **哨兵划分** 和 **递归** 。

**哨兵划分**:以数组某个元素(一般选取首元素)为 **基准数** ,将所有小于基准数的元素移动至其左边,大于基准数的元素移动至其右边。

> 下图展示了哨兵划分操作流程。经过一轮 **哨兵划分** ,可将数组排序问题拆分为 **两个较短数组的排序问题** (本文称之为左(右)子数组)。

<![Picture2.png](https://pic.leetcode-cn.com/1612615167-etrYaH-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1612615167-PHsLgY-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1612615167-aMCCrd-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1612615167-smzuGu-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1612615167-WXDRIU-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1612615167-lWmBlA-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1612615167-ghPekO-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1612615167-azMHYj-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1623073951-BKkDwO-Picture10.png)>

**递归**:对 **左子数组** 和 **右子数组** 分别递归执行 **哨兵划分**,直至子数组长度为 1 时终止递归,即可完成对整个数组的排序。

> 下图展示了数组 `[2,4,1,0,3,5]` 的快速排序流程。观察发现,快速排序和 **二分法** 的原理类似,都是以 $\log$ 时间复杂度实现搜索区间缩小。

![Picture1.png](https://pic.leetcode-cn.com/1612615552-rifQwI-Picture1.png){:width=550}

## 代码

```Python []
def quick_sort(nums, l, r):
    # 子数组长度为 1 时终止递归
    if l >= r: return
    # 哨兵划分操作
    i = partition(nums, l, r)
    # 递归左(右)子数组执行哨兵划分
    quick_sort(nums, l, i - 1)
    quick_sort(nums, i + 1, r)
    
def partition(nums, l, r):
    # 以 nums[l] 作为基准数
    i, j = l, r
    while i < j:
        while i < j and nums[j] >= nums[l]: j -= 1
        while i < j and nums[i] <= nums[l]: i += 1
        nums[i], nums[j] = nums[j], nums[i]
    nums[l], nums[i] = nums[i], nums[l]
    return i

# 调用
nums = [3, 4, 1, 5, 2]
quick_sort(nums, 0, len(nums) - 1)
```

```Java []
void quickSort(int[] nums, int l, int r) {
    // 子数组长度为 1 时终止递归
    if (l >= r) return;
    // 哨兵划分操作
    int i = partition(nums, l, r);
    // 递归左(右)子数组执行哨兵划分
    quickSort(nums, l, i - 1);
    quickSort(nums, i + 1, r);
}

int partition(int[] nums, int l, int r) {
    // 以 nums[l] 作为基准数
    int i = l, j = r;
    while (i < j) {
        while (i < j && nums[j] >= nums[l]) j--;
        while (i < j && nums[i] <= nums[l]) i++;
        swap(nums, i, j);
    }
    swap(nums, i, l);
    return i;
}

void swap(int[] nums, int i, int j) {
    // 交换 nums[i] 和 nums[j]
    int tmp = nums[i];
    nums[i] = nums[j];
    nums[j] = tmp;
}

// 调用
int[] nums = { 4, 1, 3, 2, 5 };
quickSort(nums, 0, nums.length - 1);
```

```C++ []
int partition(vector<int>& nums, int l, int r) {
    // 以 nums[l] 作为基准数
    int i = l, j = r;
    while (i < j) {
        while (i < j && nums[j] >= nums[l]) j--;
        while (i < j && nums[i] <= nums[l]) i++;
        swap(nums[i], nums[j]);
    }
    swap(nums[i], nums[l]);
    return i;
}

void quickSort(vector<int>& nums, int l, int r) {
    // 子数组长度为 1 时终止递归
    if (l >= r) return;
    // 哨兵划分操作
    int i = partition(nums, l, r);
    // 递归左(右)子数组执行哨兵划分
    quickSort(nums, l, i - 1);
    quickSort(nums, i + 1, r);
}

// 调用
vector<int> nums = { 4, 1, 3, 2, 5, 1 };
quickSort(nums, 0, nums.size() - 1);
```

## 算法特性

- **时间复杂度:**
  - **最佳 $\Omega(N \log N )$ :** 最佳情况下, 每轮哨兵划分操作将数组划分为等长度的两个子数组;哨兵划分操作为线性时间复杂度 $O(N)$ ;递归轮数共 $O(\log N)$ 。
  - **平均 $\Theta(N \log N)$ :** 对于随机输入数组,哨兵划分操作的递归轮数也为 $O(\log N)$ 。
  - **最差 $O(N^2)$ :** 对于某些特殊输入数组,每轮哨兵划分操作都将长度为 $N$ 的数组划分为长度为 $1$ 和 $N - 1$ 的两个子数组,此时递归轮数达到 $N$ 。
  > 通过 「随机选择基准数」优化,可尽可能避免出现最差情况,详情请见下文。
- **空间复杂度 $O(N)$ :** 快速排序的递归深度最好与平均皆为 $\log N$ ;输入数组完全倒序下,达到最差递归深度 $N$ 。
  > 通过「尾递归」优化,可将最差空间复杂度降低至 $O(\log N)$ ,详情请见下文。
- 虽然平均时间复杂度与「归并排序」和「堆排序」一致,但在实际使用中快速排序 **效率更高** ,这是因为:
  - **最差情况稀疏性:** 虽然快速排序的最差时间复杂度为 $O(N^2)$ ,差于归并排序和堆排序,但统计意义上看,这种情况出现的机率很低。大部分情况下,快速排序以 $O(N \log N)$ 复杂度运行。
  - **缓存使用效率高:** 哨兵划分操作时,将整个子数组加载入缓存中,访问元素效率很高;堆排序需要跳跃式访问元素,因此不具有此特性。
  - **常数系数低:** 在提及的三种算法中,快速排序的 **比较**、**赋值**、**交换** 三种操作的综合耗时最低(类似于插入排序快于冒泡排序的原理)。
- **原地:** 不用借助辅助数组的额外空间,递归仅使用 $O(\log N)$ 大小的栈帧空间。
- **非稳定:** 哨兵划分操作可能改变相等元素的相对顺序。
- **自适应:** 对于极少输入数据,每轮哨兵划分操作都将长度为 $N$ 的数组划分为长度 $1$ 和 $N - 1$ 两个子数组,此时时间复杂度劣化至 $O(N^2)$ 。

## 算法优化

快速排序的常见优化手段有「尾递归」和「随机基准数」两种。

### 尾递归:

由于普通快速排序每轮选取「子数组最左元素」作为「基准数」,因此在输入数组 **完全倒序** 时, `partition()` 的递归深度会达到 $N$ ,即 **最差空间复杂度** 为 $O(N)$ 。

每轮递归时,仅对 **较短的子数组** 执行哨兵划分 `partition()` ,就可将最差的递归深度控制在 $O(\log N)$ (每轮递归的子数组长度都 $\leq$ 当前数组长度 $/ 2$ ),即实现最差空间复杂度 $O(\log N)$ 。

> 代码仅需修改 `quick_sort()` 方法,其余方法不变,在此省略。

```Python []
def quick_sort(nums, l, r):
    # 子数组长度为 1 时终止递归
    while l < r:
        # 哨兵划分操作
        i = partition(nums, l, r)
        # 仅递归至较短子数组,控制递归深度
        if i - l < r - i:
            quick_sort(nums, l, i - 1)
            l = i + 1
        else:
            quick_sort(nums, i + 1, r)
            r = i - 1
```

```Java []
void quickSort(int[] nums, int l, int r) {
    // 子数组长度为 1 时终止递归
    while (l < r) {
        // 哨兵划分操作
        int i = partition(nums, l, r);
        // 仅递归至较短子数组,控制递归深度
        if (i - l < r - i) {
            quickSort(nums, l, i - 1);
            l = i + 1;
        } else {
            quickSort(nums, i + 1, r);
            r = i - 1;
        }
    }
}
```

```C++ []
void quickSort(vector<int>& nums, int l, int r) {
    // 子数组长度为 1 时终止递归
    while (l < r) {
        // 哨兵划分操作
        int i = partition(nums, l, r);
        // 仅递归至较短子数组,控制递归深度
        if (i - l < r - i) {
            quickSort(nums, l, i - 1);
            l = i + 1;
        } else {
            quickSort(nums, i + 1, r);
            r = i - 1;
        }
    }
}
```

### 随机基准数:

同样地,由于快速排序每轮选取「子数组最左元素」作为「基准数」,因此在输入数组 **完全有序** 或 **完全倒序** 时, `partition()` 每轮只划分一个元素,达到最差时间复杂度 $O(N^2)$ 。

因此,可使用 **随机函数** ,每轮在子数组中随机选择一个元素作为基准数,这样就可以极大概率避免以上劣化情况。

值得注意的是,由于仍然可能出现最差情况,因此快速排序的最差时间复杂度仍为 $O(N^2)$ 。

> 代码仅需修改 `partition()` 方法,其余方法不变,在此省略。

```Python []
def partition(nums, l, r):
    # 在闭区间 [l, r] 随机选取任意索引,并与 nums[l] 交换
    ra = random.randrange(l, r + 1)
    nums[l], nums[ra] = nums[ra], nums[l]
    # 以 nums[l] 作为基准数
    i, j = l, r
    while i < j:
        while i < j and nums[j] >= nums[l]: j -= 1
        while i < j and nums[i] <= nums[l]: i += 1
        nums[i], nums[j] = nums[j], nums[i]
    nums[l], nums[i] = nums[i], nums[l]
    return i
```

```Java []
int partition(int[] nums, int l, int r) {
    // 在闭区间 [l, r] 随机选取任意索引,并与 nums[l] 交换
    int ra = (int)(l + Math.random() * (r - l + 1));
    swap(nums, l, ra);
    // 以 nums[l] 作为基准数
    int i = l, j = r;
    while (i < j) {
        while (i < j && nums[j] >= nums[l]) j--;
        while (i < j && nums[i] <= nums[l]) i++;
        swap(nums, i, j);
    }
    swap(nums, i, l);
    return i;
}
```

```C++ []
int partition(vector<int>& nums, int l, int r) {
    // 在闭区间 [l, r] 随机选取任意索引,并与 nums[l] 交换
    int ra = l + rand() % (r - l + 1);
    swap(nums[l], nums[ra]);
    // 以 nums[l] 作为基准数
    int i = l, j = r;
    while (i < j) {
        while (i < j && nums[j] >= nums[l]) j--;
        while (i < j && nums[i] <= nums[l]) i++;
        swap(nums[i], nums[j]);
    }
    swap(nums[i], nums[l]);
    return i;
}
```


================================================
FILE: leetbook_ioa/docs/# 7.4 归并排序.md
================================================
# 归并排序

归并排序体现了 “分而治之” 的算法思想,具体为:

- **「分」:** 不断将数组从 **中点位置** 划分开,将原数组的排序问题转化为子数组的排序问题;
- **「治」:** 划分到子数组长度为 1 时,开始向上合并,不断将 **左右两个较短排序数组** 合并为 **一个较长排序数组**,直至合并至原数组时完成排序;

> 如下图所示,为数组 `[7,3,2,6,0,1,5,4]` 的归并排序过程。

![Picture1.png](https://pic.leetcode-cn.com/1632675739-CNHaOu-Picture1.png){:width=500}

## 算法流程

1. **递归划分:**
   1. 计算数组中点 $m$ ,递归划分左子数组 `merge_sort(l, m)` 和右子数组 `merge_sort(m + 1, r)` ;
   2. 当 $l \geq r$  时,代表子数组长度为 1 或 0 ,此时 **终止划分** ,开始合并;

2. **合并子数组:**
   1. 暂存数组 $nums$ 闭区间 $[l, r]$ 内的元素至辅助数组 $tmp$ ;
   2. **循环合并:** 设置双指针 $i$ , $j$ 分别指向 $tmp$ 的左 / 右子数组的首元素;
      > **注意:** $nums$ 子数组的左边界、中点、右边界分别为 $l$ , $m$ , $r$ ,而辅助数组 $tmp$ 中的对应索引为 $0$ , $m - l$ , $r - l$ ;
      - **当 $i == m - l + 1$ 时:** 代表左子数组已合并完,因此添加右子数组元素 $tmp[j]$ ,并执行 $j = j + 1$ ;
      - **否则,当 $j == r - l + 1$ 时:** 代表右子数组已合并完,因此添加左子数组元素 $tmp[i]$ ,并执行 $i = i + 1$ ;
      - **否则,当 $tmp[i] \leq tmp[j]$ 时:** 添加左子数组元素 $tmp[i]$ ,并执行 $i = i + 1$ ;
      - **否则(即当 $tmp[i] > tmp[j]$ 时):** 添加右子数组元素 $tmp[j]$ ,并执行 $j = j + 1$ ;

> 如下动图所示,为数组 `[7,3,2,6]` 的归并排序过程。

<![Picture2.png](https://pic.leetcode-cn.com/1632675858-cJeqUR-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1632675727-PPgpZZ-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1632675727-UVoxsJ-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1632675727-dfjbJY-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1632675727-UJRCIE-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1632675727-YDhFvj-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1632675727-hjJlql-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1632675727-FYTodg-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1632675727-dAGnBR-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/1632675727-VVDNmq-Picture11.png)>

## 代码

为简化代码,「当 $j = r + 1$ 时」 与 「当 $tmp[i] \leq tmp[j]$ 时」 两判断项可合并。

```Python []
def merge_sort(nums, l, r):
    # 终止条件
    if l >= r: return
    # 递归划分数组
    m = (l + r) // 2
    merge_sort(nums, l, m)
    merge_sort(nums, m + 1, r)
    # 合并子数组
    tmp = nums[l:r + 1]       # 暂存需合并区间元素
    i, j = 0, m - l + 1       # 两指针分别指向左/右子数组的首个元素
    for k in range(l, r + 1): # 遍历合并左/右子数组
        if i == m - l + 1:
            nums[k] = tmp[j]
            j += 1
        elif j == r - l + 1 or tmp[i] <= tmp[j]:
            nums[k] = tmp[i]
            i += 1
        else:
            nums[k] = tmp[j]
            j += 1

# 调用
nums = [3, 4, 1, 5, 2, 1]
merge_sort(0, len(nums) - 1)
```

```Java []
void mergeSort(int[] nums, int l, int r) {
    // 终止条件
    if (l >= r) return;
    // 递归划分
    int m = (l + r) / 2;
    mergeSort(nums, l, m);
    mergeSort(nums, m + 1, r);
    // 合并子数组
    int[] tmp = new int[r - l + 1]; // 暂存需合并区间元素
    for (int k = l; k <= r; k++)
        tmp[k - l] = nums[k];
    int i = 0, j = m - l + 1;       // 两指针分别指向左/右子数组的首个元素
    for (int k = l; k <= r; k++) {  // 遍历合并左/右子数组
        if (i == m - l + 1)
            nums[k] = tmp[j++];
        else if (j == r - l + 1 || tmp[i] <= tmp[j])
            nums[k] = tmp[i++];
        else {
            nums[k] = tmp[j++];
        }
    }
}

// 调用
int[] nums = { 3, 4, 1, 5, 2, 1 };
mergeSort(nums, 0, len(nums) - 1);
```

```C++ []
void mergeSort(vector<int>& nums, int l, int r) {
    // 终止条件
    if (l >= r) return;
    // 递归划分
    int m = (l + r) / 2;
    mergeSort(nums, l, m);
    mergeSort(nums, m + 1, r);
    // 合并阶段
    int tmp[r - l + 1];             // 暂存需合并区间元素
    for (int k = l; k <= r; k++)
        tmp[k - l] = nums[k];
    int i = 0, j = m - l + 1;       // 两指针分别指向左/右子数组的首个元素
    for (int k = l; k <= r; k++) {  // 遍历合并左/右子数组
        if (i == m - l + 1)
            nums[k] = tmp[j++];
        else if (j == r - l + 1 || tmp[i] <= tmp[j])
            nums[k] = tmp[i++];
        else {
            nums[k] = tmp[j++];
        }
    }
}

// 调用
vector<int> nums = { 4, 1, 3, 2, 5, 1 };
mergeSort(nums, 0, nums.size() - 1);
```

## 算法特性

- **时间复杂度:** 最佳 $\Omega(N \log N )$ ,平均 $\Theta(N \log N)$ ,最差 $O(N \log N)$ 。
- **空间复杂度 $O(N)$ :** 合并过程中需要借助辅助数组 $tmp$ ,使用 $O(N)$ 大小的额外空间;划分的递归深度为 $\log N$ ,使用 $O(\log N)$ 大小的栈帧空间。
- 若输入数据是 **链表** ,则归并排序的空间复杂度可被优化至 $O(1)$ ,这是因为:
  - 通过应用「双指针法」,可在 $O(1)$ 空间下完成两个排序链表的合并,省去辅助数组 $tmp$ 使用的额外空间;
  - 通过使用「迭代」代替「递归划分」,可省去递归使用的栈帧空间;
  > 详情请参考:[148. 排序链表](https://leetcode-cn.com/problems/sort-list/solution/sort-list-gui-bing-pai-xu-lian-biao-by-jyd/)
- **非原地:** 辅助数组 $tmp$ 需要使用额外空间。
- **稳定:** 归并排序不改变相等元素的相对顺序。
- **非自适应:** 对于任意输入数据,归并排序的时间复杂度皆相同。


================================================
FILE: leetbook_ioa/docs/LCR 120. 寻找文件副本.md
================================================
## 方法一:哈希表

利用数据结构特点,容易想到使用哈希表(Set)记录数组的各个数字,当查找到重复数字则直接返回。

### 算法流程:

1. 初始化: 新建 HashSet ,记为 $hmap$ ;
2. 遍历数组 $documents$ 中的每个数字 $doc$ :
   1. 当 $doc$ 在 $hmap$ 中,说明重复,直接返回 $doc$ ;
   2. 将 $doc$ 添加至 $hmap$ 中;
3. 返回 $-1$ 。本题中一定有重复数字,因此这里返回多少都可以。

> 下图中的 `nums` 对应本题的 `documents` 。

<![Picture1.png](https://pic.leetcode-cn.com/b73933d9cafbbed2d3b3cc3353f2ef7e9af2614d623c7e87f7bc6d8fbaf27f40-Picture1.png),![Picture2.png](https://pic.leetcode-cn.com/e97aa100bcab08166e04da36bc9f3537d2cde0f7cc4e027e12b4765fd3c0f042-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/3e40c3d2c2d5b36522d7884c685029720dffb787d4c2dd12b70596d4cedf8120-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/b5a77688e2c989573786fa7b6b1b30026f9ffe0070d0b1760cf8931573545462-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/29528f65ea95425b032c3039a8c80d9e2ae4f9cac89eef3a8c19bfc668abb546-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/23d093dbd8fd248e9075fbee511483adaef103fb072d18eec3a8d3d00c870512-Picture6.png)>

### 代码:

```Python []
class Solution:
    def findRepeatDocument(self, documents: List[int]) -> int:
        hmap = set()
        for doc in documents:
            if doc in hmap: return doc
            hmap.add(doc)
        return -1
```

```Java []
class Solution {
    public int findRepeatDocument(int[] documents) {
        Set<Integer> hmap = new HashSet<>();
        for(int doc : documents) {
            if(hmap.contains(doc)) return doc;
            hmap.add(doc);
        }
        return -1;
    }
}
```

```C++ []
class Solution {
public:
    int findRepeatDocument(vector<int>& documents) {
        unordered_map<int, bool> map;
        for(int doc : documents) {
            if(map[doc]) return doc;
            map[doc] = true;
        }
        return -1;
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(N)$ :** 遍历数组使用 $O(N)$ ,HashSet 添加与查找元素皆为 $O(1)$ 。
- **空间复杂度 $O(N)$ :** HashSet 占用 $O(N)$ 大小的额外空间。

## 方法二:原地交换

题目说明尚未被充分使用,即 `在一个长度为 n 的数组 documents 里的所有数字都在 0 ~ n-1 的范围内` 。 此说明含义:数组元素的 **索引** 和 **值** 是 **一对多** 的关系。
因此,可遍历数组并通过交换操作,使元素的 **索引** 与 **值** 一一对应(即 $documents[i] = i$ )。因而,就能通过索引映射对应的值,起到与字典等价的作用。

![Picture0.png](https://pic.leetcode-cn.com/1618146573-bOieFQ-Picture0.png){:align=center width=500}

遍历中,第一次遇到数字 $x$ 时,将其交换至索引 $x$ 处;而当第二次遇到数字 $x$ 时,一定有 $documents[x] = x$ ,此时即可得到一组重复数字。

### 算法流程:

1. 遍历数组 $documents$ ,设索引初始值为 $i = 0$ :
   1. **若 $documents[i] = i$ :** 说明此数字已在对应索引位置,无需交换,因此跳过;
   2. **若 $documents[documents[i]] = documents[i]$ :** 代表索引 $documents[i]$ 处和索引 $i$ 处的元素值都为 $documents[i]$ ,即找到一组重复值,返回此值 $documents[i]$ ;
   3. **否则:** 交换索引为 $i$ 和 $documents[i]$ 的元素值,将此数字交换至对应索引位置。

2. 若遍历完毕尚未返回,则返回 $-1$ 。

<![Picture7.png](https://pic.leetcode-cn.com/45a6303cd3ab50036a99ae89e2b0458f9b4885bb9d089997dfc0e5851a6a6300-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/58905a586575382e51096a5ce3e9e098ef8df215723174b4ac1d042e10a95c01-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/68a992b40bd5781a388c4fe811cd7a7c9b8dbb659089ed7473605323df76d241-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/98fd49b23dbb73cba6c551faaabfaaf5b3bbaed5f50f6c11ac42496bdfd2eba1-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/e6089e2d686fb1e76feb4f065ed14f7d2c02eadcdbfb6d4e2e9b6843f64914c3-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/80f2f1df8c43f56d63d09118fcb49c6c9d834aa743b01e9f8fd2b1ac9ce85403-Picture12.png),![Picture13.png](https://pic.leetcode-cn.com/64c97efd298d010e91b89eb18c7eb961538d6c1da400495c328dd92de3b47648-Picture13.png),![Picture14.png](https://pic.leetcode-cn.com/eaf0db1a4b0e0869d29fa789a234888d45dfffc5d1d13c5fb1c237a0b1bc5389-Picture14.png),![Picture15.png](https://pic.leetcode-cn.com/82ea50d1915609e368839cac6d4e0e615ff8297138aff645d0c2aba79e6a7b7e-Picture15.png)>

### 代码:

Python 中,$a, b = c, d$ 操作的原理是先暂存元组 $(c, d)$ ,然后 “按左右顺序” 赋值给 a 和 b 。
因此,若写为 $documents[i], documents[documents[i]] = documents[documents[i]], documents[i]$ ,则 $documents[i]$ 会先被赋值,之后 $documents[documents[i]]$ 指向的元素则会出错。

```Python []
class Solution:
    def findRepeatDocument(self, documents: List[int]) -> int:
        i = 0
        while i < len(documents):
            if documents[i] == i:
                i += 1
                continue
            if documents[documents[i]] == documents[i]: return documents[i]
            documents[documents[i]], documents[i] = documents[i], documents[documents[i]]
        return -1
```

```Java []
class Solution {
    public int findRepeatDocument(int[] documents) {
        int i = 0;
        while(i < documents.length) {
            if(documents[i] == i) {
                i++;
                continue;
            }
            if(documents[documents[i]] == documents[i]) return documents[i];
            int tmp = documents[i];
            documents[i] = documents[tmp];
            documents[tmp] = tmp;
        }
        return -1;
    }
}
```

```C++ []
class Solution {
public:
    int findRepeatDocument(vector<int>& documents) {
        int i = 0;
        while(i < documents.size()) {
            if(documents[i] == i) {
                i++;
                continue;
            }
            if(documents[documents[i]] == documents[i])
                return documents[i];
            swap(documents[i],documents[documents[i]]);
        }
        return -1;
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(N)$ :** 遍历数组使用 $O(N)$ ,每轮遍历的判断和交换操作使用 $O(1)$ 。
- **空间复杂度 $O(1)$ :** 使用常数复杂度的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 121. 寻找目标值 - 二维数组.md
================================================
## 解题思路:

> 若使用暴力法遍历矩阵 `plants` ,则时间复杂度为 $O(NM)$ 。暴力法未利用矩阵 **“从上到下递增、从左到右递增”** 的特点,显然不是最优解法。

如下图所示,我们将矩阵逆时针旋转 45° ,并将其转化为图形式,发现其类似于 **二叉搜索树** ,即对于每个元素,其左分支元素更小、右分支元素更大。

因此,考虑从 “根节点” 开始搜索,遇到比 `target` 大的元素就向左,反之向右,即可找到目标值 `target` 。

![Picture1.png](https://pic.leetcode-cn.com/6584ea93812d27112043d203ea90e4b0950117d45e0452d0c630fcb247fbc4af-Picture1.png){:align=center width=450}

### 算法流程:

“根节点” 对应的是矩阵的 “左下角” 和 “右上角” 元素。以 `plants` 中的 **左下角元素** 为起始点,则有:

1. 从矩阵 `plants` 左下角元素(索引设为 `(i, j)` )开始遍历,并与目标值对比:
   - 当 `plants[i][j] > target` 时,执行 `i--` ,即消去第 `i` 行元素;
   - 当 `plants[i][j] < target` 时,执行 `j++` ,即消去第 `j` 列元素;
   - 当 `plants[i][j] = target` 时,返回 $\text{true}$ ,代表找到目标值。
2. 若行索引或列索引越界,则代表矩阵中无目标值,返回 $\text{false}$ 。

> 每轮 `i` 或 `j` 移动后,相当于生成了“消去一行(列)的新矩阵”, 索引`(i,j)` 指向新矩阵的左下角元素,因此可重复使用以上性质消去行(列)。

<![Picture2.png](https://pic.leetcode-cn.com/6a083897417b51e94ed84e3483d334078d851e691eb8655b45432372ecdea9d6-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/c301ea07f6081e95d06c07cc23fb0419e67ffdd92c2511201f72c3f86f18c928-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/3f1f6c8af23c89cd3179f486cfb932322ea4fa08ab707dc5e20b9adb243278e9-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/533c0eba70d25e5f7a1930186389a38feae15a91eea771fd388edd1eecc0b129-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/116704601a28972d17b32cc641485a1ab707930504a720160e121b092e9f7084-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/7db0cca850374644eff397880d5cdb3be17a3558a306162955a7ffb31bbf4e5c-Picture7.png)>

## 代码:

```Python []
class Solution:
    def findTargetIn2DPlants(self, plants: List[List[int]], target: int) -> bool:
        i, j = len(plants) - 1, 0
        while i >= 0 and j < len(plants[0]):
            if plants[i][j] > target: i -= 1
            elif plants[i][j] < target: j += 1
            else: return True
        return False
```

```Java []
class Solution {
    public boolean findTargetIn2DPlants(int[][] plants, int target) {
        int i = plants.length - 1, j = 0;
        while(i >= 0 && j < plants[0].length)
        {
            if(plants[i][j] > target) i--;
            else if(plants[i][j] < target) j++;
            else return true;
        }
        return false;
    }
}
```

```C++ []
class Solution {
public:
    bool findTargetIn2DPlants(vector<vector<int>>& plants, int target) {
        int i = plants.size() - 1, j = 0;
        while(i >= 0 && j < plants[0].size())
        {
            if(plants[i][j] > target) i--;
            else if(plants[i][j] < target) j++;
            else return true;
        }
        return false;
    }
};
```

### 复杂度分析:

- 时间复杂度 $O(M+N)$ :其中,$N$ 和 $M$ 分别为矩阵行数和列数,此算法最多循环 $M+N$ 次。
- 空间复杂度 $O(1)$ : `i`, `j` 指针使用常数大小额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 122. 路径加密.md
================================================
## 方法一:遍历添加

在 Python 和 Java 等语言中,字符串都被设计成「不可变」的类型,即无法直接修改字符串的某一位字符,需要新建一个字符串实现。

### 算法流程:

1. 初始化一个 `list` (Python) 或 `StringBuilder` (Java) ,记为 `res` ;
2. 遍历列表 `path` 中的每个字符 `c` :
    - 当 `c` 为空格时:向 `res` 后添加空格 " " ;
    - 当 `c` 不为空格时:向 `res` 后添加字符 `c` ;
3. 将列表 `res` 转化为字符串并返回。

> 下图中的 `s` 对应本题的 `path` 。

<![Picture1.png](https://pic.leetcode-cn.com/1599931882-pLqBGE-Picture1.png),![Picture2.png](https://pic.leetcode-cn.com/1599931882-qBgBNr-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1599931882-pzDKEt-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1599931882-IEnADl-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1599931882-LvchKo-Picture5.png)>

## 代码:

```Python []
class Solution:
    def pathEncryption(self, path: str) -> str:
        res = []
        for c in path:
            if c == '.': res.append(' ')
            else: res.append(c)
        return "".join(res)
```

```Java []
class Solution {
    public String pathEncryption(String path) {
        StringBuilder res = new StringBuilder();
        for(Character c : path.toCharArray())
        {
            if(c == '.') res.append(' ');
            else res.append(c);
        }
        return res.toString();
    }
}
```

### 复杂度分析:

- **时间复杂度 $O(N)$ :** 遍历使用 $O(N)$ ,每轮添加(修改)字符操作使用 $O(1)$ ;
- **空间复杂度 $O(N)$ :** Python 新建的 list 和 Java 新建的 StringBuilder 都使用了线性大小的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 123. 图书整理 I.md
================================================
## 方法一:递归

利用递归,先递推至链表末端;回溯时,依次将节点值加入列表,即可实现链表值的倒序输出。

1. **终止条件:** 当 `head == None` 时,代表越过了链表尾节点,则返回空列表;
2. **递推工作:** 访问下一节点 `head.next` ;
3. **回溯阶段:**
    - **Python:** 返回 `当前 list + 当前节点值 [head.val]` ;
    - **Java / C++:** 将当前节点值 `head.val` 加入列表 `tmp` ;

<![Picture1.png](https://pic.leetcode-cn.com/1599284309-ongbxB-Picture1.png),![Picture2.png](https://pic.leetcode-cn.com/1599284309-sNAjgz-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1599284309-lsJzwg-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1599284309-WEexSa-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1599284309-aAAzfv-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1599284309-AwHMnh-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1599284309-TPcwUZ-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1599284309-sBtikj-Picture8.png),![Picture8-1.png](https://pic.leetcode-cn.com/1599284504-Zuewmm-Picture8-1.png)>

### 代码:

```Python []
class Solution:
    def reverseBookList(self, head: Optional[ListNode]) -> List[int]:
        return self.reverseBookList(head.next) + [head.val] if head else []
```

```Java []
class Solution {
    ArrayList<Integer> tmp = new ArrayList<Integer>();
    public int[] reverseBookList(ListNode head) {
        recur(head);
        int[] res = new int[tmp.size()];
        for(int i = 0; i < res.length; i++)
            res[i] = tmp.get(i);
        return res;
    }
    void recur(ListNode head) {
        if(head == null) return;
        recur(head.next);
        tmp.add(head.val);
    }
}
```

```C++ []
class Solution {
public:
    vector<int> reverseBookList(ListNode* head) {
        recur(head);
        return res;
    }
private:
    vector<int> res;
    void recur(ListNode* head) {
        if(head == nullptr) return;
        recur(head->next);
        res.push_back(head->val);
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(N)$:** 遍历链表,递归 $N$ 次。
- **空间复杂度 $O(N)$:** 系统递归需要使用 $O(N)$ 的栈空间。

## 方法二:辅助栈法

链表只能 **从前至后** 访问每个节点,而题目要求 **倒序输出** 各节点值,这种 **先入后出** 的需求可以借助 **栈** 来实现。

### 算法流程:

1. **入栈:** 遍历链表,将各节点值 `push` 入栈。
2. **出栈:** 将各节点值 `pop` 出栈,存储于数组并返回。

> 图解以 Java 代码为例,Python 无需将 `stack` 转移至 `res`,而是直接返回倒序数组。

<![Picture9.png](https://pic.leetcode-cn.com/1599284309-uVDdUn-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1599284309-bkTHcM-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/1599284309-pjcVQL-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/1599284309-CdJEZQ-Picture12.png),![Picture13.png](https://pic.leetcode-cn.com/1599284309-hpDDSU-Picture13.png),![Picture14.png](https://pic.leetcode-cn.com/1599284309-BTfQdQ-Picture14.png),![Picture15.png](https://pic.leetcode-cn.com/1599284309-RplwUC-Picture15.png),![Picture16.png](https://pic.leetcode-cn.com/1599284309-JIonvw-Picture16.png)>

### 代码:

Java 数组长度不可变,因此使用 List 先存储,再转为数组并返回。

```Python []
class Solution:
    def reverseBookList(self, head: ListNode) -> List[int]:
        stack = []
        while head:
            stack.append(head.val)
            head = head.next
        return stack[::-1]
```

```Java []
class Solution {
    public int[] reverseBookList(ListNode head) {
        LinkedList<Integer> stack = new LinkedList<Integer>();
        while(head != null) {
            stack.addLast(head.val);
            head = head.next;
        }
        int[] res = new int[stack.size()];
        for(int i = 0; i < res.length; i++)
            res[i] = stack.removeLast();
    return res;
    }
}
```

```C++ []
class Solution {
public:
    vector<int> reverseBookList(ListNode* head) {
        stack<int> stk;
        while(head != nullptr) {
            stk.push(head->val);
            head = head->next;
        }
        vector<int> res;
        while(!stk.empty()) {
            res.push_back(stk.top());
            stk.pop();
        }
        return res;
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(N)$:** 入栈和出栈共使用 $O(N)$ 时间。
- **空间复杂度 $O(N)$:** 辅助栈 `stack` 和数组 `res` 共使用 $O(N)$ 的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 124. 推理二叉树.md
================================================
## 解题思路:

前序遍历性质: 节点按照 `[ 根节点 | 左子树 | 右子树 ]` 排序。
中序遍历性质: 节点按照 `[ 左子树 | 根节点 | 右子树 ]` 排序。

> 以题目示例为例:
> 
> - 前序遍历划分 `[ 3 | 9 | 20 15 7 ]`
> - 中序遍历划分 `[ 9 | 3 | 15 20 7 ]`

根据以上性质,可得出以下推论:

1. 前序遍历的首元素 为 树的根节点 `node` 的值。
2. 在中序遍历中搜索根节点 `node` 的索引 ,可将 中序遍历 划分为 `[ 左子树 | 根节点 | 右子树 ]` 。
3. 根据中序遍历中的左(右)子树的节点数量,可将 前序遍历 划分为 `[ 根节点 | 左子树 | 右子树 ] ` 。

![Picture1.png](https://pic.leetcode-cn.com/1629825510-roByLr-Picture1.png){:align=center width=550}

通过以上三步,可确定 **三个节点** :1.树的根节点、2.左子树根节点、3.右子树根节点。

根据「分治算法」思想,对于树的左、右子树,仍可复用以上方法划分子树的左右子树。

### 分治解析:

**递推参数:** 根节点在前序遍历的索引 `root` 、子树在中序遍历的左边界 `left` 、子树在中序遍历的右边界 `right` ;

**终止条件:** 当 `left > right` ,代表已经越过叶节点,此时返回 $\text{null}$ ;

**递推工作:**

1. **建立根节点 `node` :** 节点值为 `preorder[root]` ;
2. **划分左右子树:** 查找根节点在中序遍历 `inorder` 中的索引 `i` ;

> 为了提升效率,本文使用哈希表 `hmap` 存储中序遍历的值与索引的映射,查找操作的时间复杂度为 $O(1)$ ;

3. **构建左右子树:** 开启左右子树递归;

|            | 根节点索引            | 中序遍历左边界 | 中序遍历右边界 |
| ---------- | --------------------- | -------------- | -------------- |
| **左子树** | `root + 1`            | `left`         | `i - 1`        |
| **右子树** | `i - left + root + 1` | `i + 1`        | `right`        |

> **TIPS:** `i - left + root + 1`含义为 `根节点索引 + 左子树长度 + 1`

**返回值:** 回溯返回 `node` ,作为上一层递归中根节点的左 / 右子节点;

<![Picture2.png](https://pic.leetcode-cn.com/1603644245-DwefAv-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1603644377-aJTwyJ-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1603644377-rGvUqA-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1603644245-OrFteB-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1603644245-RBtYMS-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1603644245-ZlaMmX-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1603644245-leDZaF-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1603644245-KtWHlj-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1603644245-tYOIfd-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/1603644245-IAznrm-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/1603644245-oLIgwn-Picture12.png)>

## 代码:

> 注意:本文方法只适用于 “无重复节点值” 的二叉树。

```Python []
class Solution:
    def deduceTree(self, preorder: List[int], inorder: List[int]) -> TreeNode:
        def recur(root, left, right):
            if left > right: return                               # 递归终止
            node = TreeNode(preorder[root])                       # 建立根节点
            i = hmap[preorder[root]]                              # 划分根节点、左子树、右子树
            node.left = recur(root + 1, left, i - 1)              # 开启左子树递归
            node.right = recur(i - left + root + 1, i + 1, right) # 开启右子树递归
            return node                                           # 回溯返回根节点

        hmap, preorder = {}, preorder
        for i in range(len(inorder)):
            hmap[inorder[i]] = i
        return recur(0, 0, len(inorder) - 1)
```

```Java []
class Solution {
    int[] preorder;
    HashMap<Integer, Integer> hmap = new HashMap<>();
    public TreeNode deduceTree(int[] preorder, int[] inorder) {
        this.preorder = preorder;
        for(int i = 0; i < inorder.length; i++)
            hmap.put(inorder[i], i);
        return recur(0, 0, inorder.length - 1);
    }
    TreeNode recur(int root, int left, int right) {
        if(left > right) return null;                          // 递归终止
        TreeNode node = new TreeNode(preorder[root]);          // 建立根节点
        int i = hmap.get(preorder[root]);                      // 划分根节点、左子树、右子树
        node.left = recur(root + 1, left, i - 1);              // 开启左子树递归
        node.right = recur(root + i - left + 1, i + 1, right); // 开启右子树递归
        return node;                                           // 回溯返回根节点
    }
}
```

```C++ []
class Solution {
public:
    TreeNode* deduceTree(vector<int>& preorder, vector<int>& inorder) {
        this->preorder = preorder;
        for(int i = 0; i < inorder.size(); i++)
            hmap[inorder[i]] = i;
        return recur(0, 0, inorder.size() - 1);
    }
private:
    vector<int> preorder;
    unordered_map<int, int> hmap;
    TreeNode* recur(int root, int left, int right) { 
        if(left > right) return nullptr;                        // 递归终止
        TreeNode* node = new TreeNode(preorder[root]);          // 建立根节点
        int i = hmap[preorder[root]];                           // 划分根节点、左子树、右子树
        node->left = recur(root + 1, left, i - 1);              // 开启左子树递归
        node->right = recur(root + i - left + 1, i + 1, right); // 开启右子树递归
        return node;                                            // 回溯返回根节点
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(N)$ :** 其中 $N$ 为树的节点数量。初始化 HashMap 需遍历 `inorder` ,占用 $O(N)$ 。递归共建立 $N$ 个节点,每层递归中的节点建立、搜索操作占用 $O(1)$ ,因此使用 $O(N)$ 时间。
- **空间复杂度 $O(N)$ :** HashMap 使用 $O(N)$ 额外空间;最差情况下(输入二叉树为链表时),递归深度达到 $N$ ,占用 $O(N)$ 的栈帧空间;因此总共使用 $O(N)$ 空间。


================================================
FILE: leetbook_ioa/docs/LCR 125. 图书整理 II.md
================================================
## 解题思路:

> 我们可将两个书车看作两个“栈”,本题可被转化为“用两个栈实现一个队列”。

栈实现队列的出队操作效率低下:栈底元素(对应队首元素)无法直接删除,需要将上方所有元素出栈。

列表倒序操作可使用双栈实现:设有含三个元素的栈 `A = [1,2,3]` 和空栈 `B = []` 。若循环执行 `A` 元素出栈并添加入栈 `B` ,直到栈 `A` 为空,则 `A = []` , `B = [3,2,1]` ,即栈 `B` 元素为栈 `A` 元素倒序。

利用栈 `B` 删除队首元素:倒序后,`B` 执行出栈则相当于删除了 `A` 的栈底元素,即对应队首元素。

![Picture1.png](https://pic.leetcode-cn.com/1599286207-HnnMhX-Picture1.png){:align=center width=500}

题目要求实现 **加入队尾**`appendTail()` 和 **删除队首**`deleteHead()` 两个函数的正常工作。因此,可以设计栈 `A` 用于加入队尾操作,栈 `B` 用于将元素倒序,从而实现删除队首元素。

### 函数设计:

1. **加入队尾 `appendTail()` :** 将数字 `val` 加入栈 `A` 即可。
2. **删除队首`deleteHead()` :** 有以下三种情况。
    1. **当栈 `B` 不为空:** `B`中仍有已完成倒序的元素,因此直接返回 `B` 的栈顶元素。
    2. **否则,当 `A` 为空:** 即两个栈都为空,无元素,因此返回 -1 。
    3. **否则:** 将栈 `A` 元素全部转移至栈 `B` 中,实现元素倒序,并返回栈 `B` 的栈顶元素。

<![Picture2.png](https://pic.leetcode-cn.com/1599286207-iyRyBk-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1599286207-CGxWnt-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1599286207-tULpWB-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1599286207-aEsTfK-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1599286207-VdXYtf-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1599286207-heDHcK-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1599286207-gwMjUh-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1599286207-xInqcE-Picture9.png)>

## 代码:

Python 和 Java 的栈的 `pop()` 函数返回栈顶元素,而 C++ 不返回;因此对于 C++ ,需要先使用 `top()` 方法暂存栈顶元素,再执行 `pop()` 出栈操作。

```Python []
class CQueue:
    def __init__(self):
        self.A, self.B = [], []

    def appendTail(self, value: int) -> None:
        self.A.append(value)

    def deleteHead(self) -> int:
        if self.B: return self.B.pop()
        if not self.A: return -1
        while self.A:
            self.B.append(self.A.pop())
        return self.B.pop()
```

```Java []
class CQueue {
    LinkedList<Integer> A, B;
    public CQueue() {
        A = new LinkedList<Integer>();
        B = new LinkedList<Integer>();
    }
    public void appendTail(int value) {
        A.addLast(value);
    }
    public int deleteHead() {
        if(!B.isEmpty()) return B.removeLast();
        if(A.isEmpty()) return -1;
        while(!A.isEmpty())
            B.addLast(A.removeLast());
        return B.removeLast();
    }
}
```

```C++ []
class CQueue {
public:
    stack<int> A, B;
    CQueue() {}
    void appendTail(int value) {
        A.push(value);
    }
    int deleteHead() {
        if(!B.empty()) {
            int tmp = B.top();
            B.pop();
            return tmp;
        }
        if(A.empty()) return -1;
        while(!A.empty()) {
            int tmp = A.top();
            A.pop();
            B.push(tmp);
        }
        int tmp = B.top();
        B.pop();
        return tmp;
    }
};
```

### 复杂度分析:

> 以下分析仅满足添加 $N$ 个元素并删除 $N$ 个元素,即栈初始和结束状态下都为空的情况。

- **时间复杂度:** `appendTail()`函数为 $O(1)$ ;`deleteHead()` 函数在 $N$ 次队首元素删除操作中总共需完成 $N$ 个元素的倒序。
- **空间复杂度 $O(N)$ :** 最差情况下,栈 `A` 和 `B` 共保存 $N$ 个元素。


================================================
FILE: leetbook_ioa/docs/LCR 126. 斐波那契数.md
================================================
## 解题思路:

斐波那契数列的定义是 $f(n + 1) = f(n) + f(n - 1)$ ,生成第 $n$ 项的做法有以下几种:

1. **递归:**
    - **原理:** 把 $f(n)$ 问题的计算拆分成 $f(n-1)$ 和 $f(n-2)$ 两个子问题的计算,并递归,以 $f(0)$ 和 $f(1)$ 为终止条件。
    - **缺点:** 大量重复的递归计算,例如 $f(n)$ 和 $f(n - 1)$ 两者向下递归需要 **各自计算** $f(n - 2)$ 的值。
2. **记忆化递归:**
    - **原理:** 在递归的基础上,新建一个长度为 $n$ 的数组,用于在递归时存储 $f(0)$ 至 $f(n)$ 的数字值,重复遇到某数字则直接从数组取用,避免了重复的递归计算。
    - **缺点:** 记忆化存储需要使用 $O(N)$ 的额外空间。
3. **动态规划:**
    - **原理:** 以斐波那契数列性质 $f(n + 1) = f(n) + f(n - 1)$ 为转移方程。
    - 从计算效率、空间复杂度上看,动态规划是本题的最佳解法。

> 下图帮助理解递归的 “重复计算” 概念。

![Picture1.png](https://pic.leetcode-cn.com/1599882883-mtYecf-Picture1.png){:align=center width=500}

### 动态规划解析:

- **状态定义:** 设 $dp$ 为一维数组,其中 $dp[i]$ 的值代表 斐波那契数列第 $i$ 个数字 。
- **转移方程:** $dp[i + 1] = dp[i] + dp[i - 1]$ ,即对应数列定义 $f(n + 1) = f(n) + f(n - 1)$ ;
- **初始状态:** $dp[0] = 0$, $dp[1] = 1$ ,即初始化前两个数字;
- **返回值:** $dp[n]$ ,即斐波那契数列的第 $n$ 个数字。

### 空间优化:

> 若新建长度为 $n$ 的 $dp$ 列表,则空间复杂度为 $O(N)$ 。

- 由于 $dp$ 列表第 $i$ 项只与第 $i-1$ 和第 $i-2$ 项有关,因此只需要初始化三个整形变量 `sum`, `a`, `b` ,利用辅助变量 $sum$ 使 $a, b$ 两数字交替前进即可 *(具体实现见代码)* 。
- 节省了 $dp$ 列表空间,因此空间复杂度降至 $O(1)$ 。

### 循环求余法:

> **大数越界:** 随着 $n$ 增大, $f(n)$ 会超过 `Int32` 甚至 `Int64` 的取值范围,导致最终的返回值错误。 

- **求余运算规则:** 设正整数 $x, y, p$ ,求余符号为 $\odot$ ,则有 $(x + y) \odot p = (x \odot p + y \odot p) \odot p$ 。
- **解析:** 根据以上规则,可推出 $f(n) \odot p = [f(n-1) \odot p + f(n-2) \odot p] \odot p$ ,从而可以在循环过程中每次计算 $sum = (a + b) \odot 1000000007$ ,此操作与最终返回前取余等价。

<![Picture2.png](https://pic.leetcode-cn.com/1599882883-jbnPaZ-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1599882883-ZIXjom-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1599882883-UHnEEL-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1599882883-UHtjpA-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1599882883-jXtHXx-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1599882883-ppWbXc-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1599882883-lyXbyd-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1599882883-vhrJxv-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1599882883-cIpqVP-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/1599882883-NmQlPg-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/1599882883-coycTs-Picture12.png),![Picture13.png](https://pic.leetcode-cn.com/1599882883-FZVjJi-Picture13.png)>

## 代码:

```Python []
class Solution:
    def fib(self, n: int) -> int:
        a, b = 0, 1
        for _ in range(n):
            a, b = b, (a + b) % 1000000007
        return a
```

```Java []
class Solution {
    public int fib(int n) {
        int a = 0, b = 1, sum;
        for(int i = 0; i < n; i++){
            sum = (a + b) % 1000000007;
            a = b;
            b = sum;
        }
        return a;
    }
}
```

```C++ []
class Solution {
public:
    int fib(int n) {
        int a = 0, b = 1, sum;
        for(int i = 0; i < n; i++){
            sum = (a + b) % 1000000007;
            a = b;
            b = sum;
        }
        return a;
    }
};
```

由于 Python 中整形数字的大小限制取决计算机的内存(可理解为无限大),因此也可不考虑大数越界问题;但当数字很大时,加法运算的效率也会降低,因此不推荐此方法。

```Python []
# 不考虑大数越界问题
class Solution:
    def fib(self, n: int) -> int:
        a, b = 0, 1
        for _ in range(n):
            a, b = b, a + b
        return a % 1000000007
```

### 复杂度分析:

- **时间复杂度 $O(n)$ :** 计算 $f(n)$ 需循环 $n$ 次,每轮循环内计算操作使用 $O(1)$ 。
- **空间复杂度 $O(1)$ :** 几个标志变量使用常数大小的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 127. 跳跃训练.md
================================================
## 解题思路:

设跳上 $n$ 级平台有 $f(n)$ 种跳法。在所有跳法中,青蛙的最后一步只有两种情况: **跳上 $1$ 级或 $2$ 级平台**。

1. **当为 $1$ 级平台:** 剩 $n-1$ 个平台,此情况共有 $f(n-1)$ 种跳法;
2. **当为 $2$ 级平台:** 剩 $n-2$ 个平台,此情况共有 $f(n-2)$ 种跳法。

即 $f(n)$ 为以上两种情况之和,即 $f(n)=f(n-1)+f(n-2)$ ,以上递推性质为斐波那契数列。因此,本题可转化为 **求斐波那契数列第 $n$ 项的值** ,唯一的不同在于起始数字不同。

- 跳跃训练问题: $f(0)=1$ ,  $f(1)=1$ , $f(2)=2$ ;
- 斐波那契数列问题: $f(0)=0$ , $f(1)=1$ , $f(2)=1$ 。

![Picture1.png](https://pic.leetcode-cn.com/1599883153-UckfTw-Picture1.png){:align=center width=500}

### 动态规划解析:

- **状态定义:** 设 $dp$ 为一维数组,其中 $dp[i]$ 的值代表斐波那契数列的第 $i$ 个数字。
- **转移方程:** $dp[i + 1] = dp[i] + dp[i - 1]$ ,即对应数列定义 $f(n + 1) = f(n) + f(n - 1)$ ;
- **初始状态:** $dp[0] = 1$, $dp[1] = 1$ ,即初始化前两个数字;
- **返回值:** $dp[n]$ ,即斐波那契数列的第 $n$ 个数字。

### 空间优化:

> 若新建长度为 $n$ 的 $dp$ 列表,则空间复杂度为 $O(N)$ 。

- 由于 $dp$ 列表第 $i$ 项只与第 $i-1$ 和第 $i-2$ 项有关,因此只需要初始化三个整形变量 `sum`, `a`, `b` ,利用辅助变量 $sum$ 使 $a, b$ 两数字交替前进即可 *(具体实现见代码)* 。
- 因为节省了 $dp$ 列表空间,因此空间复杂度降至 $O(1)$ 。

### 循环求余法:

> **大数越界:** 随着 $n$ 增大, $f(n)$ 会超过 `Int32` 甚至 `Int64` 的取值范围,导致最终的返回值错误。

- **求余运算规则:** 设正整数 $x, y, p$ ,求余符号为 $\odot$ ,则有 $(x + y) \odot p = (x \odot p + y \odot p) \odot p$ 。
- **解析:** 根据以上规则,可推出 $f(n) \odot p = [f(n-1) \odot p + f(n-2) \odot p] \odot p$ ,从而可以在循环过程中每次计算 $sum = a + b \odot 1000000007$ ,此操作与最终返回前取余等价。

<![Picture2.png](https://pic.leetcode-cn.com/1599883153-iXEZvr-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1599883153-MjJsdM-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1599883153-kMaCBQ-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1599883153-jVtBVj-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1599883153-EsemaN-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1599883153-wznsCe-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1599883153-mVlvjo-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1599883153-zzFSWJ-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1599883153-LmZgWM-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/1599883153-jSUeMz-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/1599883153-kRKefY-Picture12.png),![Picture13.png](https://pic.leetcode-cn.com/1599883153-vEYzWk-Picture13.png)>

## 代码:

```Python []
class Solution:
    def trainWays(self, num: int) -> int:
        a, b = 1, 1
        for _ in range(num):
            a, b = b, (a + b) % 1000000007
        return a
```

```Java []
class Solution {
    public int trainWays(int num) {
        int a = 1, b = 1, sum;
        for(int i = 0; i < num; i++){
            sum = (a + b) % 1000000007;
            a = b;
            b = sum;
        }
        return a;
    }
}
```

```C++ []
class Solution {
public:
    int trainWays(int num) {
        int a = 1, b = 1, sum;
        for(int i = 0; i < num; i++){
            sum = (a + b) % 1000000007;
            a = b;
            b = sum;
        }
        return a;
    }
};
```

由于 Python 中整形数字的大小限制取决计算机的内存(可理解为无限大),因此也可不考虑大数越界问题;但当数字很大时,加法运算的效率也会降低,因此不推荐此方法。

```Python []
# 不考虑大数越界问题
class Solution:
    def trainWays(self, num: int) -> int:
        a, b = 1, 1
        for _ in range(num):
            a, b = b, a + b
        return a % 1000000007
```

### 复杂度分析:

- **时间复杂度 $O(n)$ :** 计算 $f(n)$ 需循环 $n$ 次,每轮循环内计算操作使用 $O(1)$ 。
- **空间复杂度 $O(1)$ :** 几个标志变量使用常数大小的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 128. 库存管理 I.md
================================================
## 解题思路:

如下图所示,寻找旋转数组的最小元素即为寻找 **右排序数组** 的首个元素 $stock[x]$ ,称 $x$ 为 **旋转点** 。

> 下图中的 `numbers` 对应本题的 `stock` 。

![Picture1.png](https://pic.leetcode-cn.com/1599404042-JMvjtL-Picture1.png){:align=center width=450}

排序数组的查找问题首先考虑使用 **二分法** 解决,其可将 **遍历法** 的 **线性级别** 时间复杂度降低至 **对数级别** 。

### 算法流程:

1. **初始化:** 声明 $i$, $j$ 双指针分别指向 $stock$ 数组左右两端;
2. **循环二分:** 设 $m = (i + j) / 2$ 为每次二分的中点( "`/`" 代表向下取整除法,因此恒有 $i \leq m < j$ ),可分为以下三种情况:
    1. **当 $stock[m] > stock[j]$ 时:** $m$ 一定在 左排序数组 中,即旋转点 $x$ 一定在 $[m + 1, j]$ 闭区间内,因此执行 $i = m + 1$;
    2. **当 $stock[m] < stock[j]$ 时:** $m$ 一定在 右排序数组 中,即旋转点 $x$ 一定在$[i, m]$ 闭区间内,因此执行 $j = m$;
    3. **当 $stock[m] = stock[j]$ 时:** 无法判断 $m$ 在哪个排序数组中,即无法判断旋转点 $x$ 在 $[i, m]$ 还是 $[m + 1, j]$ 区间中。**解决方案:** 执行 $j = j - 1$ 缩小判断范围,分析见下文。
3. **返回值:** 当 $i = j$ 时跳出二分循环,并返回 **旋转点的值** $stock[i]$ 即可。

### 正确性证明:

当 $stock[m] = stock[j]$ 时,无法判定 $m$ 在左(右)排序数组,自然也无法通过二分法安全地缩小区间,因为其会导致旋转点 $x$ 不在区间 $[i, j]$ 内。举例如下:

> 设以下两个旋转点值为 $0$ 的示例数组,则当 $i = 0$, $j = 4$ 时 $m = 2$ ,两示例结果不同。
> 示例一 $[1, 0, 1, 1, 1]$ :旋转点 $x = 1$ ,因此 $m = 2$ 在 **右排序数组** 中。
> 示例二 $[1, 1, 1, 0, 1]$ :旋转点 $x = 3$ ,因此 $m = 2$ 在 **左排序数组** 中。

而证明 $j = j - 1$ 正确(缩小区间安全性),需分为两种情况:

1. **当 $x < j$ 时:** 易得执行 $j = j - 1$ 后,旋转点 $x$ 仍在区间 $[i, j]$ 内。
2. **当 $x = j$ 时:** 执行 $j = j - 1$ 后越过(丢失)了旋转点 $x$ ,但最终返回的元素值 $stock[i]$ 仍等于旋转点值 $stock[x]$ 。

    1. 由于 $x = j$ ,因此 $stock[x] = stock[j] = stock[m] \leq number[i]$ ;
    2. 又由于 $i \leq m <j$ 恒成立,因此有 $m < x$ ,即此时 $m$ 一定在左排序数组中,因此 $stock[m] \geq stock[i]$ ;

综合 `1.` , `2.` ,可推出 $stock[i] = stock[m]$ ,且区间 $[i, m]$ 内所有元素值相等,即有:

$$
stock[i] = stock[i+1] = \cdots = stock[m] = stock[x]
$$

此时,执行 $j = j - 1$ 后虽然丢失了旋转点 $x$ ,但之后区间 $[i, j]$ 只包含左排序数组,二分下去返回的一定是本轮的 $stock[i]$ ,而其与 $stock[x]$ 相等。

> 综上所述,此方法可以保证返回值 $stock[i]$ 等于旋转点值 $stock[x]$ ,但在少数特例下 $i \ne x$ ;而本题目只要求返回 “旋转点的值” ,因此本方法正确。

**补充思考:** 为什么本题二分法不用 $stock[m]$ 和 $stock[i]$ 作比较?

二分目的是判断 $m$ 在哪个排序数组中,从而缩小区间。而在 $stock[m] > stock[i]$情况下,无法判断 $m$ 在哪个排序数组中。本质上是由于 $j$ 初始值肯定在右排序数组中;$i$ 初始值无法确定在哪个排序数组中。举例如下:

> 对于以下两示例,当 $i = 0, j = 4, m = 2$ 时,有 `stock[m] > stock[i]` ,而结果不同。
> $[1, 2, 3, 4 ,5]$ 旋转点 $x = 0$ : $m$ 在右排序数组(此示例只有右排序数组);
> $[3, 4, 5, 1 ,2]$ 旋转点 $x = 3$ : $m$ 在左排序数组。

<![Picture2.png](https://pic.leetcode-cn.com/1599404042-VzHrmU-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1599404042-fNXpQJ-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1599404042-qbOflt-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1599404042-sBLuCR-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1599404042-lYmLFN-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1599404042-HkRBZW-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1599404366-eOwigV-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1599404366-ngPDoD-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1599404438-qzDKAI-Picture10.png)>

### 复杂度分析:

- **时间复杂度 $O(\log N)$ :** 在特例情况下(例如 $[1, 1, 1, 1]$),会退化到 $O(N)$。
- **空间复杂度 $O(1)$ :** $i$ , $j$ , $m$ 变量使用常数大小的额外空间。

## 代码:

```Python []
class Solution:
    def stockManagement(self, stock: List[int]) -> int:
        i, j = 0, len(stock) - 1
        while i < j:
            m = (i + j) // 2
            if stock[m] > stock[j]: i = m + 1
            elif stock[m] < stock[j]: j = m
            else: j -= 1
        return stock[i]
```

```Java []
class Solution {
    public int stockManagement(int[] stock) {
        int i = 0, j = stock.length - 1;
        while (i < j) {
            int m = (i + j) / 2;
            if (stock[m] > stock[j]) i = m + 1;
            else if (stock[m] < stock[j]) j = m;
            else j--;
        }
        return stock[i];
    }
}
```

```C++ []
class Solution {
public:
    int stockManagement(vector<int>& stock) {
        int i = 0, j = stock.size() - 1;
        while (i < j) {
            int m = (i + j) / 2;
            if (stock[m] > stock[j]) i = m + 1;
            else if (stock[m] < stock[j]) j = m;
            else j--;
        }
        return stock[i];
    }
};
```

实际上,当出现 $stock[m] = stock[j]$ 时,一定有区间 $[i, m]$ 内所有元素相等 或 区间 $[m, j]$ 内所有元素相等(或两者皆满足)。对于寻找此类数组的最小值问题,可直接放弃二分查找,而使用线性查找替代。

```Python []
class Solution:
    def stockManagement(self, stock: List[int]) -> int:
        i, j = 0, len(stock) - 1
        while i < j:
            m = (i + j) // 2
            if stock[m] > stock[j]: i = m + 1
            elif stock[m] < stock[j]: j = m
            else: return min(stock[i:j])
        return stock[i]
```

```Java []
class Solution {
    public int stockManagement(int[] stock) {
        int i = 0, j = stock.length - 1;
        while (i < j) {
            int m = (i + j) / 2;
            if (stock[m] > stock[j]) i = m + 1;
            else if (stock[m] < stock[j]) j = m;
            else {
                int x = i;
                for(int k = i + 1; k < j; k++) {
                    if(stock[k] < stock[x]) x = k;
                }
                return stock[x];
            }
        }
        return stock[i];
    }
}
```

```C++ []
class Solution {
public:
    int stockManagement(vector<int>& stock) {
        int i = 0, j = stock.size() - 1;
        while (i < j) {
            int m = (i + j) / 2;
            if (stock[m] > stock[j]) i = m + 1;
            else if (stock[m] < stock[j]) j = m;
            else {
                int x = i;
                for(int k = i + 1; k < j; k++) {
                    if(stock[k] < stock[x]) x = k;
                }
                return stock[x];
            }
        }
        return stock[i];
    }
};
```


================================================
FILE: leetbook_ioa/docs/LCR 129. 字母迷宫.md
================================================
## 解题思路:

本问题是典型的回溯问题,可使用 **深度优先搜索(DFS)+ 剪枝** 解决。

- **深度优先搜索:** 可以理解为暴力法遍历矩阵中所有字符串可能性。DFS 通过递归,先朝一个方向搜到底,再回溯至上个节点,沿另一个方向搜索,以此类推。
- **剪枝:** 在搜索中,遇到 `这条路不可能和目标字符串匹配成功` 的情况(*例如:此矩阵元素和目标字符不同、此元素已被访问)*,则应立即返回,称之为 `可行性剪枝` 。

> 下图中的 `word` 对应本题的 `target` 。

![Picture0.png](https://pic.leetcode-cn.com/1604944042-glmqJO-Picture0.png){:align=center width=500}

### DFS 解析:

- **递归参数:** 当前元素在矩阵 `grid` 中的行列索引 `i` 和 `j` ,当前目标字符在 `target` 中的索引 `k` 。
- **终止条件:**
  1. 返回 $\text{false}$ : (1) 行或列索引越界 **或** (2) 当前矩阵元素与目标字符不同 **或** (3) 当前矩阵元素已访问过 ( (3) 可合并至 (2) ) 。
  2. 返回 $\text{true}$ : `k = len(target) - 1` ,即字符串 `target` 已全部匹配。
- **递推工作:**
  1. 标记当前矩阵元素: 将 `grid[i][j]` 修改为 **空字符** `''` ,代表此元素已访问过,防止之后搜索时重复访问。
  2. 搜索下一单元格: 朝当前元素的 **上、下、左、右** 四个方向开启下层递归,使用 `或` 连接 (代表只需找到一条可行路径就直接返回,不再做后续 DFS ),并记录结果至 `res` 。
  3. 还原当前矩阵元素: 将 `grid[i][j]` 元素还原至初始值,即 `target[k]` 。
- **返回值:** 返回布尔量 `res` ,代表是否搜索到目标字符串。

> 使用空字符(Python: `''` , Java/C++: `'\0'` )做标记是为了防止标记字符与矩阵原有字符重复。当存在重复时,此算法会将矩阵原有字符认作标记字符,从而出现错误。

<![Picture1.png](https://pic.leetcode-cn.com/1600793567-fPZPYj-Picture1.png),![Picture2.png](https://pic.leetcode-cn.com/1600793567-hVwomN-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1600793567-yoOQer-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1600793567-qyZcNF-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1600793567-pvxYVP-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1600793567-izfBtb-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1600793567-bwnSPQ-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1600793567-pnRRIE-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1600793567-yQNohz-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1600793567-zLOKmi-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/1600793567-neMJnx-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/1600793567-dyuEzg-Picture12.png),![Picture13.png](https://pic.leetcode-cn.com/1600793567-lnVDIT-Picture13.png),![Picture14.png](https://pic.leetcode-cn.com/1600793567-tLXXgg-Picture14.png),![Picture15.png](https://pic.leetcode-cn.com/1600793567-VwCJGV-Picture15.png),![Picture16.png](https://pic.leetcode-cn.com/1600793567-aNgVtM-Picture16.png),![Picture17.png](https://pic.leetcode-cn.com/1600793567-EcdfJE-Picture17.png),![Picture18.png](https://pic.leetcode-cn.com/1600793793-PrBQdk-Picture18.png)>

## 代码:

```Python []
class Solution:
    def wordPuzzle(self, grid: List[List[str]], target: str) -> bool:
        def dfs(i, j, k):
            if not 0 <= i < len(grid) or not 0 <= j < len(grid[0]) or grid[i][j] != target[k]: return False
            if k == len(target) - 1: return True
            grid[i][j] = ''
            res = dfs(i + 1, j, k + 1) or dfs(i - 1, j, k + 1) or dfs(i, j + 1, k + 1) or dfs(i, j - 1, k + 1)
            grid[i][j] = target[k]
            return res

        for i in range(len(grid)):
            for j in range(len(grid[0])):
                if dfs(i, j, 0): return True
        return False
```

```Java []
class Solution {
    public boolean wordPuzzle(char[][] grid, String target) {
        char[] words = target.toCharArray();
        for(int i = 0; i < grid.length; i++) {
            for(int j = 0; j < grid[0].length; j++) {
                if(dfs(grid, words, i, j, 0)) return true;
            }
        }
        return false;
    }
    boolean dfs(char[][] grid, char[] target, int i, int j, int k) {
        if(i >= grid.length || i < 0 || j >= grid[0].length || j < 0 || grid[i][j] != target[k]) return false;
        if(k == target.length - 1) return true;
        grid[i][j] = '\0';
        boolean res = dfs(grid, target, i + 1, j, k + 1) || dfs(grid, target, i - 1, j, k + 1) || 
                      dfs(grid, target, i, j + 1, k + 1) || dfs(grid, target, i , j - 1, k + 1);
        grid[i][j] = target[k];
        return res;
    }
}
```

```C++ []
class Solution {
public:
    bool wordPuzzle(vector<vector<char>>& grid, string target) {
        rows = grid.size();
        cols = grid[0].size();
        for(int i = 0; i < rows; i++) {
            for(int j = 0; j < cols; j++) {
                if(dfs(grid, target, i, j, 0)) return true;
            }
        }
        return false;
    }
private:
    int rows, cols;
    bool dfs(vector<vector<char>>& grid, string target, int i, int j, int k) {
        if(i >= rows || i < 0 || j >= cols || j < 0 || grid[i][j] != target[k]) return false;
        if(k == target.size() - 1) return true;
        grid[i][j] = '\0';
        bool res = dfs(grid, target, i + 1, j, k + 1) || dfs(grid, target, i - 1, j, k + 1) || 
                      dfs(grid, target, i, j + 1, k + 1) || dfs(grid, target, i , j - 1, k + 1);
        grid[i][j] = target[k];
        return res;
    }
};
```

### 复杂度分析:

> $M, N$ 分别为矩阵行列大小,$K$ 为字符串 `target` 长度。

- **时间复杂度 $O(3^KMN)$ :** 最差情况下,需要遍历矩阵中长度为 $K$ 字符串的所有方案,时间复杂度为 $O(3^K)$;矩阵中共有 $MN$ 个起点,时间复杂度为 $O(MN)$ 。
  - **方案数计算:** 设字符串长度为 $K$ ,搜索中每个字符有上、下、左、右四个方向可以选择,舍弃回头(上个字符)的方向,剩下 $3$ 种选择,因此方案数的复杂度为 $O(3^K)$ 。
- **空间复杂度 $O(K)$ :** 搜索过程中的递归深度不超过 $K$ ,因此系统因函数调用累计使用的栈空间占用 $O(K)$ (因为函数返回后,系统调用的[栈空间会释放](https://leetcode-cn.com/explore/orignial/card/recursion-i/259/complexity-analysis/1223/))。最坏情况下 $K = MN$ ,递归深度为 $MN$ ,此时系统栈使用 $O(MN)$ 的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 130. 衣橱整理.md
================================================
## 解题思路:

为提升回溯的计算效率,首先讲述两项前置工作: **数位之和计算** 、 **可达解分析** 。

### 数位之和计算:

设一数字 $x$ ,向下取整除法符号 $//$ ,求余符号 $\odot$ ,则有:

- $x \odot 10$ :得到 $x$ 的个位数字;
- $x // 10$ : 令 $x$ 的十进制数向右移动一位,即删除个位数字。

因此,可通过循环求得数位和 $s$ ,数位和计算的封装函数如下所示:

```Python []
def sums(x):
    s = 0
    while x != 0:
        s += x % 10
        x = x // 10
    return s
```

```Java []
int sums(int x)
    int s = 0;
    while(x != 0) {
        s += x % 10;
        x = x / 10;
    }
    return s;
```

```C++ []
int sums(int x)
    int s = 0;
    while(x != 0) {
        s += x % 10;
        x = x / 10;
    }
    return s;
```

由于机器人每次只能移动一格(即只能从 $x$ 运动至 $x \pm 1$),因此每次只需计算 $x$ 到 $x \pm 1$ 的**数位和增量**。本题说明 $1 \leq n,m \leq 100$ ,以下公式仅在此范围适用。

**数位和增量公式:** 设 $x$ 的数位和为 $s_x$ ,$x+1$ 的数位和为 $s_{x+1}$ ;

1. **当 $(x + 1) \odot 10 = 0$ 时:** $s_{x+1} = s_x - 8$ ,例如 $19, 20$ 的数位和分别为 $10, 2$ ;
2. **当 $(x + 1) \odot 10 \neq 0$ 时:** $s_{x+1} = s_x + 1$ ,例如 $1, 2$ 的数位和分别为 $1, 2$ 。

> 以下代码为增量公式的三元表达式写法,将整合入最终代码中。

```Python []
s_x + 1 if (x + 1) % 10 else s_x - 8
```

```Java []
(x + 1) % 10 != 0 ? s_x + 1 : s_x - 8;
```

```C++ []
(x + 1) % 10 != 0 ? s_x + 1 : s_x - 8;
```

### 可达解分析:

根据数位和增量公式得知,数位和每逢 **进位** 突变一次。根据此特点,矩阵中 **满足数位和的解** 构成的几何形状形如多个 **等腰直角三角形** ,每个三角形的直角顶点位于 $0, 10, 20, ...$ 等数位和突变的矩阵索引处  。

三角形内的解虽然都满足数位和要求,但由于机器人每步只能走一个单元格,而三角形间不一定是连通的,因此机器人不一定能到达,称之为 **不可达解** ;同理,可到达的解称为 **可达解**  *(本题求此解)* 。

> 下图展示了 $n,m = 20$ ,$cnt \in [6, 19]$ 的可达解、不可达解、非解,以及连通性的变化。其中 $k$ 对应本题的 $cnt$ 。

<![Picture1.png](https://pic.leetcode-cn.com/1603026306-OdpwLi-Picture1.png),![Picture2.png](https://pic.leetcode-cn.com/1603026306-jCBpqd-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1603026306-aEEvfM-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1603026306-daxIuh-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1603026306-HAMNPH-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1603026306-IUKeMt-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1603026306-YxlxXI-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1603026306-JLhUWz-Picture8.png)>

根据可达解的结构和连通性,易推出机器人可 **仅通过向右和向下移动,访问所有可达解** 。

- **三角形内部:** 全部连通,易证;
- **两三角形连通处:** 若某三角形内的解为可达解,则必与其左边或上边的三角形连通(即相交),即机器人必可从左边或上边走进此三角形。

![Picture9.png](https://pic.leetcode-cn.com/1603024999-XMpudY-Picture9.png){:align=center width=500}

## 方法一:深度优先遍历(DFS)

**深度优先搜索:** 可以理解为暴力法模拟机器人在矩阵中的所有路径。DFS 通过递归,先朝一个方向搜到底,再回溯至上个节点,沿另一个方向搜索,以此类推。

**剪枝:** 在搜索中,遇到数位和超出目标值、此元素已访问,则应立即返回,称之为 `可行性剪枝` 。

### 算法解析:

- **递归参数:** 当前元素在矩阵中的行列索引 `i` 和 `j` ,两者的数位和 `si`, `sj` 。
- **终止条件:** 当 (1) 行列索引越界 **或** (2) 数位和超出目标值 `cnt`  **或** (3) 当前元素已访问过 时,返回 $0$ ,代表不计入可达解。
- **递推工作:**
  1. **标记当前单元格** :将索引 `(i, j)` 存入 Set `visited` 中,代表此单元格已被访问过。
  2. **搜索下一单元格:** 计算当前元素的 **下、右** 两个方向元素的数位和,并开启下层递归 。
- **回溯返回值:** 返回 `1 + 右方搜索的可达解总数 + 下方搜索的可达解总数`,代表从本单元格递归搜索的可达解总数。

<![Picture10.png](https://pic.leetcode-cn.com/1603024999-URYkbB-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/1603024999-XyKkZo-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/1603024999-eQXMnv-Picture12.png),![Picture13.png](https://pic.leetcode-cn.com/1603024999-mcujIe-Picture13.png),![Picture14.png](https://pic.leetcode-cn.com/1603024999-dXOdEJ-Picture14.png),![Picture15.png](https://pic.leetcode-cn.com/1603024999-ApTwow-Picture15.png),![Picture16.png](https://pic.leetcode-cn.com/1603024999-krgMMb-Picture16.png),![Picture17.png](https://pic.leetcode-cn.com/1603024999-JCGqrp-Picture17.png),![Picture18.png](https://pic.leetcode-cn.com/1603024999-jYYavg-Picture18.png),![Picture19.png](https://pic.leetcode-cn.com/1603024999-RRZCbl-Picture19.png),![Picture20.png](https://pic.leetcode-cn.com/1603024999-HBTzMV-Picture20.png),![Picture21.png](https://pic.leetcode-cn.com/1603024999-iYtADx-Picture21.png)>

### 代码:

> Java/C++ 代码中 `visited` 为辅助矩阵,Python 中为 Set 。

```Python []
class Solution:
    def wardrobeFinishing(self, m: int, n: int, cnt: int) -> int:
        def dfs(i, j, si, sj):
            if i >= m or j >= n or cnt < si + sj or (i, j) in visited: return 0
            visited.add((i,j))
            return 1 + dfs(i + 1, j, si + 1 if (i + 1) % 10 else si - 8, sj) + dfs(i, j + 1, si, sj + 1 if (j + 1) % 10 else sj - 8)

        visited = set()
        return dfs(0, 0, 0, 0)
```

```Java []
class Solution {
    int m, n, cnt;
    boolean[][] visited;
    public int wardrobeFinishing(int m, int n, int cnt) {
        this.m = m; this.n = n; this.cnt = cnt;
        this.visited = new boolean[m][n];
        return dfs(0, 0, 0, 0);
    }
    public int dfs(int i, int j, int si, int sj) {
        if(i >= m || j >= n || cnt < si + sj || visited[i][j]) return 0;
        visited[i][j] = true;
        return 1 + dfs(i + 1, j, (i + 1) % 10 != 0 ? si + 1 : si - 8, sj) + dfs(i, j + 1, si, (j + 1) % 10 != 0 ? sj + 1 : sj - 8);
    }
}
```

```C++ []
class Solution {
public:
    int wardrobeFinishing(int m, int n, int cnt) {
        vector<vector<bool>> visited(m, vector<bool>(n, 0));
        return dfs(0, 0, 0, 0, visited, m, n, cnt);
    }
private:
    int dfs(int i, int j, int si, int sj, vector<vector<bool>> &visited, int m, int n, int cnt) {
        if(i >= m || j >= n || cnt < si + sj || visited[i][j]) return 0;
        visited[i][j] = true;
        return 1 + dfs(i + 1, j, (i + 1) % 10 != 0 ? si + 1 : si - 8, sj, visited, m, n, cnt) +
                   dfs(i, j + 1, si, (j + 1) % 10 != 0 ? sj + 1 : sj - 8, visited, m, n, cnt);
    }
};
```

### 复杂度分析:

> 设矩阵行列数分别为 $M, N$ 。

- **时间复杂度 $O(MN)$ :** 最差情况下,机器人遍历矩阵所有单元格,此时时间复杂度为 $O(MN)$ 。
- **空间复杂度 $O(MN)$ :** 最差情况下,Set `visited` 内存储矩阵所有单元格的索引,使用 $O(MN)$ 的额外空间。

## 方法二:广度优先遍历(BFS)

BFS 和 DFS 的目标都是遍历整个矩阵,不同点在于搜索顺序不同。DFS 是朝一个方向走到底,再回退,以此类推;BFS 则是按照“平推”的方式向前搜索。

**BFS 实现:** 通常利用队列实现广度优先遍历。

### 算法解析:

- **初始化:** 将机器人初始点 $(0, 0)$ 加入队列 `queue` ;
- **迭代终止条件:** `queue` 为空。代表已遍历完所有可达解。
- **迭代工作:**
  1. **单元格出队:** 将队首单元格的 索引、数位和 弹出,作为当前搜索单元格。
  2. **判断是否跳过:** 若 (1) 行列索引越界 **或** (2) 数位和超出目标值 `cnt`  **或** (3) 当前元素已访问过  时,执行 `continue` 。
  3. **标记当前单元格** :将单元格索引 `(i, j)` 存入 Set `visited` 中,代表此单元格 **已被访问过** 。
  4. **单元格入队:** 将当前元素的 **下方、右方** 单元格的 **索引、数位和** 加入 `queue`  。
- **返回值:** Set `visited` 的长度 `len(visited)` ,即可达解的数量。

> Java/C++ 使用了辅助变量 `res` 统计可达解数量; Python 直接返回 Set 的元素数 `len(visited)` 即可。

<![Picture22.png](https://pic.leetcode-cn.com/1603024999-EKiknO-Picture22.png),![Picture23.png](https://pic.leetcode-cn.com/1603024999-hEnxrs-Picture23.png),![Picture24.png](https://pic.leetcode-cn.com/1603024999-goUtpL-Picture24.png),![Picture25.png](https://pic.leetcode-cn.com/1603024999-BwmmIl-Picture25.png),![Picture26.png](https://pic.leetcode-cn.com/1603024999-bQyxbG-Picture26.png),![Picture27.png](https://pic.leetcode-cn.com/1603024999-tjBCbi-Picture27.png),![Picture28.png](https://pic.leetcode-cn.com/1603024999-MBLwqu-Picture28.png),![Picture29.png](https://pic.leetcode-cn.com/1603024999-NYKszu-Picture29.png),![Picture30.png](https://pic.leetcode-cn.com/1603024999-aMYSTi-Picture30.png)>

### 代码:

> Java/C++ 代码中 `visited` 为辅助矩阵,Python 中为 Set 。

```Python []
class Solution:
    def wardrobeFinishing(self, m: int, n: int, cnt: int) -> int:
        queue, visited = [(0, 0, 0, 0)], set()
        while queue:
            i, j, si, sj = queue.pop(0)
            if i >= m or j >= n or cnt < si + sj or (i, j) in visited: continue
            visited.add((i,j))
            queue.append((i + 1, j, si + 1 if (i + 1) % 10 else si - 8, sj))
            queue.append((i, j + 1, si, sj + 1 if (j + 1) % 10 else sj - 8))
        return len(visited)
```

```Java []
class Solution {
    public int wardrobeFinishing(int m, int n, int cnt) {
        boolean[][] visited = new boolean[m][n];
        int res = 0;
        Queue<int[]> queue= new LinkedList<int[]>();
        queue.add(new int[] { 0, 0, 0, 0 });
        while(queue.size() > 0) {
            int[] x = queue.poll();
            int i = x[0], j = x[1], si = x[2], sj = x[3];
            if(i >= m || j >= n || cnt < si + sj || visited[i][j]) continue;
            visited[i][j] = true;
            res ++;
            queue.add(new int[] { i + 1, j, (i + 1) % 10 != 0 ? si + 1 : si - 8, sj });
            queue.add(new int[] { i, j + 1, si, (j + 1) % 10 != 0 ? sj + 1 : sj - 8 });
        }
        return res;
    }
}
```

```C++ []
class Solution {
public:
    int wardrobeFinishing(int m, int n, int cnt) {
        vector<vector<bool>> visited(m, vector<bool>(n, 0));
        int res = 0;
        queue<vector<int>> que;
        que.push({ 0, 0, 0, 0 });
        while(que.size() > 0) {
            vector<int> x = que.front();
            que.pop();
            int i = x[0], j = x[1], si = x[2], sj = x[3];
            if(i >= m || j >= n || cnt < si + sj || visited[i][j]) continue;
            visited[i][j] = true;
            res++;
            que.push({ i + 1, j, (i + 1) % 10 != 0 ? si + 1 : si - 8, sj });
            que.push({ i, j + 1, si, (j + 1) % 10 != 0 ? sj + 1 : sj - 8 });
        }
        return res;
    }
};
```

### 复杂度分析:

> 设矩阵行列数分别为 $M, N$ 。

- **时间复杂度 $O(MN)$ :** 最差情况下,机器人遍历矩阵所有单元格,此时时间复杂度为 $O(MN)$ 。
- **空间复杂度 $O(MN)$ :** 最差情况下,Set `visited` 内存储矩阵所有单元格的索引,使用 $O(MN)$ 的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 131. 砍竹子 I.md
================================================
## 解题思路:

设将长度为 $n$ 的竹子切为 $a$ 段:

$$
n = n_1 + n_2 + ... + n_a
$$

本题等价于求解:

$$
\max(n_1 \times n_2 \times ... \times n_a)
$$

> 以下数学推导总体分为两步:(1) 当所有绳段长度相等时,乘积最大。(2) 最优的绳段长度为 $3$ 。

### 数学推导:

以下公式为“算术几何均值不等式” ,等号当且仅当 $n_1 = n_2 = ... = n_a$ 时成立。

$$
\frac{n_1 + n_2 + ... + n_a}{a} \geq \sqrt[a]{n_1 n_2 ... n_a}
$$

> **推论一:** 将竹子 **以相等的长度等分为多段** ,得到的乘积最大。

设将竹子按照 $x$ 长度等分为 $a$ 段,即 $n = ax$ ,则乘积为 $x^a$ 。观察以下公式,由于 $n$ 为常数,因此当 $x^{\frac{1}{x}}$ 取最大值时, 乘积达到最大值。

$$
x^a = x^{\frac{n}{x}} = (x^{\frac{1}{x}})^n
$$

根据分析,可将问题转化为求 $y = x^{\frac{1}{x}}$ 的极大值,因此对 $x$ 求导数。

$$
\begin{aligned}
 \ln y & = \frac{1}{x} \ln x & \text{取对数} \\
 \frac{1}{y} \dot {y} & = \frac{1}{x^2} - \frac{1}{x^2} \ln x & \text{对 $x$ 求导} \\
 & = \frac{1 - \ln x}{x^2} \\
 \dot {y} & = \frac{1 - \ln x}{x^2} x^{\frac{1}{x}} & \text{整理得}
\end{aligned}
$$

令 $\dot {y} = 0$ ,则 $1 - \ln x = 0$ ,易得驻点为 $x_0 = e \approx 2.7$ ;根据以下公式,可知 $x_0$ 为极大值点。

$$
\dot {y}
\begin{cases}
 > 0 & , x \in [- \infty, e) \\
 < 0 & , x \in (e, \infty] \\
\end{cases}
$$

由于切分长度 $x$ 必须为整数,最接近 $e$ 的整数为 $2$ 或 $3$ 。如下式所示,代入 $x = 2$ 和 $x = 3$ ,得出 $x = 3$ 时,乘积达到最大。

$$
y(3) = 3^{1/3} \approx 1.44 \\
y(2) = 2^{1/2} \approx 1.41
$$

口算对比方法:给两数字同时取 $6$ 次方,再对比。

$$
y(3)^6 = (3^{1/3})^6 = 9 \\
y(2)^6 = (2^{1/2})^6 = 8
$$

> **推论二:** 尽可能将竹子以长度 $3$ 等分为多段时,乘积最大。

### 切分规则:

1. **最优:** $3$ 。把竹子尽可能切为多个长度为 $3$ 的片段,留下的最后一段竹子的长度可能为 $0,1,2$ 三种情况。
2. **次优:** $2$ 。若最后一段竹子长度为 $2$ ;则保留,不再拆为 $1+1$ 。
3. **最差:** $1$ 。若最后一段竹子长度为 $1$ ;则应把一份 $3 + 1$ 替换为 $2 + 2$,因为 $2 \times 2 > 3 \times 1$。

### 算法流程:

1. 当 $n \leq 3$ 时,按照规则应不切分,但由于题目要求必须剪成 $m>1$ 段,因此必须剪出一段长度为 $1$ 的竹子,即返回 $n - 1$ 。
2. 当 $n>3$ 时,求 $n$ 除以 $3$ 的 整数部分 $a$ 和 余数部分 $b$ (即 $n = 3a + b$ ),并分为以下三种情况:
    - 当 $b = 0$ 时,直接返回 $3^a$;
    - 当 $b = 1$ 时,要将一个 $1 + 3$ 转换为 $2+2$,因此返回 $3^{a-1} \times 4$;
    - 当 $b = 2$ 时,返回 $3^a \times 2$。

![Picture1.png](https://pic.leetcode-cn.com/1f9adeaa7b9fff0ab19c9d29e3a8f98749011d22dc162d67bdbe223f1a38119f-Picture1.png){:align=center width=600}

## 代码:

> Python 中常见有三种幂计算函数: **`*`** 和 **`pow()`** 的时间复杂度均为 $O(\log a)$ ;而 **`math.pow()`** 始终调用 C 库的 `pow()` 函数,其执行浮点取幂,时间复杂度为 $O(1)$ 。

```Python []
class Solution:
    def cuttingBamboo(self, bamboo_len: int) -> int:
        if bamboo_len <= 3: return bamboo_len - 1
        a, b = bamboo_len // 3, bamboo_len % 3
        if b == 0: return int(math.pow(3, a))
        if b == 1: return int(math.pow(3, a - 1) * 4)
        return int(math.pow(3, a) * 2)
```

```Java []
class Solution {
    public int cuttingBamboo(int bamboo_len) {
        if(bamboo_len <= 3) return bamboo_len - 1;
        int a = bamboo_len / 3, b = bamboo_len % 3;
        if(b == 0) return (int)Math.pow(3, a);
        if(b == 1) return (int)Math.pow(3, a - 1) * 4;
        return (int)Math.pow(3, a) * 2;
    }
}
```

```C++ []
class Solution {
public:
    int cuttingBamboo(int bamboo_len) {
        if(bamboo_len <= 3) return bamboo_len - 1;
        int a = bamboo_len / 3, b = bamboo_len % 3;
        if(b == 0) return pow(3, a);
        if(b == 1) return pow(3, a - 1) * 4;
        return pow(3, a) * 2;
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(1)$ :** 仅有求整、求余、次方运算。
  - [求整和求余运算](https://stackoverflow.com/questions/35189851/time-complexity-of-modulo-operator-in-python):资料提到不超过机器数的整数可以看作是 $O(1)$ ;
  - [幂运算](https://stackoverflow.com/questions/32418731/java-math-powa-b-time-complexity):查阅资料,提到浮点取幂为 $O(1)$ 。
- **空间复杂度 $O(1)$ :** 变量 `a` 和 `b` 使用常数大小额外空间。

## 贪心思路:

数学推导需要一定的知识基础,贪心算法的思路更加适合快速解题。

> 设一竹子长度为 $n$ ( $n>1$ ),则其必可被切分为两段 $n=n_1+n_2$ 。
> 根据经验推测,切分的两数字乘积往往原数字更大,即往往有 $n_1 \times n_2 > n_1 + n_2 = n$ 。
>
> - **例如竹子长度为 $6$ :**  $6 = 3 + 3 < 3 \times 3 = 9$ ;
> - **也有少数反例,例如 $2$ :** $2 = 1 + 1 > 1 \times 1 = 1$ 。

- **推论一:** 合理的切分方案可以带来更大的乘积。

> 设一竹子长度为 $n$ ( $n>1$ ),**切分为两段** $n=n_1+n_2$ ,**切分为三段** $n=n_1+n_2+n_3$ 。
> 根据经验推测,**三段** 的乘积往往更大,即往往有 $n_1 n_2 n_3 > n_1 n_2$ 。
>
> - **例如竹子长度为 $9$ :** 两段 $9=4+5$ 和 三段 $9=3+3+3$,则有 $4 \times 5 < 3 \times 3 \times 3$ 。
> - **也有少数反例,例如 $6$ :** 两段 $6=3+3$ 和 三段 $6=2+2+2$,则有 $3 \times 3 > 2 \times 2 \times 2$ 。

- **推论二:** 若切分方案合理,竹子段切分的越多,乘积越大。

> 总体上看,貌似长竹子切分为越多段乘积越大,但其实到某个长度分界点后,乘积到达最大值,就不应再切分了。
> **问题转化:** 是否有**优先级最高的长度** $x$ 存在?若有,则应该尽可能把竹子以 $x$ 长度切为多段,以获取最大乘积。

- **推论三:** 为使乘积最大,只有长度为 $2$ 和 $3$ 的竹子不应再切分,且 $3$ 比 $2$ 更优 *(详情见下表)* 。

| 竹子切分方案  | 乘积                                       | 结论                                                              |
| ------------- | ------------------------------------------ | ----------------------------------------------------------------- |
| $2 = 1 + 1$   | $1 \times 1 = 1$                           | $2$ 不应切分                                                      |
| $3=1+2$       | $1 \times 2 = 2$                           | $3$ 不应切分                                                      |
| $4=2+2=1+3$   | $2 \times 2 = 4 > 1 \times 3 = 3$          | $4$ 和 $2$ 等价,且 $2+2$ 比 $1+3$ 更优                           |
| $5=2+3=1+4$   | $2 \times 3 = 6 > 1 \times 4 = 4$          | $5$ 应切分为 $2+3$                                                |
| $6=3+3=2+2+2$ | $3 \times 3 = 9 > 2 \times 2 \times 2 = 8$ | $6$ 应切分为 $3+3$ ,进而**推出 $3$ 比 $2$ 更优**                 |
| $>7$          | ...                                        | **长绳**(长度>7)可转化为多个**短绳**(长度1~6),因此肯定应切分 |


================================================
FILE: leetbook_ioa/docs/LCR 132. 砍竹子 II.md
================================================
## 解题思路:

> 切分规则的推导流程请见上一题「砍竹子 I」。

### 切分规则:

1. **最优:** $3$ 。把竹子尽可能切为多个长度为 $3$ 的片段,留下的最后一段竹子的长度可能为 $0,1,2$ 三种情况。
2. **次优:** $2$ 。若最后一段竹子长度为 $2$ ;则保留,不再拆为 $1+1$ 。
3. **最差:** $1$ 。若最后一段竹子长度为 $1$ ;则应把一份 $3 + 1$ 替换为 $2 + 2$,因为 $2 \times 2 > 3 \times 1$。

### 算法流程:

1. 当 $n \leq 3$ 时,按照规则应不切分,但由于题目要求必须剪成 $m>1$ 段,因此必须剪出一段长度为 $1$ 的竹子,即返回 $n - 1$ 。
2. 当 $n>3$ 时,求 $n$ 除以 $3$ 的 整数部分 $a$ 和 余数部分 $b$ (即 $n = 3a + b$ ),并分为以下三种情况(设求余操作符号为 "$\odot$" ):
    - 当 $b = 0$ 时,直接返回 $3^a \odot 1000000007$;
    - 当 $b = 1$ 时,要将一个 $1 + 3$ 转换为 $2+2$,因此返回 $(3^{a-1} \times 4)\odot 1000000007$;
    - 当 $b = 2$ 时,返回 $(3^a \times 2) \odot 1000000007$。

![Picture1.png](https://pic.leetcode-cn.com/1f9adeaa7b9fff0ab19c9d29e3a8f98749011d22dc162d67bdbe223f1a38119f-Picture1.png){:align=center width=600}

### 大数求余解法:

**大数越界:** 当 $a$ 增大时,最后返回的 $3^a$ 大小以指数级别增长,可能超出 `int32` 甚至 `int64` 的取值范围,导致返回值错误。
**大数求余问题:** 在仅使用 `int32` 类型存储的前提下,正确计算 $x^a$ 对 $p$ 求余(即 $x^a \odot p$ )的值。
**解决方案:** *循环求余* 、 *快速幂求余* ,其中后者的时间复杂度更低,两种方法均基于以下求余运算规则推出:

$$
(xy) \odot p = [(x \odot p)(y \odot p)] \odot p
$$

### 1. 循环求余:

根据求余运算性质推出(∵ 本题中 $x<p$,∴ $x \odot p = x$ ):

$$
x^a \odot p = [(x ^{a-1} \odot p)(x \odot p)] \odot p=[(x ^{a-1} \odot p)x] \odot p
$$

利用此公式,可通过循环操作依次求 $x^1, x^2, ..., x^{a-1}, x^a$ 对 $p$ 的余数,保证每轮中间值 `rem` 都在 `int32` 取值范围中。封装方法代码如下所示。

```Python []
# 求 (x^a) % p —— 循环求余法
def remainder(x, a, p):
    rem = 1
    for _ in range(a):
        rem = (rem * x) % p
    return rem
```

**时间复杂度 $O(N)$ :** 其中 $N=a$ ,即循环的线性复杂度。

### 2. 快速幂求余:

根据求余运算性质可推出:

$$
x^a \odot p = (x^2)^{a/2} \odot p = (x^2 \odot p)^{a / 2} \odot p
$$

当 $a$ 为奇数时 $a/2$ 不是整数,因此分为以下两种情况( ''$//$'' 代表向下取整的除法):

$$
{x^a \odot p = }
\begin{cases}
(x^2 \odot p)^{a // 2} \odot p &  \text{, $a$ 为偶数} \\
{[(x \odot p)(x ^{a-1} \odot p)] \odot p = [x(x^2 \odot p)^{a//2}] \odot p} & \text{, $a$ 为奇数} \\
\end{cases}
$$

**解析:** 利用以上公式,可通过循环操作每次把指数 $a$ 问题降低至指数 $a//2$ 问题,只需循环 $\log_2(N)$ 次,因此可将复杂度降低至对数级别。封装方法代码如下所示。

```Python []
# 求 (x^a) % p —— 快速幂求余
def remainder(x, a, p):
    rem = 1
    while a > 0:
        if a % 2: rem = (rem * x) % p
        x = x ** 2 % p
        a //= 2
    return rem
```

**帮助理解:** 根据下表, 初始状态 $rem=1$, $x=3$, $a=19$, $p=1000000007$ ,最后会将 $rem \times (x^a \odot p)$ 化为 $rem \times (x^0 \odot p) = rem \times 1$ 的形式,即 $rem$ 为余数答案。

| $n$ |                 $rem \times (x^a \odot p)$ | $rem_n=rem_{n-1} \times x_{n-1} \odot p$ |        $x_n=x_{n-1}^2 \odot p$ | $a_n=a_{n-1}//2$ |
| --- | -----------------------------------------: | ---------------------------------------: | -----------------------------: | :--------------: |
| $1$ |                $1 \times (3^{19} \odot p)$ |                                      $1$ |                            $3$ |       $19$       |
| $2$ |                 $3 \times (9^{9} \odot p)$ |                      $3=1\times3\odot p$ |                $9=3^2 \odot p$ |    $9=19//2$     |
| $3$ |               $27 \times (81^{4} \odot p)$ |                $27 = 3 \times 9 \odot p$ |                $81=9^2\odot p$ |     $4=9//2$     |
| $4$ |             $27 \times (6561^{2} \odot p)$ |                                     $27$ |            $6561=81^2 \odot p$ |     $2=4//2$     |
| $5$ |         $27 \times (43046721^{1} \odot p)$ |                                     $27$ |      $43046721=6561^2 \odot p$ |     $1=2//2$     |
| $6$ | $162261460 \times (175880701^{0} \odot p)$ |   $162261460=27 \times 43046721 \odot p$ | $175880701=43046721^2 \odot p$ |     $0=1//2$     |

## 代码:

**Python 代码:** 由于语言特性,理论上 Python 中的变量取值范围由系统内存大小决定(无限大),因此在 Python 中其实不用考虑大数越界问题。
**Java/C++ 代码:** 根据二分法计算原理,至少要保证变量 `x` 和 `rem` 可以正确存储 $1000000007^2$ ,而 $2^{64} > 1000000007^2 > 2^{32}$ ,因此我们选取 `long` 类型。

```Python []
class Solution:
    def cuttingBamboo(self, bamboo_len: int) -> int:
        if bamboo_len <= 3: return bamboo_len - 1
        a, b, p, x, rem = bamboo_len // 3 - 1, bamboo_len % 3, 1000000007, 3 , 1
        while a > 0:
            if a % 2: rem = (rem * x) % p
            x = x ** 2 % p
            a //= 2
        if b == 0: return (rem * 3) % p # = 3^(a+1) % p
        if b == 1: return (rem * 4) % p # = 3^a * 4 % p
        return (rem * 6) % p # = 3^(a+1) * 2 % p
```

```Java []
class Solution {
    public int cuttingBamboo(int bamboo_len) {
        if(bamboo_len <= 3) return bamboo_len - 1;
        int b = bamboo_len % 3, p = 1000000007;
        long rem = 1, x = 3;
        for(int a = bamboo_len / 3 - 1; a > 0; a /= 2) {
            if(a % 2 == 1) rem = (rem * x) % p;
            x = (x * x) % p;
        }
        if(b == 0) return (int)(rem * 3 % p);
        if(b == 1) return (int)(rem * 4 % p);
        return (int)(rem * 6 % p);
    }
}
```

```C++ []
class Solution {
public:
    int cuttingBamboo(int bamboo_len) {
        if(bamboo_len <= 3) return bamboo_len - 1;
        int b = bamboo_len % 3, p = 1000000007;
        long rem = 1, x = 3;
        for(int a = bamboo_len / 3 - 1; a > 0; a /= 2) {
            if(a % 2 == 1) rem = (rem * x) % p;
            x = (x * x) % p;
        }
        if(b == 0) return (int)(rem * 3 % p);
        if(b == 1) return (int)(rem * 4 % p);
        return (int)(rem * 6 % p);
    }
};
```

```Python []
# 由于语言特性,Python 可以不考虑大数越界问题
class Solution:
    def cuttingBamboo(self, bamboo_len: int) -> int:
        if bamboo_len <= 3: return bamboo_len - 1
        a, b, p = bamboo_len // 3, bamboo_len % 3, 1000000007
        if b == 0: return 3 ** a % p
        if b == 1: return 3 ** (a - 1) * 4 % p
        return 3 ** a * 2 % p
```

### 复杂度分析:

> 以下为 **二分求余法** 的复杂度。

- **时间复杂度 $O(\log N)$ :** 其中 $N=a$ ,二分法为对数级别复杂度,每轮仅有求整、求余、次方运算。
  - [求整和求余运算](https://stackoverflow.com/questions/35189851/time-complexity-of-modulo-operator-in-python):资料提到不超过机器数的整数可以看作是 $O(1)$ ;
  - [幂运算](https://stackoverflow.com/questions/32418731/java-math-powa-b-time-complexity):查阅资料,提到浮点取幂为 $O(1)$ 。
- **空间复杂度 $O(1)$ :** 变量 `a, b, p, x, rem` 使用常数大小额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 133. 位 1 的个数.md
================================================
## 方法一:逐位判断

根据 **与运算** 定义,设二进制数字 $n$ ,则有:

- 若 $n \& 1 = 0$ ,则 $n$ 二进制 **最右一位** 为 $0$ ;
- 若 $n \& 1 = 1$ ,则 $n$ 二进制 **最右一位** 为 $1$ 。

根据以上特点,考虑以下 **循环判断** :

1. 判断 $n$ 最右一位是否为 $1$ ,根据结果计数。
2. 将 $n$ 右移一位(本题要求把数字 $n$ 看作无符号数,因此使用 **无符号右移** 操作)。

### 算法流程:

1. 初始化数量统计变量 $res = 0$ 。
2. 循环逐位判断: 当 $n = 0$ 时跳出。
   1. **`res += n & 1` :** 若 $n \& 1 = 1$ ,则统计数 $res$ 加一。
   2. **`n >>= 1` :** 将二进制数字 $n$ 无符号右移一位( Java 中无符号右移为 "$>>>$" ) 。
3. 返回统计数量 $res$ 。

<![Picture2.png](https://pic.leetcode-cn.com/196a1e24f89c3291d8462f1a2bdab87dde8590d4c04d964d503db8dcaf5fda72-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/4f4d43ed85b87c9dba12e0b3f3f3a8760f90e8e23d33d19ebabb3ad3c8149897-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/8f054e5ba19053365563577f339343bb635591381b1d8c950624bd9390309c71-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/20f8471b079eaa94d0f09b7627c94e64f541b85f660d3f20b14fd2fa1e3b1f92-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/6312b1569a40d74174f0c31fcfb8cc9836e0c2ab6c0ade144ab74f009ae0560d-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/eee12d1995aa0aa24757dcb10e1c8829ef72f685aa3baad74bf001d9f8cd7e54-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/9f734c501f50afaaee0d9ea0fe3c42f3af68eaaff1c9c5563295bbe1ac2a3110-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/ad1934398b309e369cbaa83f21a88a672ae9025460a3c93ec94439574620e1de-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/aae3da9131792c0103f9b24b35abebadb30b47d92441c5927546036066e5614b-Picture10.png)>

### 代码:

```Python []
class Solution:
    def hammingWeight(self, n: int) -> int:
        res = 0
        while n:
            res += n & 1
            n >>= 1
        return res
```

```Java []
public class Solution {
    public int hammingWeight(int n) {
        int res = 0;
        while(n != 0) {
            res += n & 1;
            n >>>= 1;
        }
        return res;
    }
}
```

```C++ []
class Solution {
public:
    int hammingWeight(uint32_t n) {
        unsigned int res = 0; // c++ 使用无符号数
        while(n != 0) {
            res += n & 1;
            n >>= 1;
        }
        return res;
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(\log_2 n)$ :** 此算法循环内部仅有 **移位、与、加** 等基本运算,占用 $O(1)$ ;逐位判断需循环 $log_2 n$ 次,其中 $\log_2 n$ 代表数字 $n$ 最高位 $1$ 的所在位数(例如 $\log_2 4 = 2$, $\log_2 16 = 4$)。
- **空间复杂度 $O(1)$ :** 变量 $res$ 使用常数大小额外空间。

## 方法二:巧用 $n \& (n - 1)$

- **$(n - 1)$ 解析:** 二进制数字 $n$ 最右边的 $1$ 变成 $0$ ,此 $1$ 右边的 $0$ 都变成 $1$ 。
- **$n \& (n - 1)$ 解析:** 二进制数字 $n$ 最右边的 $1$ 变成 $0$ ,其余不变。

![Picture1.png](https://pic.leetcode-cn.com/f23d9ef4fcfd65d7fbe29e477cbf36110b2f34558020e8cff09a1e13c0275c43-Picture1.png){:align=center width=450}

### 算法流程:

1. 初始化数量统计变量 $res$ 。
2. 循环消去最右边的 $1$ :当 $n = 0$ 时跳出。
   1. **`res += 1` :** 统计变量加 $1$ ;
   2. **`n &= n - 1` :** 消去数字 $n$ 最右边的 $1$ 。
3. 返回统计数量 $res$ 。

<![Picture11.png](https://pic.leetcode-cn.com/d16a9a6cfdba918c655679373632afc8ddeaf9b64912aa1fbf7b57371736ccaa-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/a6c05d83742bdf0cc50f9e4f1cc05833b3fca1b33abad88cf82c30459964bfa1-Picture12.png),![Picture13.png](https://pic.leetcode-cn.com/19f7add30dac42e0785de28909579b0f961122cbfd673a44230b3a1c4fe89f80-Picture13.png),![Picture14.png](https://pic.leetcode-cn.com/016ca059d0eb893b9a5f1c0b3ff013ffbd42424f8cd0cc1f9a76624dcbd87c41-Picture14.png)>

### 代码:

```Python []
class Solution:
    def hammingWeight(self, n: int) -> int:
        res = 0
        while n:
            res += 1
            n &= n - 1
        return res
```

```Java []
public class Solution {
    public int hammingWeight(int n) {
        int res = 0;
        while(n != 0) {
            res++;
            n &= n - 1;
        }
        return res;
    }
}
```

```C++ []
class Solution {
public:
    int hammingWeight(uint32_t n) {
        int res = 0;
        while(n != 0) {
            res++;
            n &= n - 1;
        }
        return res;
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(M)$ :** $n \& (n - 1)$ 操作仅有减法和与运算,占用 $O(1)$ ;设 $M$ 为二进制数字 $n$ 中 $1$ 的个数,则需循环 $M$ 次(每轮消去一个 $1$ ),占用 $O(M)$ 。
- **空间复杂度 $O(1)$ :** 变量 $res$ 使用常数大小额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 134. Pow(x, n).md
================================================
## 解题思路:

求 $x^n$ 最简单的方法是通过循环将 $n$ 个 $x$ 乘起来,依次求 $x^1, x^2, ..., x^{n-1}, x^n$ ,时间复杂度为 $O(n)$ 。
**快速幂法** 可将时间复杂度降低至 $O(\log n)$ ,以下从 「分治法」 和 「二进制」 两个角度解析快速幂法。

### 快速幂解析(分治法角度):

> 快速幂实际上是分治思想的一种应用。

**二分推导:** $x^n = x^{n/2} \times x^{n/2} = (x^2)^{n/2}$ ,令 $n/2$ 为整数,则需要分为奇偶两种情况(设向下取整除法符号为 "$//$" ):

$$
x^n =
\begin{cases}
 (x^2)^{n//2} & , n 为偶数 \\
 x(x^2)^{n//2} & , n 为奇数  \\
\end{cases}
$$

> 观察发现,当 $n$ 为奇数时,二分后会多出一项 $x$ 。

**幂结果获取:**

- 根据推导,可通过循环 $x = x^2$ 操作,每次把幂从 $n$ 降至 $n//2$ ,直至将幂降为 $0$ ;
- 设 $res=1$ ,则初始状态 $x^n = x^n \times res$ 。在循环二分时,每当 $n$ 为奇数时,将多出的一项 $x$ 乘入 $res$ ,则最终可化至 $x^n = x^0 \times res = res$ ,返回 $res$ 即可。

![Picture2.png](https://pic.leetcode-cn.com/1599885604-YzlkAN-Picture2.png){:align=center width=500}

**转化为位运算:**

- 向下整除 $n // 2$  **等价于** 右移一位 $n >> 1$ ;
- 取余数 $n \mod 2$ **等价于** 判断二进制最右位 $n \& 1$ ;

### 快速幂解析(二进制角度):

> 利用十进制数字 $n$ 的二进制表示,可对快速幂进行数学化解释。

对于任何十进制正整数 $n$ ,设其二进制为 "$b_m...b_3b_2b_1$"( $b_i$ 为二进制某位值,$i \in [1,m]$ ),则有:

- **二进制转十进制:** $n = 1b_1 + 2b_2 + 4b_3 + ... + 2^{m-1}b_m$ *(即二进制转十进制公式)* ;
- **幂的二进制展开:** $x^n = x^{1b_1 + 2b_2 + 4b_3 + ... + 2^{m-1}b_m} = x^{1b_1}x^{2b_2}x^{4b_3}...x^{2^{m-1}b_m}$  ;

根据以上推导,可把计算 $x^n$ 转化为解决以下两个问题:

- **计算 $x^1, x^2, x^4, ..., x^{2^{m-1}}$ 的值:** 循环赋值操作 $x = x^2$ 即可;
- **获取二进制各位 $b_1, b_2, b_3, ..., b_m$ 的值:** 循环执行以下操作即可。
  1. **$n \& 1$ (与操作):** 判断 $n$ 二进制最右一位是否为 $1$ ;
  2. **$n>>1$  (移位操作):** $n$ 右移一位(可理解为删除最后一位)。

因此,应用以上操作,可在循环中依次计算 $x^{2^{0}b_1}, x^{2^{1}b_2}, ..., x^{2^{m-1}b_m}$ 的值,并将所有 $x^{2^{i-1}b_i}$ 累计相乘即可,其中:

$$
x^{2^{i-1}b_i}=
\begin{cases}
 1 & , b_i = 0 \\
 x^{2^{i-1}} & , b_i = 1 \\
\end{cases}
$$

![Picture1.png](https://pic.leetcode-cn.com/1599885604-yDzVYK-Picture1.png){:align=center width=500}

### 算法流程:

1. 当 $x = 0.0$ 时:直接返回 $0.0$ ,以避免后续 $1$ 除以 $0$ 操作报错。**分析:** 数字 $0$ 的正数次幂恒为 $0$ ;$0$ 的 $0$ 次幂和负数次幂没有意义,因此直接返回 $0.0$ 即可。
2. 初始化 $res = 1$ 。
3. 当 $n < 0$ 时:把问题转化至 $n \geq 0$ 的范围内,即执行 $x = 1/x$ ,$n = - n$ 。
4. 循环计算:当 $n = 0$ 时跳出。
   1. 当 $n \& 1 = 1$ 时:将当前 $x$ 乘入 $res$ (即 $res *= x$ )。
   2. 执行 $x = x^2$ (即 $x *= x$ )。
   3. 执行 $n$ 右移一位(即 $n >>= 1$)。
5. 返回 $res$ 。

## 代码:

Java 中 int32 变量区间 $n \in [-2147483648, 2147483647]$ ,因此当 $n = -2147483648$ 时执行 $n = -n$ 会因越界而赋值出错。解决方法是先将 $n$ 存入 long 变量 $b$ ,后面用 $b$ 操作即可。

```Python []
class Solution:
    def myPow(self, x: float, n: int) -> float:
        if x == 0.0: return 0.0
        res = 1
        if n < 0: x, n = 1 / x, -n
        while n:
            if n & 1: res *= x
            x *= x
            n >>= 1
        return res
```

```Java []
class Solution {
    public double myPow(double x, int n) {
        if(x == 0.0f) return 0.0d;
        long b = n;
        double res = 1.0;
        if(b < 0) {
            x = 1 / x;
            b = -b;
        }
        while(b > 0) {
            if((b & 1) == 1) res *= x;
            x *= x;
            b >>= 1;
        }
        return res;
    }
}
```

```C++ []
class Solution {
public:
    double myPow(double x, int n) {
        if(x == 0.0f) return 0.0;
        long b = n;
        double res = 1.0;
        if(b < 0) {
            x = 1 / x;
            b = -b;
        }
        while(b > 0) {
            if((b & 1) == 1) res *= x;
            x *= x;
            b >>= 1;
        }
        return res;
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(\log n)$ :** 二分的时间复杂度为对数级别。
- **空间复杂度 $O(1)$ :** $res$, $b$ 等变量占用常数大小额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 135. 报数.md
================================================
## 解题思路:

题目要求打印 “从 $1$ 至 $cnt$ 的数字” ,因此需考虑以下两个问题:

1. **最大的 $cnt$ 位数(记为 $end$ )和位数 $cnt$ 的关系:** 例如最大的 $1$ 位数是 $9$ ,最大的 $2$ 位数是 $99$ ,最大的 $3$ 位数是 $999$ 。则可推出公式:

$$
end = 10^{cnt} - 1
$$

2. **大数越界问题:** 当 $cnt$ 较大时,$end$ 会超出 $int32$ 整型的取值范围,超出取值范围的数字无法正常存储。但由于本题要求返回 int 类型数组,相当于默认所有数字都在 int32 整型取值范围内,因此不考虑大数越界问题。

因此,只需定义区间 $[1, 10^{cnt} - 1]$ 和步长 $1$ ,通过 $for$ 循环生成结果列表 $res$ 并返回即可。

### 代码:

```Python []
class Solution:
    def countNumbers(self, cnt: int) -> List[int]:
        res = []
        for i in range(1, 10 ** cnt):
            res.append(i)
        return res
```

```Java []
class Solution {
    public int[] countNumbers(int cnt) {
        int end = (int)Math.pow(10, cnt) - 1;
        int[] res = new int[end];
        for(int i = 0; i < end; i++)
            res[i] = i + 1;
        return res;
    }
}
```

利用 Python 的语言特性,可以简化代码:先使用 `range()` 方法生成可迭代对象,再使用 `list()` 方法转化为列表并返回即可。

```Python
class Solution:
    def countNumbers(self, cnt: int) -> List[int]:
        return list(range(1, 10 ** cnt))
```

### 复杂度分析:

- **时间复杂度 $O(10^{cnt})$ :** 生成长度为 $10^{cnt}$ 的列表需使用 $O(10^{cnt})$ 时间。
- **空间复杂度 $O(1)$ :** 建立列表需使用 $O(1)$ 大小的额外空间( 列表作为返回结果,不计入额外空间 )。

## 大数打印拓展:

实际上,本题的主要考点是大数越界情况下的打印。需要解决以下三个问题:

**1. 表示大数的变量类型:**

- 无论是 short / int / long ... 任意变量类型,数字的取值范围都是有限的。因此,大数的表示应用字符串 String 类型。

**2. 生成数字的字符串集:**

- 使用 int 类型时,每轮可通过 $+1$ 生成下个数字,而此方法无法应用至 String 类型。并且, String 类型的数字的进位操作效率较低,例如 `"9999"` 至 `"10000"` 需要从个位到千位循环判断,进位 4 次。
- 观察可知,生成的列表实际上是 $cnt$ 位 $0$ - $9$ 的 **全排列** ,因此可避开进位操作,通过递归生成数字的 String 列表。

**3. 递归生成全排列:**

- 基于分治算法的思想,先固定高位,向低位递归,当个位已被固定时,添加数字的字符串。例如当 $cnt = 2$ 时(数字范围 $1 - 99$ ),固定十位为 $0$ - $9$ ,按顺序依次开启递归,固定个位 $0$ - $9$ ,终止递归并添加数字字符串。

> 下图中的 `n` 对应本题中的 `cnt` 。

![Picture1.png](https://pic.leetcode-cn.com/83f4b5930ddc1d42b05c724ea2950ee7f00427b11150c86b45bd88405f8c7c87-Picture1.png){:align=center width=500}

根据以上方法,可初步编写全排列代码:

```Python []
class Solution:
    def countNumbers(self, cnt: int) -> [int]:
        def dfs(x):
            if x == cnt: # 终止条件:已固定完所有位
                res.append(''.join(num)) # 拼接 num 并添加至 res 尾部
                return
            for i in range(10): # 遍历 0 - 9
                num[x] = str(i) # 固定第 x 位为 i
                dfs(x + 1) # 开启固定第 x + 1 位
        
        num = ['0'] * cnt # 起始数字定义为 cnt 个 0 组成的字符列表
        res = [] # 数字字符串列表
        dfs(0) # 开启全排列递归
        return ','.join(res)  # 拼接所有数字字符串,使用逗号隔开,并返回
```

```Java []
class Solution {
    StringBuilder res;
    int count = 0, cnt;
    char[] num, loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    public String countNumbers(int cnt) {
        this.cnt = cnt;
        res = new StringBuilder(); // 数字字符串集
        num = new char[cnt]; // 定义长度为 cnt 的字符列表
        dfs(0); // 开启全排列递归
        res.deleteCharAt(res.length() - 1); // 删除最后多余的逗号
        return res.toString(); // 转化为字符串并返回
    }
    void dfs(int x) {
        if(x == cnt) { // 终止条件:已固定完所有位
            res.append(String.valueOf(num) + ","); // 拼接 num 并添加至 res 尾部,使用逗号隔开
            return;
        }
        for(char i : loop) { // 遍历 ‘0‘ - ’9‘
            num[x] = i; // 固定第 x 位为 i
            dfs(x + 1); // 开启固定第 x + 1 位
        }
    }
}
```

在此方法下,各数字字符串被逗号隔开,共同组成长字符串。返回的数字集字符串如下所示:

```yaml
输入:n = 1
输出:"0,1,2,3,4,5,6,7,8,9"

输入:n = 2
输出:"00,01,02,...,10,11,12,...,97,98,99"

输入:n = 3
输出:"000,001,002,...,100,101,102,...,997,998,999"
```

观察可知,当前的生成方法仍有以下问题:

1. 诸如 $00, 01, 02, \cdots$ 应显示为 $0, 1, 2, \cdots$ ,即应 **删除高位多余的 $0$** ;
2. 此方法从 $0$ 开始生成,而题目要求 **列表从 $1$ 开始** ;

以上两个问题的解决方法如下:

**1. 删除高位多余的 $0$ :**

- **字符串左边界定义:** 声明变量 $start$ 规定字符串的左边界,以保证添加的数字字符串 `num[start:]` 中无高位多余的 $0$ 。例如当 $cnt = 2$ 时,$1 - 9$ 时 $start = 1$ ,$10 - 99$ 时 $start = 0$ 。

- **左边界 $start$ 变化规律:** 观察可知,当输出数字的所有位都是 $9$ 时,则下个数字需要向更高位进 $1$ ,此时左边界 $start$ 需要减 $1$ (即高位多余的 $0$ 减少一个)。例如当 $cnt = 3$ (数字范围 $1 - 999$ )时,左边界 $start$ 需要减 $1$ 的情况有: "009" 进位至 "010" , "099" 进位至 "100" 。设数字各位中 $9$ 的数量为 $nine$ ,所有位都为 $9$ 的判断条件可用以下公式表示:

$$
cnt - start = nine
$$

- **统计 $nine$ 的方法:** 固定第 $x$ 位时,当 $i = 9$ 则执行 $nine = nine + 1$ ,并在回溯前恢复 $nine = nine - 1$ 。

**2. 列表从 $1$ 开始:**

- 在以上方法的基础上,添加数字字符串前判断其是否为 `"0"` ,若为 `"0"` 则直接跳过。

<![Picture2.png](https://pic.leetcode-cn.com/bb0fc4784a72a8faad53689b0990f81e4d05ec49944045ed8aa9135361c40900-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/97c09f1a09ecc9ecb4bd07e979a237b17fbd4d0df573f373a3870aa5ba9ee646-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/a5172aa7252a4faccbc784ace848cd6a22de5f12bd05a390684e11149a367d19-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/a39c50b23a277472678dfea21bdce694ea8fe1ba53cd88d539042dc79bded1c6-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/5141d4ee38c38126c5a4ee9180a7d3de3f78aef2df49e4219a5a7eb048bc6945-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/78503ed898575813a65c53d6af335e5ff6e21aaf8bfac3d8a47ff8b5b461c0a6-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/94c3fb5cc91bd94980d73d5c3f41b8a9c0e28621b30077dacc1477be09ea123c-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/0a75909b073c50769c09c9d0ab26fe9c74db406c52611b824b1cc04dae7a19ed-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/98054fcc5e43d84baba54224be52c5cd35b23fcc8dca3594e1068e6095f7b79a-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/ff49da44975c30a260e15136b21e21c3e615f077cd6a3ae923c077a1e0a485c5-Picture11.png)>

### 代码:

为 **正确表示大数** ,以下代码的返回值为数字字符串集拼接而成的长字符串。

```Python []
class Solution:
    def countNumbers(self, cnt: int) -> [int]:
        def dfs(x):
            if x == cnt:
                s = ''.join(num[self.start:])
                if s != '0': res.append(s)
                if cnt - self.start == self.nine: self.start -= 1
                return
            for i in range(10):
                if i == 9: self.nine += 1
                num[x] = str(i)
                dfs(x + 1)
            self.nine -= 1
        
        num, res = ['0'] * cnt, []
        self.nine = 0
        self.start = cnt - 1
        dfs(0)
        return ','.join(res)
```

```Java []
class Solution {
    StringBuilder res;
    int nine = 0, count = 0, start, cnt;
    char[] num, loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    public String countNumbers(int cnt) {
        this.cnt = cnt;
        res = new StringBuilder();
        num = new char[cnt];
        start = cnt - 1;
        dfs(0);
        res.deleteCharAt(res.length() - 1);
        return res.toString();
    }
    void dfs(int x) {
        if(x == cnt) {
            String s = String.valueOf(num).substring(start);
            if(!s.equals("0")) res.append(s + ",");
            if(cnt - start == nine) start--;
            return;
        }
        for(char i : loop) {
            if(i == '9') nine++;
            num[x] = i;
            dfs(x + 1);
        }
        nine--;
    }
}
```

本题要求输出 int 类型数组。为 **运行通过** ,可在添加数字字符串 $s$ 前,将其转化为 int 类型。代码如下所示:

```Python []
class Solution:
    def countNumbers(self, cnt: int) -> [int]:
        def dfs(x):
            if x == cnt:
                s = ''.join(num[self.start:])
                if s != '0': res.append(int(s))
                if cnt - self.start == self.nine: self.start -= 1
                return
            for i in range(10):
                if i == 9: self.nine += 1
                num[x] = str(i)
                dfs(x + 1)
            self.nine -= 1
        
        num, res = ['0'] * cnt, []
        self.nine = 0
        self.start = cnt - 1
        dfs(0)
        return res
```

```Java []
class Solution {
    int[] res;
    int nine = 0, count = 0, start, cnt;
    char[] num, loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    public int[] countNumbers(int cnt) {
        this.cnt = cnt;
        res = new int[(int)Math.pow(10, cnt) - 1];
        num = new char[cnt];
        start = cnt - 1;
        dfs(0);
        return res;
    }
    void dfs(int x) {
        if(x == cnt) {
            String s = String.valueOf(num).substring(start);
            if(!s.equals("0")) res[count++] = Integer.parseInt(s);
            if(cnt - start == nine) start--;
            return;
        }
        for(char i : loop) {
            if(i == '9') nine++;
            num[x] = i;
            dfs(x + 1);
        }
        nine--;
    }
}
```

### 复杂度分析:

- **时间复杂度 $O(10^{cnt})$ :** 递归的生成的排列的数量为 $10^{cnt}$ 。
- **空间复杂度 $O(10^{cnt})$ :** 结果列表 $res$ 的长度为 $10^{cnt} - 1$ ,各数字字符串的长度区间为 $1, 2, ..., cnt$ ,因此占用 $O(10^{cnt})$ 大小的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 136. 删除链表节点.md
================================================
## 解题思路:

本题删除值为 `val` 的节点分需为两步:定位节点、修改引用。

1. **定位节点:** 遍历链表,直到 `head.val == val` 时跳出,即可定位目标节点。
2. **修改引用:** 设节点 `cur` 的前驱节点为 `pre` ,后继节点为 `cur.next` ;则执行 `pre.next = cur.next` ,即可实现删除 `cur` 节点。

![Picture1.png](https://pic.leetcode-cn.com/1613757478-NBOvjn-Picture1.png){:align=center width=450}

### 算法流程:

1. **特例处理:** 当应删除头节点 `head` 时,直接返回 `head.next` 即可。
2. **初始化:** `pre = head` , `cur = head.next` 。
3. **定位节点:** 当 `cur` 为空 **或** `cur` 节点值等于 `val` 时跳出。
   1. 保存当前节点索引,即 `pre = cur` 。
   2. 遍历下一节点,即 `cur = cur.next` 。
4. **删除节点:** 若 `cur` 指向某节点,则执行 `pre.next = cur.next` ;若 `cur` 指向 $\text{null}$ ,代表链表中不包含值为 `val` 的节点。
5. **返回值:** 返回链表头部节点 `head` 即可。

<![Picture2.png](https://pic.leetcode-cn.com/1599417705-BpuWiY-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1599417705-RNAPbt-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1599417705-dIljCU-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1599417705-nRNZwN-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1599417705-XmugFY-Picture6.png)>

## 代码:

```Python []
class Solution:
    def deleteNode(self, head: ListNode, val: int) -> ListNode:
        if head.val == val: return head.next
        pre, cur = head, head.next
        while cur and cur.val != val:
            pre, cur = cur, cur.next
        if cur: pre.next = cur.next
        return head
```

```Java []
class Solution {
    public ListNode deleteNode(ListNode head, int val) {
        if(head.val == val) return head.next;
        ListNode pre = head, cur = head.next;
        while(cur != null && cur.val != val) {
            pre = cur;
            cur = cur.next;
        }
        if(cur != null) pre.next = cur.next;
        return head;
    }
}
```

```C++ []
class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        if(head->val == val) return head->next;
        ListNode *pre = head, *cur = head->next;
        while(cur != nullptr && cur->val != val) {
            pre = cur;
            cur = cur->next;
        }
        if(cur != nullptr) pre->next = cur->next;
        return head;
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(N)$ :** $N$ 为链表长度,删除操作平均需循环 $N/2$ 次,最差 $N$ 次。
- **空间复杂度 $O(1)$ :** `cur`, `pre` 占用常数大小额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 137. 模糊搜索验证.md
================================================
## 解题思路:

> 设 $s$ 的长度为 $n$ ,$p$ 的长度为 $m$ ;将 $s$ 的第 $i$ 个字符记为 $s_i$ ,$p$ 的第 $j$ 个字符记为 $p_j$ ,将 $s$ 的前 $i$ 个字符组成的子字符串记为 $s[:i]$ , 同理将 $p$ 的前 $j$ 个字符组成的子字符串记为 $p[:j]$ 。
>
> 因此,本题可转化为求 $s[:n]$ 是否能和  $p[:m]$ 匹配。

总体思路是从 $s[:1]$ 和 $p[:1]$ 是否能匹配开始判断,每轮添加一个字符并判断是否能匹配,直至添加完整个字符串 $s$ 和 $p$ 。展开来看,假设 $s[:i]$ 与  $p[:j]$ 可以匹配,那么下一状态有两种:

1. 添加一个字符 $s_{i+1}$ 后是否能匹配?
2. 添加字符 $p_{j+1}$ 后是否能匹配?

![Picture1.png](https://pic.leetcode-cn.com/1614516402-HyzAil-Picture1.png){:align=center width=500}

因此,本题的状态共有 $m \times n$ 种,应定义状态矩阵 $dp$ ,$dp[i][j]$ 代表 $s[:i]$ 与  $p[:j]$ 是否可以匹配。

做好状态定义,接下来就是根据  「`普通字符`」 ,  「`.`」 , 「`*`」三种字符的功能定义,分析出动态规划的转移方程。

### 动态规划解析:

**状态定义:** 设动态规划矩阵 `dp` ,`dp[i][j]` 代表字符串 `s` 的前 `i` 个字符和 `p` 的前 `j` 个字符能否匹配。

**转移方程:** 需要注意,由于 `dp[0][0]` 代表的是空字符的状态, 因此 `dp[i][j]` 对应的添加字符是 `s[i - 1]` 和 `p[j - 1]` 。

- 当 `p[j - 1] = '*'` 时,`dp[i][j]` 在当以下任一情况为 $\text{true}$ 时等于 $\text{true}$ :

  1. **`dp[i][j - 2]`:** 即将字符组合 `p[j - 2] *` 看作出现 0 次时,能否匹配;
  2. **`dp[i - 1][j]` 且 `s[i - 1] = p[j - 2]`:** 即让字符 `p[j - 2]` 多出现 1 次时,能否匹配;
  3. **`dp[i - 1][j]` 且 `p[j - 2] = '.'`:** 即让字符 `'.'` 多出现 1 次时,能否匹配;

- 当 `p[j - 1] != '*'` 时,`dp[i][j]` 在当以下任一情况为 $\text{true}$ 时等于 $\text{true}$ :

  1. **`dp[i - 1][j - 1]` 且 `s[i - 1] = p[j - 1]`:** 即让字符 `p[j - 1]` 多出现一次时,能否匹配;
  2. **`dp[i - 1][j - 1]` 且 `p[j - 1] = '.'`:** 即将字符 `.` 看作字符 `s[i - 1]` 时,能否匹配;

**初始化:** 需要先初始化 `dp` 矩阵首行,以避免状态转移时索引越界。

- **`dp[0][0] = true`:** 代表两个空字符串能够匹配。
- **`dp[0][j] = dp[0][j - 2]` 且 `p[j - 1] = '*'`:** 首行 `s` 为空字符串,因此当 `p` 的偶数位为 `*` 时才能够匹配(即让 `p` 的奇数位出现 0 次,保持 `p` 是空字符串)。因此,循环遍历字符串 `p` ,步长为 2(即只看偶数位)。

**返回值:** `dp` 矩阵右下角字符,代表字符串 `s` 和 `p` 能否匹配。

<![Picture2.png](https://pic.leetcode-cn.com/1614516402-hHLAeA-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1614516402-KnJpAF-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1614516402-MacqQq-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1614516402-rFRAGU-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1614516402-ATFWBt-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1614516402-OeJlxq-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1614516402-oqHduu-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1614516402-ETWYMx-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1614516402-NXXjya-Picture10.png),![Picture11.png](https://pic.leetcode-cn.com/1614516402-uMxtXN-Picture11.png),![Picture12.png](https://pic.leetcode-cn.com/1614516402-HHmdNJ-Picture12.png),![Picture13.png](https://pic.leetcode-cn.com/1614516402-bBdFaG-Picture13.png),![Picture14.png](https://pic.leetcode-cn.com/1614516402-EsgHuc-Picture14.png),![Picture15.png](https://pic.leetcode-cn.com/1614516402-YlyLPO-Picture15.png),![Picture16.png](https://pic.leetcode-cn.com/1614516402-VpcAnO-Picture16.png),![Picture17.png](https://pic.leetcode-cn.com/1614516402-CmmPpZ-Picture17.png),![Picture18.png](https://pic.leetcode-cn.com/1614516402-ibjjpB-Picture18.png),![Picture19.png](https://pic.leetcode-cn.com/1614516402-gBEUfu-Picture19.png)>

## 代码:

```Python []
class Solution:
    def articleMatch(self, s: str, p: str) -> bool:
        m, n = len(s) + 1, len(p) + 1
        dp = [[False] * n for _ in range(m)]
        dp[0][0] = True
        for j in range(2, n, 2):
            dp[0][j] = dp[0][j - 2] and p[j - 1] == '*'
        for i in range(1, m):
            for j in range(1, n):
                dp[i][j] = dp[i][j - 2] or dp[i - 1][j] and (s[i - 1] == p[j - 2] or p[j - 2] == '.') \
                           if p[j - 1] == '*' else \
                           dp[i - 1][j - 1] and (p[j - 1] == '.' or s[i - 1] == p[j - 1])
        return dp[-1][-1]
```

```Java []
class Solution {
    public boolean articleMatch(String s, String p) {
        int m = s.length() + 1, n = p.length() + 1;
        boolean[][] dp = new boolean[m][n];
        dp[0][0] = true;
        for(int j = 2; j < n; j += 2)
            dp[0][j] = dp[0][j - 2] && p.charAt(j - 1) == '*';
        for(int i = 1; i < m; i++) {
            for(int j = 1; j < n; j++) {
                dp[i][j] = p.charAt(j - 1) == '*' ?
                    dp[i][j - 2] || dp[i - 1][j] && (s.charAt(i - 1) == p.charAt(j - 2) || p.charAt(j - 2) == '.') :
                    dp[i - 1][j - 1] && (p.charAt(j - 1) == '.' || s.charAt(i - 1) == p.charAt(j - 1));
            }
        }
        return dp[m - 1][n - 1];
    }
}
```

```C++ []
class Solution {
public:
    bool articleMatch(string s, string p) {
        int m = s.size() + 1, n = p.size() + 1;
        vector<vector<bool>> dp(m, vector<bool>(n, false));
        dp[0][0] = true;
        for(int j = 2; j < n; j += 2)
            dp[0][j] = dp[0][j - 2] && p[j - 1] == '*';
        for(int i = 1; i < m; i++) {
            for(int j = 1; j < n; j++) {
                dp[i][j] = p[j - 1] == '*' ?
                    dp[i][j - 2] || dp[i - 1][j] && (s[i - 1] == p[j - 2] || p[j - 2] == '.'):
                    dp[i - 1][j - 1] && (p[j - 1] == '.' || s[i - 1] == p[j - 1]);
            }
        }
        return dp[m - 1][n - 1];
    }
};
```

以上代码利用布尔运算实现简短长度,若阅读不畅,可先理解以下代码,与文中内容一一对应:

```Python []
class Solution:
    def articleMatch(self, s: str, p: str) -> bool:
        m, n = len(s) + 1, len(p) + 1
        dp = [[False] * n for _ in range(m)]
        dp[0][0] = True
        # 初始化首行
        for j in range(2, n, 2):
            dp[0][j] = dp[0][j - 2] and p[j - 1] == '*'
        # 状态转移
        for i in range(1, m):
            for j in range(1, n):
                if p[j - 1] == '*':
                    if dp[i][j - 2]: dp[i][j] = True                              # 1.
                    elif dp[i - 1][j] and s[i - 1] == p[j - 2]: dp[i][j] = True   # 2.
                    elif dp[i - 1][j] and p[j - 2] == '.': dp[i][j] = True        # 3.
                else:
                    if dp[i - 1][j - 1] and s[i - 1] == p[j - 1]: dp[i][j] = True # 1.
                    elif dp[i - 1][j - 1] and p[j - 1] == '.': dp[i][j] = True    # 2.
        return dp[-1][-1]
```

```Java []
class Solution {
    public boolean articleMatch(String s, String p) {
        int m = s.length() + 1, n = p.length() + 1;
        boolean[][] dp = new boolean[m][n];
        dp[0][0] = true;
        // 初始化首行
        for(int j = 2; j < n; j += 2)
            dp[0][j] = dp[0][j - 2] && p.charAt(j - 1) == '*';
        // 状态转移
        for(int i = 1; i < m; i++) {
            for(int j = 1; j < n; j++) {
                if(p.charAt(j - 1) == '*') {
                    if(dp[i][j - 2]) dp[i][j] = true;                                            // 1.
                    else if(dp[i - 1][j] && s.charAt(i - 1) == p.charAt(j - 2)) dp[i][j] = true; // 2.
                    else if(dp[i - 1][j] && p.charAt(j - 2) == '.') dp[i][j] = true;             // 3.
                } else {
                    if(dp[i - 1][j - 1] && s.charAt(i - 1) == p.charAt(j - 1)) dp[i][j] = true;  // 1.
                    else if(dp[i - 1][j - 1] && p.charAt(j - 1) == '.') dp[i][j] = true;         // 2.
                }
            }
        }
        return dp[m - 1][n - 1];
    }
}
```

```C++ []
class Solution {
public:
    bool articleMatch(string s, string p) {
        int m = s.size() + 1, n = p.size() + 1;
        vector<vector<bool>> dp(m, vector<bool>(n, false));
        dp[0][0] = true;
        // 初始化首行
        for(int j = 2; j < n; j += 2)
            dp[0][j] = dp[0][j - 2] && p[j - 1] == '*';
        // 状态转移
        for(int i = 1; i < m; i++) {
            for(int j = 1; j < n; j++) {
                if(p[j - 1] == '*') {
                    if(dp[i][j - 2]) dp[i][j] = true;                              // 1.
                    else if(dp[i - 1][j] && s[i - 1] == p[j - 2]) dp[i][j] = true; // 2.
                    else if(dp[i - 1][j] && p[j - 2] == '.') dp[i][j] = true;      // 3.
                } else {
                    if(dp[i - 1][j - 1] && s[i - 1] == p[j - 1]) dp[i][j] = true;  // 1.
                    else if(dp[i - 1][j - 1] && p[j - 1] == '.') dp[i][j] = true;  // 2.
                }
            }
        }
        return dp[m - 1][n - 1];
    }
};
```

### 复杂度分析:

- **时间复杂度 $O(MN)$ :** 其中 $M, N$ 分别为 `s` 和 `p` 的长度,状态转移需遍历整个 `dp` 矩阵。
- **空间复杂度 $O(MN)$ :** 状态矩阵 `dp` 使用 $O(MN)$ 的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 138. 有效数字.md
================================================
## 解题思路:

本题使用有限状态自动机。根据字符类型和合法数值的特点,先定义状态,再画出状态转移图,最后编写代码即可。

**字符类型:**

空格 「   」、数字「 $0—9$ 」 、正负号 「 $+$, $-$ 」 、小数点 「 $.$ 」 、幂符号 「 $e$, $E$ 」 。

**状态定义:**

按照字符串从左到右的顺序,定义以下 9 种状态。

0. 开始的空格
1. 幂符号前的正负号
2. 小数点前的数字
3. 小数点、小数点后的数字
4. 当小数点前为空格时,小数点、小数点后的数字
5. 幂符号
6. 幂符号后的正负号
7. 幂符号后的数字
8. 结尾的空格

**结束状态:**

合法的结束状态有 2, 3, 7, 8 。

![Picture1.png](https://pic.leetcode-cn.com/1599283151-YmPMis-Picture1.png){:align=center width=650}

### 算法流程:

1. **初始化:**
   1. **状态转移表 `states` :** 设 `states[i]` ,其中 `i` 为所处状态,`states[i]` 使用哈希表存储可转移至的状态。键值对 `(key, value)` 含义:输入字符 `key` ,则从状态 `i` 转移至状态 `value` 。
   2. **当前状态 `p` :** 起始状态初始化为 `p = 0` 。

2. **状态转移循环:** 遍历字符串 `s` 的每个字符 `c` 。
   1. **记录字符类型 `t` :** 分为四种情况。
      - 当 `c` 为正负号时,执行 `t = 's'` ;
      - 当 `c` 为数字时,执行 `t = 'd'` ;
      - 当 `c` 为 `e` 或 `E` 时,执行 `t = 'e'` ;
      - 当 `c` 为 `.` 或 `空格` 时,执行 `t = c` (即用字符本身表示字符类型);
      - 否则,执行 `t = '?'` ,代表为不属于判断范围的非法字符,后续直接返回 $\text{false}$ 。
   2. **终止条件:** 若字符类型 `t` 不在哈希表 `states[p]` 中,说明无法转移至下一状态,因此直接返回 $\text{false}$ 。
   3. **状态转移:** 状态 `p` 转移至 `states[p][t]` 。

3. **返回值:** 跳出循环后,若状态 `p` $\in {2, 3, 7, 8}$ ,说明结尾合法,返回 $\text{true}$ ,否则返回 $\text{false}$ 。

<![Picture2.png](https://pic.leetcode-cn.com/1599283163-NYRJuG-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/1599283166-EeQMXb-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/1599283171-UsxiTn-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/1599283169-vZtZhA-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/1599283174-EjrKZh-Picture6.png),![Picture7.png](https://pic.leetcode-cn.com/1599283177-PHaNOb-Picture7.png),![Picture8.png](https://pic.leetcode-cn.com/1599283183-QAjXuu-Picture8.png),![Picture9.png](https://pic.leetcode-cn.com/1599283186-RNpWas-Picture9.png),![Picture10.png](https://pic.leetcode-cn.com/1599283190-JizpdM-Picture10.png)>

## 代码:

Java 的状态转移表 `states` 使用 Map[] 数组存储。

```Python []
class Solution:
    def validNumber(self, s: str) -> bool:
        states = [
            { ' ': 0, 's': 1, 'd': 2, '.': 4 }, # 0. start with 'blank'
            { 'd': 2, '.': 4 } ,                # 1. 'sign' before 'e'
            { 'd': 2, '.': 3, 'e': 5, ' ': 8 }, # 2. 'digit' before 'dot'
            { 'd': 3, 'e': 5, ' ': 8 },         # 3. 'digit' after 'dot'
            { 'd': 3 },                         # 4. 'digit' after 'dot' (‘blank’ before 'dot')
            { 's': 6, 'd': 7 },                 # 5. 'e'
            { 'd': 7 },                         # 6. 'sign' after 'e'
            { 'd': 7, ' ': 8 },                 # 7. 'digit' after 'e'
            { ' ': 8 }                          # 8. end with 'blank'
        ]
        p = 0                           # start with state 0
        for c in s:
            if '0' <= c <= '9': t = 'd' # digit
            elif c in "+-": t = 's'     # sign
            elif c in "eE": t = 'e'     # e or E
            elif c in ". ": t = c       # dot, blank
            else: t = '?'               # unknown
            if t not in states[p]: return False
            p = states[p][t]
        return p in (2, 3, 7, 8)
```

```Java []
class Solution {
    public boolean validNumber(String s) {
        Map[] states = {
            new HashMap<>() {{ put(' ', 0); put('s', 1); put('d', 2); put('.', 4); }}, // 0.
            new HashMap<>() {{ put('d', 2); put('.', 4); }},                           // 1.
            new HashMap<>() {{ put('d', 2); put('.', 3); put('e', 5); put(' ', 8); }}, // 2.
            new HashMap<>() {{ put('d', 3); put('e', 5); put(' ', 8); }},              // 3.
            new HashMap<>() {{ put('d', 3); }},                                        // 4.
            new HashMap<>() {{ put('s', 6); put('d', 7); }},                           // 5.
            new HashMap<>() {{ put('d', 7); }},                                        // 6.
            new HashMap<>() {{ put('d', 7); put(' ', 8); }},                           // 7.
            new HashMap<>() {{ put(' ', 8); }}                                         // 8.
        };
        int p = 0;
        char t;
        for(char c : s.toCharArray()) {
            if(c >= '0' && c <= '9') t = 'd';
            else if(c == '+' || c == '-') t = 's';
            else if(c == 'e' || c == 'E') t = 'e';
            else if(c == '.' || c == ' ') t = c;
            else t = '?';
            if(!states[p].containsKey(t)) return false;
            p = (int)states[p].get(t);
        }
        return p == 2 || p == 3 || p == 7 || p == 8;
    }
}
```

### 复杂度分析:

- **时间复杂度 $O(N)$ :** 其中 $N$ 为字符串 `s` 的长度,判断需遍历字符串,每轮状态转移的使用 $O(1)$ 时间。
- **空间复杂度 $O(1)$ :** `states` 和 `p` 使用常数大小的额外空间。


================================================
FILE: leetbook_ioa/docs/LCR 139. 训练计划 I.md
================================================
## 解题思路:

考虑定义双指针 $i$ , $j$ 分列数组左右两端,循环执行:

1. 指针 $i$ 从左向右寻找偶数;
2. 指针 $j$ 从右向左寻找奇数;
3. 将 偶数 $actions[i]$ 和 奇数 $actions[j]$ 交换。

可始终保证: 指针 $i$ 左边都是奇数,指针 $j$ 右边都是偶数 。

> 下图中的 `nums` 对应本题的 `actions` 。

![Picture1.png](https://pic.leetcode-cn.com/43e965485da89efa688947bc108232f10b65b5ba5c0dbd6a68227a82c7e451e4-Picture1.png){:align=center width=450}

### 算法流程:

1. **初始化:** $i$ , $j$ 双指针,分别指向数组 $actions$ 左右两端;
2. **循环交换:** 当 $i = j$ 时跳出;
   1. 指针 $i$ 遇到奇数则执行 $i = i + 1$ 跳过,直到找到偶数;
   2. 指针 $j$ 遇到偶数则执行 $j = j - 1$ 跳过,直到找到奇数;
   3. 交换 $actions[i]$ 和 $actions[j]$ 值;
3. **返回值:** 返回已修改的 $actions$ 数组。

<![Picture2.png](https://pic.leetcode-cn.com/da0888dfd73a7acd81e0e90589fe9d64f3505ea50bd5912b91d69a8da7198f34-Picture2.png),![Picture3.png](https://pic.leetcode-cn.com/d7f2d1d374e8c49a070d741ca7c56e07a79d7e4e956843c7743f57a836129b3b-Picture3.png),![Picture4.png](https://pic.leetcode-cn.com/df55f9254945072e0a2527c34557407a2543d60c1522bfc8a2455c156f4858cd-Picture4.png),![Picture5.png](https://pic.leetcode-cn.com/4d55b6e14518172f0a0b182bcb4fd2da1486ce25d9c73614e531786ed7f34901-Picture5.png),![Picture6.png](https://pic.leetcode-cn.com/dbe233642580b0cde66172b2016eeb8b0e5d68497d1397a718d8d269be52769d-Picture6.png),![Picture7.png](htt
Download .txt
gitextract_y7isvm8k/

├── .gitignore
├── LICENSE
├── README.md
├── leetbook_ioa/
│   └── docs/
│       ├── # 0 引言.md
│       ├── # 0.1 刷题建议.md
│       ├── # 0.2 题目分类.md
│       ├── # 1.1 数据结构简介.md
│       ├── # 1.2 算法复杂度.md
│       ├── # 1.3 时间复杂度.md
│       ├── # 1.4 空间复杂度.md
│       ├── # 11.1 动态规划解题框架.md
│       ├── # 7.1 排序算法简介.md
│       ├── # 7.2 冒泡排序.md
│       ├── # 7.3 快速排序.md
│       ├── # 7.4 归并排序.md
│       ├── LCR 120. 寻找文件副本.md
│       ├── LCR 121. 寻找目标值 - 二维数组.md
│       ├── LCR 122. 路径加密.md
│       ├── LCR 123. 图书整理 I.md
│       ├── LCR 124. 推理二叉树.md
│       ├── LCR 125. 图书整理 II.md
│       ├── LCR 126. 斐波那契数.md
│       ├── LCR 127. 跳跃训练.md
│       ├── LCR 128. 库存管理 I.md
│       ├── LCR 129. 字母迷宫.md
│       ├── LCR 130. 衣橱整理.md
│       ├── LCR 131. 砍竹子 I.md
│       ├── LCR 132. 砍竹子 II.md
│       ├── LCR 133. 位 1 的个数.md
│       ├── LCR 134. Pow(x, n).md
│       ├── LCR 135. 报数.md
│       ├── LCR 136. 删除链表节点.md
│       ├── LCR 137. 模糊搜索验证.md
│       ├── LCR 138. 有效数字.md
│       ├── LCR 139. 训练计划 I.md
│       ├── LCR 140. 训练计划 II.md
│       ├── LCR 141. 训练计划 III.md
│       ├── LCR 142. 训练计划 IV.md
│       ├── LCR 143. 子结构判断.md
│       ├── LCR 144. 翻转二叉树.md
│       ├── LCR 145. 判断对称二叉树.md
│       ├── LCR 146. 螺旋遍历二维数组.md
│       ├── LCR 147. 最小栈.md
│       ├── LCR 148. 验证图书取出顺序.md
│       ├── LCR 149. 彩灯装饰记录 I.md
│       ├── LCR 150. 彩灯装饰记录 II.md
│       ├── LCR 151. 彩灯装饰记录 III.md
│       ├── LCR 152. 验证二叉搜索树的后序遍历序列.md
│       ├── LCR 153. 二叉树中和为目标值的路径.md
│       ├── LCR 154. 随机链表的复制.md
│       ├── LCR 155. 将二叉搜索树转化为排序的双向链表.md
│       ├── LCR 156. 序列化与反序列化二叉树.md
│       ├── LCR 157. 套餐内商品的排列顺序.md
│       ├── LCR 158. 库存管理 II.md
│       ├── LCR 159. 库存管理 III.md
│       ├── LCR 160. 数据流中的中位数.md
│       ├── LCR 161. 连续天数的最高销售额.md
│       ├── LCR 162. 数字 1 的个数.md
│       ├── LCR 163. 找到第 k 位数字.md
│       ├── LCR 164. 破解闯关密码.md
│       ├── LCR 165. 解密数字.md
│       ├── LCR 166. 珠宝的最高价值.md
│       ├── LCR 167. 招式拆解 I.md
│       ├── LCR 168. 丑数.md
│       ├── LCR 169. 招式拆解 II.md
│       ├── LCR 170. 交易逆序对的总数.md
│       ├── LCR 171. 训练计划 V.md
│       ├── LCR 172. 统计目标成绩的出现次数.md
│       ├── LCR 173. 点名.md
│       ├── LCR 174. 寻找二叉搜索树中的目标节点.md
│       ├── LCR 175. 计算二叉树的深度.md
│       ├── LCR 176. 判断是否为平衡二叉树.md
│       ├── LCR 177. 撞色搭配.md
│       ├── LCR 178. 训练计划 VI.md
│       ├── LCR 179. 查找总价格为目标值的两个商品.md
│       ├── LCR 180. 文件组合.md
│       ├── LCR 181. 字符串中的单词反转.md
│       ├── LCR 182. 动态口令.md
│       ├── LCR 183. 望远镜中最高的海拔.md
│       ├── LCR 184. 设计自助结算系统.md
│       ├── LCR 185. 统计结果概率.md
│       ├── LCR 186. 文物朝代判断.md
│       ├── LCR 187. 破冰游戏.md
│       ├── LCR 188. 买卖芯片的最佳时机.md
│       ├── LCR 189. 设计机械累加器.md
│       ├── LCR 190. 加密运算.md
│       ├── LCR 191. 按规则计算统计结果.md
│       ├── LCR 192. 把字符串转换成整数 (atoi).md
│       ├── LCR 193. 求二叉搜索树的最近公共祖先.md
│       └── LCR 194. 寻找二叉树的最近公共祖先.md
├── selected_coding_interview/
│   ├── codes/
│   │   ├── cpp/
│   │   │   ├── include/
│   │   │   │   ├── ListNode.hpp
│   │   │   │   ├── PrintUtil.hpp
│   │   │   │   ├── TreeNode.hpp
│   │   │   │   └── include.hpp
│   │   │   ├── lc_101_symmetric_tree/
│   │   │   │   └── lc_101_symmetric_tree_s1.cpp
│   │   │   ├── lc_102_binary_tree_level_order_traversal/
│   │   │   │   └── lc_102_binary_tree_level_order_traversal_s1.cpp
│   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal/
│   │   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal_s1.cpp
│   │   │   │   └── lc_103_binary_tree_zigzag_level_order_traversal_s2.cpp
│   │   │   ├── lc_104_maximum_depth_of_binary_tree/
│   │   │   │   ├── lc_104_maximum_depth_of_binary_tree_s1.cpp
│   │   │   │   └── lc_104_maximum_depth_of_binary_tree_s2.cpp
│   │   │   ├── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal/
│   │   │   │   └── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal_s1.cpp
│   │   │   ├── lc_10_regular_expression_matching/
│   │   │   │   ├── lc_10_regular_expression_matching_s1.cpp
│   │   │   │   └── lc_10_regular_expression_matching_s2.cpp
│   │   │   ├── lc_110_balanced_binary_tree/
│   │   │   │   ├── lc_110_balanced_binary_tree_s1.cpp
│   │   │   │   └── lc_110_balanced_binary_tree_s2.cpp
│   │   │   ├── lc_113_path_sum_ii/
│   │   │   │   └── lc_113_path_sum_ii_s1.cpp
│   │   │   ├── lc_11_container_with_most_water/
│   │   │   │   └── lc_11_container_with_most_water_s1.cpp
│   │   │   ├── lc_121_best_time_to_buy_and_sell_stock/
│   │   │   │   └── lc_121_best_time_to_buy_and_sell_stock_s1.cpp
│   │   │   ├── lc_136_single_number/
│   │   │   │   └── lc_136_single_number_s1.cpp
│   │   │   ├── lc_138_copy_list_with_random_pointer/
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s1.cpp
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s2.cpp
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s3.cpp
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s4.cpp
│   │   │   │   └── lc_138_copy_list_with_random_pointer_s5.cpp
│   │   │   ├── lc_1480_running_sum_of_1d_array/
│   │   │   │   └── lc_1480_running_sum_of_1d_array_s1.cpp
│   │   │   ├── lc_154_find_minimum_in_rotated_sorted_array_ii/
│   │   │   │   ├── lc_154_find_minimum_in_rotated_sorted_array_ii_s1.cpp
│   │   │   │   └── lc_154_find_minimum_in_rotated_sorted_array_ii_s2.cpp
│   │   │   ├── lc_160_intersection_of_two_linked_lists/
│   │   │   │   └── lc_160_intersection_of_two_linked_lists_s1.cpp
│   │   │   ├── lc_167_two_sum_ii_input_array_is_sorted/
│   │   │   │   └── lc_167_two_sum_ii_input_array_is_sorted_s1.cpp
│   │   │   ├── lc_169_majority_element/
│   │   │   │   ├── lc_169_majority_element_s1.cpp
│   │   │   │   └── lc_169_majority_element_s2.cpp
│   │   │   ├── lc_179_largest_number/
│   │   │   │   ├── lc_179_largest_number_s1.cpp
│   │   │   │   └── lc_179_largest_number_s2.cpp
│   │   │   ├── lc_1823_find_the_winner_of_the_circular_game/
│   │   │   │   └── lc_1823_find_the_winner_of_the_circular_game_s1.cpp
│   │   │   ├── lc_191_number_of_1_bits/
│   │   │   │   ├── lc_191_number_of_1_bits_s1.cpp
│   │   │   │   └── lc_191_number_of_1_bits_s2.cpp
│   │   │   ├── lc_205_isomorphic_strings/
│   │   │   │   └── lc_205_isomorphic_strings_s1.cpp
│   │   │   ├── lc_206_reverse_linked_list/
│   │   │   │   ├── lc_206_reverse_linked_list_s1.cpp
│   │   │   │   └── lc_206_reverse_linked_list_s2.cpp
│   │   │   ├── lc_215_kth_largest_element_in_an_array/
│   │   │   │   ├── lc_215_kth_largest_element_in_an_array_s1.cpp
│   │   │   │   └── lc_215_kth_largest_element_in_an_array_s2.cpp
│   │   │   ├── lc_21_merge_two_sorted_lists/
│   │   │   │   └── lc_21_merge_two_sorted_lists_s1.cpp
│   │   │   ├── lc_226_invert_binary_tree/
│   │   │   │   ├── lc_226_invert_binary_tree_s1.cpp
│   │   │   │   └── lc_226_invert_binary_tree_s2.cpp
│   │   │   ├── lc_230_kth_smallest_element_in_a_bst/
│   │   │   │   └── lc_230_kth_smallest_element_in_a_bst_s1.cpp
│   │   │   ├── lc_232_implement_queue_using_stacks/
│   │   │   │   └── lc_232_implement_queue_using_stacks_s1.cpp
│   │   │   ├── lc_233_number_of_digit_one/
│   │   │   │   ├── lc_233_number_of_digit_one_s1.cpp
│   │   │   │   ├── lc_233_number_of_digit_one_s2.cpp
│   │   │   │   └── lc_233_number_of_digit_one_s3.cpp
│   │   │   ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree/
│   │   │   │   ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s1.cpp
│   │   │   │   ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s2.cpp
│   │   │   │   └── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s3.cpp
│   │   │   ├── lc_236_lowest_common_ancestor_of_a_binary_tree/
│   │   │   │   ├── lc_236_lowest_common_ancestor_of_a_binary_tree_s1.cpp
│   │   │   │   └── lc_236_lowest_common_ancestor_of_a_binary_tree_s2.cpp
│   │   │   ├── lc_237_delete_node_in_a_linked_list/
│   │   │   │   ├── lc_237_delete_node_in_a_linked_list_s1.cpp
│   │   │   │   └── lc_237_delete_node_in_a_linked_list_s2.cpp
│   │   │   ├── lc_238_product_of_array_except_self/
│   │   │   │   └── lc_238_product_of_array_except_self_s1.cpp
│   │   │   ├── lc_239_sliding_window_maximum/
│   │   │   │   ├── lc_239_sliding_window_maximum_s1.cpp
│   │   │   │   └── lc_239_sliding_window_maximum_s2.cpp
│   │   │   ├── lc_240_search_a_2d_matrix_ii/
│   │   │   │   └── lc_240_search_a_2d_matrix_ii_s1.cpp
│   │   │   ├── lc_242_valid_anagram/
│   │   │   │   ├── lc_242_valid_anagram_s1.cpp
│   │   │   │   └── lc_242_valid_anagram_s2.cpp
│   │   │   ├── lc_264_ugly_number_ii/
│   │   │   │   └── lc_264_ugly_number_ii_s1.cpp
│   │   │   ├── lc_266_palindrome_permutation/
│   │   │   │   ├── lc_266_palindrome_permutation_s1.cpp
│   │   │   │   └── lc_266_palindrome_permutation_s2.cpp
│   │   │   ├── lc_278_first_bad_version/
│   │   │   │   └── lc_278_first_bad_version_s1.cpp
│   │   │   ├── lc_287_find_the_duplicate_number/
│   │   │   │   ├── lc_287_find_the_duplicate_number_s1.cpp
│   │   │   │   ├── lc_287_find_the_duplicate_number_s2.cpp
│   │   │   │   └── lc_287_find_the_duplicate_number_s3.cpp
│   │   │   ├── lc_295_find_median_from_data_stream/
│   │   │   │   └── lc_295_find_median_from_data_stream_s1.cpp
│   │   │   ├── lc_371_sum_of_two_integers/
│   │   │   │   └── lc_371_sum_of_two_integers_s1.cpp
│   │   │   ├── lc_387_first_unique_character_in_a_string/
│   │   │   │   └── lc_387_first_unique_character_in_a_string_s1.cpp
│   │   │   ├── lc_392_is_subsequence/
│   │   │   │   └── lc_392_is_subsequence_s1.cpp
│   │   │   ├── lc_3_longest_substring_without_repeating_characters/
│   │   │   │   ├── lc_3_longest_substring_without_repeating_characters_s1.cpp
│   │   │   │   └── lc_3_longest_substring_without_repeating_characters_s2.cpp
│   │   │   ├── lc_400_nth_digit/
│   │   │   │   ├── lc_400_nth_digit_s1.cpp
│   │   │   │   ├── lc_400_nth_digit_s2.cpp
│   │   │   │   ├── lc_400_nth_digit_s3.cpp
│   │   │   │   └── lc_400_nth_digit_s4.cpp
│   │   │   ├── lc_409_longest_palindrome/
│   │   │   │   └── lc_409_longest_palindrome_s1.cpp
│   │   │   ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/
│   │   │   │   ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.cpp
│   │   │   │   └── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.cpp
│   │   │   ├── lc_46_permutations/
│   │   │   │   └── lc_46_permutations_s1.cpp
│   │   │   ├── lc_47_permutations_ii/
│   │   │   │   └── lc_47_permutations_ii_s1.cpp
│   │   │   ├── lc_48_rotate_image/
│   │   │   │   ├── lc_48_rotate_image_s1.cpp
│   │   │   │   ├── lc_48_rotate_image_s2.cpp
│   │   │   │   └── lc_48_rotate_image_s3.cpp
│   │   │   ├── lc_509_fibonacci_number/
│   │   │   │   └── lc_509_fibonacci_number_s1.cpp
│   │   │   ├── lc_53_maximum_subarray/
│   │   │   │   └── lc_53_maximum_subarray_s1.cpp
│   │   │   ├── lc_54_spiral_matrix/
│   │   │   │   └── lc_54_spiral_matrix_s1.cpp
│   │   │   ├── lc_65_valid_number/
│   │   │   │   └── lc_65_valid_number_s1.cpp
│   │   │   ├── lc_6_zigzag_conversion/
│   │   │   │   └── lc_6_zigzag_conversion_s1.cpp
│   │   │   ├── lc_704_binary_search/
│   │   │   │   └── lc_704_binary_search_s1.cpp
│   │   │   ├── lc_70_climbing_stairs/
│   │   │   │   └── lc_70_climbing_stairs_s1.cpp
│   │   │   ├── lc_724_find_pivot_index/
│   │   │   │   └── lc_724_find_pivot_index_s1.cpp
│   │   │   ├── lc_796_rotate_string/
│   │   │   │   └── lc_796_rotate_string_s1.cpp
│   │   │   ├── lc_79_word_search/
│   │   │   │   └── lc_79_word_search_s1.cpp
│   │   │   ├── lc_86_partition_list/
│   │   │   │   ├── lc_86_partition_list_s1.cpp
│   │   │   │   └── lc_86_partition_list_s2.cpp
│   │   │   ├── lc_876_middle_of_the_linked_list/
│   │   │   │   └── lc_876_middle_of_the_linked_list_s1.cpp
│   │   │   ├── lc_8_string_to_integer_atoi/
│   │   │   │   └── lc_8_string_to_integer_atoi_s1.cpp
│   │   │   └── lc_946_validate_stack_sequences/
│   │   │       └── lc_946_validate_stack_sequences_s1.cpp
│   │   ├── java/
│   │   │   ├── include/
│   │   │   │   ├── ListNode.java
│   │   │   │   ├── PrintUtil.java
│   │   │   │   └── TreeNode.java
│   │   │   ├── lc_101_symmetric_tree/
│   │   │   │   └── lc_101_symmetric_tree.java
│   │   │   ├── lc_102_binary_tree_level_order_traversal/
│   │   │   │   └── lc_102_binary_tree_level_order_traversal.java
│   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal/
│   │   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal_s1.java
│   │   │   │   ├── lc_103_binary_tree_zigzag_level_order_traversal_s2.java
│   │   │   │   └── lc_103_binary_tree_zigzag_level_order_traversal_s3.java
│   │   │   ├── lc_104_maximum_depth_of_binary_tree/
│   │   │   │   ├── lc_104_maximum_depth_of_binary_tree_s1.java
│   │   │   │   └── lc_104_maximum_depth_of_binary_tree_s2.java
│   │   │   ├── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal/
│   │   │   │   └── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal.java
│   │   │   ├── lc_10_regular_expression_matching/
│   │   │   │   ├── lc_10_regular_expression_matching_s1.java
│   │   │   │   └── lc_10_regular_expression_matching_s2.java
│   │   │   ├── lc_110_balanced_binary_tree/
│   │   │   │   ├── lc_110_balanced_binary_tree_s1.java
│   │   │   │   └── lc_110_balanced_binary_tree_s2.java
│   │   │   ├── lc_113_path_sum/
│   │   │   │   └── lc_113_path_sum.java
│   │   │   ├── lc_11_container_with_most_water/
│   │   │   │   └── lc_11_container_with_most_water.java
│   │   │   ├── lc_121_best_time_to_buy_and_sell_stock/
│   │   │   │   └── lc_121_best_time_to_buy_and_sell_stock.java
│   │   │   ├── lc_122_best_time_to_buy_and_sell_stock/
│   │   │   │   └── lc_122_best_time_to_buy_and_sell_stock.java
│   │   │   ├── lc_135_candy/
│   │   │   │   └── lc_135_candy.java
│   │   │   ├── lc_136_single_number/
│   │   │   │   └── lc_136_single_number.java
│   │   │   ├── lc_137_single_number/
│   │   │   │   ├── lc_137_single_number_s1.java
│   │   │   │   └── lc_137_single_number_s2.java
│   │   │   ├── lc_138_copy_list_with_random_pointer/
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s1.java
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s2.java
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s3.java
│   │   │   │   ├── lc_138_copy_list_with_random_pointer_s4.java
│   │   │   │   └── lc_138_copy_list_with_random_pointer_s5.java
│   │   │   ├── lc_142_linked_list_cycle/
│   │   │   │   └── lc_142_linked_list_cycle.java
│   │   │   ├── lc_1480_running_sum_of_1d_array/
│   │   │   │   └── lc_1480_running_sum_of_1d_array.java
│   │   │   ├── lc_151_reverse_words_in_a_string/
│   │   │   │   ├── lc_151_reverse_words_in_a_string_s1.java
│   │   │   │   └── lc_151_reverse_words_in_a_string_s2.java
│   │   │   ├── lc_154_find_minimum_in_rotated_sorted_array/
│   │   │   │   ├── lc_154_find_minimum_in_rotated_sorted_array_s1.java
│   │   │   │   └── lc_154_find_minimum_in_rotated_sorted_array_s2.java
│   │   │   ├── lc_155_min_stack/
│   │   │   │   └── lc_155_min_stack.java
│   │   │   ├── lc_15_three_sum/
│   │   │   │   └── lc_15_three_sum.java
│   │   │   ├── lc_160_intersection_of_two_linked_lists/
│   │   │   │   └── lc_160_intersection_of_two_linked_lists.java
│   │   │   ├── lc_167_two_sum/
│   │   │   │   └── lc_167_two_sum.java
│   │   │   ├── lc_169_majority_element/
│   │   │   │   ├── lc_169_majority_element_s1.java
│   │   │   │   └── lc_169_majority_element_s2.java
│   │   │   ├── lc_179_largest_number/
│   │   │   │   ├── lc_179_largest_number_s1.java
│   │   │   │   └── lc_179_largest_number_s2.java
│   │   │   ├── lc_1823_find_the_winner_of_the_circular_game/
│   │   │   │   └── lc_1823_find_the_winner_of_the_circular_game.java
│   │   │   ├── lc_191_number_of_1_bits/
│   │   │   │   ├── lc_191_number_of_1_bits_s1.java
│   │   │   │   └── lc_191_number_of_1_bits_s2.java
│   │   │   ├── lc_198_house_robber/
│   │   │   │   └── lc_198_house_robber.java
│   │   │   ├── lc_205_isomorphic_strings/
│   │   │   │   └── lc_205_isomorphic_strings.java
│   │   │   ├── lc_206_reverse_linked_list/
│   │   │   │   ├── lc_206_reverse_linked_list_s1.java
│   │   │   │   └── lc_206_reverse_linked_list_s2.java
│   │   │   ├── lc_207_course_schedule/
│   │   │   │   ├── lc_207_course_schedule_s1.java
│   │   │   │   └── lc_207_course_schedule_s2.java
│   │   │   ├── lc_20_valid_parentheses/
│   │   │   │   └── lc_20_valid_parentheses.java
│   │   │   ├── lc_213_house_robber/
│   │   │   │   └── lc_213_house_robber.java
│   │   │   ├── lc_215_kth_largest_element_in_an_array/
│   │   │   │   ├── lc_215_kth_largest_element_in_an_array_s1.java
│   │   │   │   └── lc_215_kth_largest_element_in_an_array_s2.java
│   │   │   ├── lc_21_merge_two_sorted_lists/
│   │   │   │   └── lc_21_merge_two_sorted_lists.java
│   │   │   ├── lc_226_invert_binary_tree/
│   │   │   │   ├── lc_226_invert_binary_tree_s1.java
│   │   │   │   └── lc_226_invert_binary_tree_s2.java
│   │   │   ├── lc_230_kth_smallest_element_in_a_bst/
│   │   │   │   └── lc_230_kth_smallest_element_in_a_bst.java
│   │   │   ├── lc_231_power_of_two/
│   │   │   │   └── lc_231_power_of_two.java
│   │   │   ├── lc_232_implement_queue_using_stacks/
│   │   │   │   └── lc_232_implement_queue_using_stacks.java
│   │   │   ├── lc_233_number_of_digit_one/
│   │   │   │   ├── lc_233_number_of_digit_one_s1.java
│   │   │   │   ├── lc_233_number_of_digit_one_s2.java
│   │   │   │   └── lc_233_number_of_digit_one_s3.java
│   │   │   ├── lc_235_lowest_common_ancestor_of_bst/
│   │   │   │   ├── lc_235_lowest_common_ancestor_of_bst_s1.java
│   │   │   │   ├── lc_235_lowest_common_ancestor_of_bst_s2.java
│   │   │   │   └── lc_235_lowest_common_ancestor_of_bst_s3.java
│   │   │   ├── lc_236_lowest_common_ancestor_of_binary_tree/
│   │   │   │   ├── lc_236_lowest_common_ancestor_of_binary_tree_s1.java
│   │   │   │   └── lc_236_lowest_common_ancestor_of_binary_tree_s2.java
│   │   │   ├── lc_237_delete_node_in_linked_list/
│   │   │   │   ├── lc_237_delete_node_in_linked_list_s1.java
│   │   │   │   └── lc_237_delete_node_in_linked_list_s2.java
│   │   │   ├── lc_238_product_of_array_except_self/
│   │   │   │   └── lc_238_product_of_array_except_self.java
│   │   │   ├── lc_239_sliding_window_maximum/
│   │   │   │   ├── lc_239_sliding_window_maximum_s1.java
│   │   │   │   └── lc_239_sliding_window_maximum_s2.java
│   │   │   ├── lc_240_search_a_2d_matrix/
│   │   │   │   └── lc_240_search_a_2d_matrix.java
│   │   │   ├── lc_242_valid_anagram/
│   │   │   │   ├── lc_242_valid_anagram_s1.java
│   │   │   │   └── lc_242_valid_anagram_s2.java
│   │   │   ├── lc_264_ugly_number/
│   │   │   │   └── lc_264_ugly_number.java
│   │   │   ├── lc_266_palindrome_permutation/
│   │   │   │   ├── lc_266_palindrome_permutation_s1.java
│   │   │   │   └── lc_266_palindrome_permutation_s2.java
│   │   │   ├── lc_278_first_bad_version/
│   │   │   │   └── lc_278_first_bad_version.java
│   │   │   ├── lc_287_find_the_duplicate_number/
│   │   │   │   ├── lc_287_find_the_duplicate_number_s1.java
│   │   │   │   ├── lc_287_find_the_duplicate_number_s2.java
│   │   │   │   └── lc_287_find_the_duplicate_number_s3.java
│   │   │   ├── lc_295_find_median_from_data_stream/
│   │   │   │   └── lc_295_find_median_from_data_stream.java
│   │   │   ├── lc_297_serialize_and_deserialize_binary_tree/
│   │   │   │   └── lc_297_serialize_and_deserialize_binary_tree.java
│   │   │   ├── lc_300_longest_increasing_subsequence/
│   │   │   │   ├── lc_300_longest_increasing_subsequence_s1.java
│   │   │   │   └── lc_300_longest_increasing_subsequence_s2.java
│   │   │   ├── lc_343_integer_break/
│   │   │   │   └── lc_343_integer_break.java
│   │   │   ├── lc_371_sum_of_two_integers/
│   │   │   │   └── lc_371_sum_of_two_integers.java
│   │   │   ├── lc_387_first_unique_character_in_a_string/
│   │   │   │   └── lc_387_first_unique_character_in_a_string.java
│   │   │   ├── lc_392_is_subsequence/
│   │   │   │   └── lc_392_is_subsequence.java
│   │   │   ├── lc_394_decode_string/
│   │   │   │   ├── lc_394_decode_string_s1.java
│   │   │   │   └── lc_394_decode_string_s2.java
│   │   │   ├── lc_3_longest_substring_without_repeating_characters/
│   │   │   │   ├── lc_3_longest_substring_without_repeating_characters_s1.java
│   │   │   │   └── lc_3_longest_substring_without_repeating_characters_s2.java
│   │   │   ├── lc_400_nth_digit/
│   │   │   │   ├── lc_400_nth_digit_s1.java
│   │   │   │   ├── lc_400_nth_digit_s2.java
│   │   │   │   ├── lc_400_nth_digit_s3.java
│   │   │   │   └── lc_400_nth_digit_s4.java
│   │   │   ├── lc_409_longest_palindrome/
│   │   │   │   └── lc_409_longest_palindrome.java
│   │   │   ├── lc_415_add_strings/
│   │   │   │   └── lc_415_add_strings.java
│   │   │   ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/
│   │   │   │   ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.java
│   │   │   │   └── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.java
│   │   │   ├── lc_46_permutations/
│   │   │   │   └── lc_46_permutations.java
│   │   │   ├── lc_47_permutations/
│   │   │   │   └── lc_47_permutations.java
│   │   │   ├── lc_48_rotate_image/
│   │   │   │   ├── lc_48_rotate_image_s1.java
│   │   │   │   ├── lc_48_rotate_image_s2.java
│   │   │   │   └── lc_48_rotate_image_s3.java
│   │   │   ├── lc_509_fibonacci_number/
│   │   │   │   └── lc_509_fibonacci_number.java
│   │   │   ├── lc_50_powx_n/
│   │   │   │   └── lc_50_powx_n.java
│   │   │   ├── lc_53_maximum_subarray/
│   │   │   │   └── lc_53_maximum_subarray.java
│   │   │   ├── lc_54_spiral_matrix/
│   │   │   │   └── lc_54_spiral_matrix.java
│   │   │   ├── lc_59_spiral_matrix/
│   │   │   │   └── lc_59_spiral_matrix.java
│   │   │   ├── lc_64_minimum_path_sum/
│   │   │   │   └── lc_64_minimum_path_sum.java
│   │   │   ├── lc_65_valid_number/
│   │   │   │   └── lc_65_valid_number.java
│   │   │   ├── lc_6_zigzag_conversion/
│   │   │   │   └── lc_6_zigzag_conversion.java
│   │   │   ├── lc_704_binary_search/
│   │   │   │   └── lc_704_binary_search.java
│   │   │   ├── lc_70_climbing_stairs/
│   │   │   │   └── lc_70_climbing_stairs.java
│   │   │   ├── lc_724_find_pivot_index/
│   │   │   │   └── lc_724_find_pivot_index.java
│   │   │   ├── lc_796_rotate_string/
│   │   │   │   └── lc_796_rotate_string.java
│   │   │   ├── lc_79_word_search/
│   │   │   │   └── lc_79_word_search.java
│   │   │   ├── lc_86_partition_list/
│   │   │   │   ├── lc_86_partition_list_s1.java
│   │   │   │   └── lc_86_partition_list_s2.java
│   │   │   ├── lc_876_middle_of_the_linked_list/
│   │   │   │   └── lc_876_middle_of_the_linked_list.java
│   │   │   ├── lc_89_gray_code/
│   │   │   │   └── lc_89_gray_code.java
│   │   │   ├── lc_8_string_to_integer_atoi/
│   │   │   │   ├── lc_8_string_to_integer_atoi_s1.java
│   │   │   │   └── lc_8_string_to_integer_atoi_s2.java
│   │   │   └── lc_946_validate_stack_sequences/
│   │   │       └── lc_946_validate_stack_sequences.java
│   │   └── python/
│   │       ├── fix_tests.py
│   │       ├── include/
│   │       │   ├── __init__.py
│   │       │   ├── binary_tree.py
│   │       │   ├── linked_list.py
│   │       │   └── print_util.py
│   │       ├── lc_101_symmetric_tree.py
│   │       ├── lc_102_binary_tree_level_order_traversal.py
│   │       ├── lc_103_binary_tree_zigzag_level_order_traversal_s1.py
│   │       ├── lc_103_binary_tree_zigzag_level_order_traversal_s2.py
│   │       ├── lc_103_binary_tree_zigzag_level_order_traversal_s3.py
│   │       ├── lc_104_maximum_depth_of_binary_tree_s1.py
│   │       ├── lc_104_maximum_depth_of_binary_tree_s2.py
│   │       ├── lc_105_construct_binary_tree_from_preorder_and_inorder_traversal.py
│   │       ├── lc_10_regular_expression_matching_s1.py
│   │       ├── lc_10_regular_expression_matching_s2.py
│   │       ├── lc_110_balanced_binary_tree_s1.py
│   │       ├── lc_110_balanced_binary_tree_s2.py
│   │       ├── lc_113_path_sum_ii.py
│   │       ├── lc_11_container_with_most_water.py
│   │       ├── lc_121_best_time_to_buy_and_sell_stock.py
│   │       ├── lc_122_best_time_to_buy_and_sell_stock_ii.py
│   │       ├── lc_135_candy.py
│   │       ├── lc_136_single_number.py
│   │       ├── lc_137_single_number_ii_s1.py
│   │       ├── lc_137_single_number_ii_s2.py
│   │       ├── lc_138_copy_list_with_random_pointer_s1.py
│   │       ├── lc_138_copy_list_with_random_pointer_s2.py
│   │       ├── lc_138_copy_list_with_random_pointer_s3.py
│   │       ├── lc_138_copy_list_with_random_pointer_s4.py
│   │       ├── lc_138_copy_list_with_random_pointer_s5.py
│   │       ├── lc_142_linked_list_cycle_ii.py
│   │       ├── lc_1480_running_sum_of_1d_array.py
│   │       ├── lc_151_reverse_words_in_a_string_s1.py
│   │       ├── lc_151_reverse_words_in_a_string_s2.py
│   │       ├── lc_151_reverse_words_in_a_string_s3.py
│   │       ├── lc_154_find_minimum_in_rotated_sorted_array_ii_s1.py
│   │       ├── lc_154_find_minimum_in_rotated_sorted_array_ii_s2.py
│   │       ├── lc_155_min_stack.py
│   │       ├── lc_15_three_sum.py
│   │       ├── lc_160_intersection_of_two_linked_lists.py
│   │       ├── lc_167_two_sum_ii.py
│   │       ├── lc_169_majority_element_s1.py
│   │       ├── lc_169_majority_element_s2.py
│   │       ├── lc_179_largest_number_s1.py
│   │       ├── lc_179_largest_number_s2.py
│   │       ├── lc_1823_find_the_winner_of_the_circular_game.py
│   │       ├── lc_191_number_of_1_bits_s1.py
│   │       ├── lc_191_number_of_1_bits_s2.py
│   │       ├── lc_198_house_robber.py
│   │       ├── lc_205_isomorphic_strings.py
│   │       ├── lc_206_reverse_linked_list_s1.py
│   │       ├── lc_206_reverse_linked_list_s2.py
│   │       ├── lc_206_reverse_linked_list_s3.py
│   │       ├── lc_207_course_schedule_s1.py
│   │       ├── lc_207_course_schedule_s2.py
│   │       ├── lc_20_valid_parentheses.py
│   │       ├── lc_213_house_robber_ii.py
│   │       ├── lc_215_kth_largest_element_in_an_array_s1.py
│   │       ├── lc_215_kth_largest_element_in_an_array_s2.py
│   │       ├── lc_21_merge_two_sorted_lists.py
│   │       ├── lc_226_invert_binary_tree_s1.py
│   │       ├── lc_226_invert_binary_tree_s2.py
│   │       ├── lc_226_invert_binary_tree_s3.py
│   │       ├── lc_230_kth_smallest_element_in_a_bst.py
│   │       ├── lc_231_power_of_two.py
│   │       ├── lc_232_implement_queue_using_stacks.py
│   │       ├── lc_233_number_of_digit_one_s1.py
│   │       ├── lc_233_number_of_digit_one_s2.py
│   │       ├── lc_233_number_of_digit_one_s3.py
│   │       ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s1.py
│   │       ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s2.py
│   │       ├── lc_235_lowest_common_ancestor_of_a_binary_search_tree_s3.py
│   │       ├── lc_236_lowest_common_ancestor_of_a_binary_tree_s1.py
│   │       ├── lc_236_lowest_common_ancestor_of_a_binary_tree_s2.py
│   │       ├── lc_237_delete_node_in_a_linked_list_s1.py
│   │       ├── lc_237_delete_node_in_a_linked_list_s2.py
│   │       ├── lc_238_product_of_array_except_self.py
│   │       ├── lc_239_sliding_window_maximum_s1.py
│   │       ├── lc_239_sliding_window_maximum_s2.py
│   │       ├── lc_240_search_a_2d_matrix_ii.py
│   │       ├── lc_242_valid_anagram_s1.py
│   │       ├── lc_242_valid_anagram_s2.py
│   │       ├── lc_264_ugly_number_ii.py
│   │       ├── lc_266_palindrome_permutation_s1.py
│   │       ├── lc_266_palindrome_permutation_s2.py
│   │       ├── lc_278_first_bad_version.py
│   │       ├── lc_287_find_the_duplicate_number_s1.py
│   │       ├── lc_287_find_the_duplicate_number_s2.py
│   │       ├── lc_287_find_the_duplicate_number_s3.py
│   │       ├── lc_295_find_median_from_data_stream_s1.py
│   │       ├── lc_295_find_median_from_data_stream_s2.py
│   │       ├── lc_297_serialize_and_deserialize_binary_tree.py
│   │       ├── lc_300_longest_increasing_subsequence_s1.py
│   │       ├── lc_300_longest_increasing_subsequence_s2.py
│   │       ├── lc_343_integer_break.py
│   │       ├── lc_371_sum_of_two_integers.py
│   │       ├── lc_387_first_unique_character_in_a_string.py
│   │       ├── lc_392_is_subsequence.py
│   │       ├── lc_394_decode_string_s1.py
│   │       ├── lc_394_decode_string_s2.py
│   │       ├── lc_39_combination_sum_s1.py
│   │       ├── lc_39_combination_sum_s2.py
│   │       ├── lc_3_longest_substring_without_repeating_characters_s1.py
│   │       ├── lc_3_longest_substring_without_repeating_characters_s2.py
│   │       ├── lc_400_nth_digit_s1.py
│   │       ├── lc_400_nth_digit_s2.py
│   │       ├── lc_400_nth_digit_s3.py
│   │       ├── lc_400_nth_digit_s4.py
│   │       ├── lc_409_longest_palindrome.py
│   │       ├── lc_40_combination_sum_ii_s1.py
│   │       ├── lc_40_combination_sum_ii_s2.py
│   │       ├── lc_415_add_strings.py
│   │       ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.py
│   │       ├── lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.py
│   │       ├── lc_46_permutations.py
│   │       ├── lc_47_permutations_ii.py
│   │       ├── lc_48_rotate_image_s1.py
│   │       ├── lc_48_rotate_image_s2.py
│   │       ├── lc_48_rotate_image_s3.py
│   │       ├── lc_509_fibonacci_number.py
│   │       ├── lc_50_powx_n.py
│   │       ├── lc_53_maximum_subarray.py
│   │       ├── lc_54_spiral_matrix.py
│   │       ├── lc_59_spiral_matrix_ii.py
│   │       ├── lc_64_minimum_path_sum.py
│   │       ├── lc_65_valid_number.py
│   │       ├── lc_6_zigzag_conversion.py
│   │       ├── lc_704_binary_search.py
│   │       ├── lc_70_climbing_stairs.py
│   │       ├── lc_724_find_pivot_index.py
│   │       ├── lc_768_max_chunks_to_make_sorted_ii.py
│   │       ├── lc_796_rotate_string.py
│   │       ├── lc_79_word_search.py
│   │       ├── lc_86_partition_list_s1.py
│   │       ├── lc_86_partition_list_s2.py
│   │       ├── lc_876_middle_of_the_linked_list.py
│   │       ├── lc_89_gray_code.py
│   │       ├── lc_8_string_to_integer_atoi_s1.py
│   │       ├── lc_8_string_to_integer_atoi_s2.py
│   │       └── lc_946_validate_stack_sequences.py
│   └── docs/
│       ├── 10. 正则表达式匹配.md
│       ├── 101. 对称二叉树.md
│       ├── 102. 二叉树的层序遍历.md
│       ├── 103. 二叉树的锯齿形层序遍历.md
│       ├── 104. 二叉树的最大深度.md
│       ├── 105. 从前序与中序遍历序列构造二叉树.md
│       ├── 11. 盛最多水的容器.md
│       ├── 110. 平衡二叉树.md
│       ├── 113. 路径总和 II.md
│       ├── 121. 买卖股票的最佳时机.md
│       ├── 122. 买卖股票的最佳时机 II .md
│       ├── 135. 分发糖果.md
│       ├── 136. 只出现一次的数字.md
│       ├── 137. 只出现一次的数字 II.md
│       ├── 138. 复制带随机指针的链表.md
│       ├── 142. 环形链表 II.md
│       ├── 1480. 一维数组的动态和.md
│       ├── 15. 三数之和.md
│       ├── 151. 反转字符串中的单词.md
│       ├── 154. 寻找旋转排序数组中的最小值 II.md
│       ├── 155. 最小栈 .md
│       ├── 160. 相交链表.md
│       ├── 167. 两数之和 II.md
│       ├── 169. 多数元素.md
│       ├── 179. 最大数.md
│       ├── 1823. 找出游戏的获胜者.md
│       ├── 191. 位1的个数.md
│       ├── 198. 打家劫舍.md
│       ├── 20. 有效的括号.md
│       ├── 205. 同构字符串.md
│       ├── 206. 反转链表.md
│       ├── 207. 课程表.md
│       ├── 21. 合并两个有序链表.md
│       ├── 213. 打家劫舍 II.md
│       ├── 215. 数组中的第K个最大元素.md
│       ├── 226. 翻转二叉树.md
│       ├── 230. 二叉搜索树中第K小的元素.md
│       ├── 231. 2 的幂.md
│       ├── 232. 用栈实现队列.md
│       ├── 233. 数字 1 的个数.md
│       ├── 235. 二叉搜索树的最近公共祖先.md
│       ├── 236. 二叉树的最近公共祖先.md
│       ├── 237. 删除链表中的节点.md
│       ├── 238. 除自身以外数组的乘积.md
│       ├── 239. 滑动窗口最大值.md
│       ├── 240. 搜索二维矩阵 II.md
│       ├── 242. 有效的字母异位词.md
│       ├── 264. 丑数 II .md
│       ├── 266. 回文排列.md
│       ├── 278. 第一个错误的版本.md
│       ├── 287. 寻找重复数.md
│       ├── 295. 数据流的中位数.md
│       ├── 297. 二叉树的序列化与反序列化.md
│       ├── 3. 无重复字符的最长子串.md
│       ├── 300. 最长递增子序列.md
│       ├── 343. 整数拆分.md
│       ├── 371. 两整数之和.md
│       ├── 387. 字符串中的第一个唯一字符.md
│       ├── 39. 组合总和.md
│       ├── 392. 判断子序列.md
│       ├── 394. 字符串解码.md
│       ├── 40. 组合总和 II.md
│       ├── 400. 第 N 位数字.md
│       ├── 409. 最长回文串.md
│       ├── 415. 字符串相加.md
│       ├── 426. 将二叉搜索树转化为排序的双向链表.md
│       ├── 46. 全排列.md
│       ├── 47. 全排列 II.md
│       ├── 48. 旋转图像.md
│       ├── 50. Pow(x, n).md
│       ├── 509. 斐波那契数.md
│       ├── 53. 最大子数组和.md
│       ├── 54. 螺旋矩阵.md
│       ├── 59. 螺旋矩阵 II.md
│       ├── 6. N 字形变换.md
│       ├── 64. 最小路径和.md
│       ├── 65. 有效数字.md
│       ├── 70. 爬楼梯.md
│       ├── 704. 二分查找.md
│       ├── 724. 寻找数组的中心下标.md
│       ├── 768. 最多能完成排序的块 II.md
│       ├── 79. 单词搜索.md
│       ├── 796. 旋转字符串.md
│       ├── 8. 字符串转换整数 (atoi).md
│       ├── 86. 分隔链表.md
│       ├── 876. 链表的中间结点.md
│       ├── 89. 格雷编码.md
│       └── 946. 验证栈序列.md
└── sword_for_offer/
    ├── codes/
    │   ├── cpp/
    │   │   ├── include/
    │   │   │   ├── ListNode.hpp
    │   │   │   ├── PrintUtil.hpp
    │   │   │   ├── TreeNode.hpp
    │   │   │   └── include.hpp
    │   │   ├── sfo_03_find_duplicate_numbers_in_an_array_s1/
    │   │   │   └── sfo_03_find_duplicate_numbers_in_an_array_s1.cpp
    │   │   ├── sfo_03_find_duplicate_numbers_in_an_array_s2/
    │   │   │   └── sfo_03_find_duplicate_numbers_in_an_array_s2.cpp
    │   │   ├── sfo_04_find_a_number_in_2d_matrix_s1/
    │   │   │   └── sfo_04_find_a_number_in_2d_matrix_s1.cpp
    │   │   ├── sfo_05_replace_spaces_s1/
    │   │   │   └── sfo_05_replace_spaces_s1.cpp
    │   │   ├── sfo_06_print_a_linked_list_in_reverse_order_s1/
    │   │   │   └── sfo_06_print_a_linked_list_in_reverse_order_s1.cpp
    │   │   ├── sfo_06_print_a_linked_list_in_reverse_order_s2/
    │   │   │   └── sfo_06_print_a_linked_list_in_reverse_order_s2.cpp
    │   │   ├── sfo_07_reconstruct_binary_tree_s1/
    │   │   │   └── sfo_07_reconstruct_binary_tree_s1.cpp
    │   │   ├── sfo_09_implement_a_queue_using_two_stacks_s1/
    │   │   │   └── sfo_09_implement_a_queue_using_two_stacks_s1.cpp
    │   │   ├── sfo_10i_fibonacci_numbers_s1/
    │   │   │   └── sfo_10i_fibonacci_numbers_s1.cpp
    │   │   ├── sfo_10ii_frog_jump_s1/
    │   │   │   └── sfo_10ii_frog_jump_s1.cpp
    │   │   ├── sfo_11_find_minimum_in_rotated_sorted_array_s1/
    │   │   │   └── sfo_11_find_minimum_in_rotated_sorted_array_s1.cpp
    │   │   ├── sfo_11_find_minimum_in_rotated_sorted_array_s2/
    │   │   │   └── sfo_11_find_minimum_in_rotated_sorted_array_s2.cpp
    │   │   ├── sfo_12_word_search_s1/
    │   │   │   └── sfo_12_word_search_s1.cpp
    │   │   ├── sfo_13_range_of_motion_of_a_robot_s1/
    │   │   │   └── sfo_13_range_of_motion_of_a_robot_s1.cpp
    │   │   ├── sfo_13_range_of_motion_of_a_robot_s2/
    │   │   │   └── sfo_13_range_of_motion_of_a_robot_s2.cpp
    │   │   ├── sfo_14i_cut_the_rope_i_s1/
    │   │   │   └── sfo_14i_cut_the_rope_i_s1.cpp
    │   │   ├── sfo_14ii_cut_the_rope_ii_s1/
    │   │   │   └── sfo_14ii_cut_the_rope_ii_s1.cpp
    │   │   ├── sfo_15_number_of_1_bits_s1/
    │   │   │   └── sfo_15_number_of_1_bits_s1.cpp
    │   │   ├── sfo_15_number_of_1_bits_s2/
    │   │   │   └── sfo_15_number_of_1_bits_s2.cpp
    │   │   ├── sfo_16_powers_of_integers_s1/
    │   │   │   └── sfo_16_powers_of_integers_s1.cpp
    │   │   ├── sfo_18_delete_a_node_from_a_linked_list_s1/
    │   │   │   └── sfo_18_delete_a_node_from_a_linked_list_s1.cpp
    │   │   ├── sfo_19_regular_expression_matching_s1/
    │   │   │   └── sfo_19_regular_expression_matching_s1.cpp
    │   │   ├── sfo_19_regular_expression_matching_s2/
    │   │   │   └── sfo_19_regular_expression_matching_s2.cpp
    │   │   ├── sfo_21_adjust_the_order_of_numbers_in_an_array_s1/
    │   │   │   └── sfo_21_adjust_the_order_of_numbers_in_an_array_s1.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
    │   │   ├── 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
    │   │   ├── sfo_24_reverse_a_linked_list_s1/
    │   │   │   └── sfo_24_reverse_a_linked_list_s1.cpp
    │   │   ├── sfo_24_reverse_a_linked_list_s2/
    │   │   │   └── sfo_24_reverse_a_linked_list_s2.cpp
    │   │   ├── sfo_25_combine_two_sorted_linked_lists_s1/
    │   │   │   └── sfo_25_combine_two_sorted_linked_lists_s1.cpp
    │   │   ├── sfo_26_substructure_of_a_binary_tree_s1/
    │   │   │   └── sfo_26_substructure_of_a_binary_tree_s1.cpp
    │   │   ├── sfo_27_mirror_of_a_binary_tree_s1/
    │   │   │   └── sfo_27_mirror_of_a_binary_tree_s1.cpp
    │   │   ├── sfo_27_mirror_of_a_binary_tree_s2/
    │   │   │   └── sfo_27_mirror_of_a_binary_tree_s2.cpp
    │   │   ├── sfo_28_symmetric_binary_tree_s1/
    │   │   │   └── sfo_28_symmetric_binary_tree_s1.cpp
    │   │   ├── sfo_29_print_a_given_matrix_in_spiral_form_s1/
    │   │   │   └── sfo_29_print_a_given_matrix_in_spiral_form_s1.cpp
    │   │   ├── sfo_30_min_stack_s1/
    │   │   │   └── sfo_30_min_stack_s1.cpp
    │   │   ├── sfo_31_validate_stack_sequences_s1/
    │   │   │   └── sfo_31_validate_stack_sequences_s1.cpp
    │   │   ├── sfo_32i_print_a_binary_tree_topbottom_i_s1/
    │   │   │   └── sfo_32i_print_a_binary_tree_topbottom_i_s1.cpp
    │   │   ├── sfo_32ii_print_a_binary_tree_topbottom_ii_s1/
    │   │   │   └── sfo_32ii_print_a_binary_tree_topbottom_ii_s1.cpp
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s1/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s1.cpp
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s2/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s2.cpp
    │   │   ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_33_postorder_traversal_of_a_binary_search_tree_s1.cpp
    │   │   ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s2/
    │   │   │   └── sfo_33_postorder_traversal_of_a_binary_search_tree_s2.cpp
    │   │   ├── sfo_34_all_xsum_paths_in_a_binary_tree_s1/
    │   │   │   └── sfo_34_all_xsum_paths_in_a_binary_tree_s1.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
    │   │   ├── 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
    │   │   ├── sfo_36_binary_search_tree_and_doubly_linked_list_s1/
    │   │   │   └── sfo_36_binary_search_tree_and_doubly_linked_list_s1.cpp
    │   │   ├── sfo_37_serialize_and_deserialize_a_binary_tree_s1/
    │   │   │   └── sfo_37_serialize_and_deserialize_a_binary_tree_s1.cpp
    │   │   ├── sfo_38_all_permutations_of_a_string_s1/
    │   │   │   └── sfo_38_all_permutations_of_a_string_s1.cpp
    │   │   ├── sfo_39_the_majority_element_in_an_array_s1/
    │   │   │   └── sfo_39_the_majority_element_in_an_array_s1.cpp
    │   │   ├── sfo_39_the_majority_element_in_an_array_s2/
    │   │   │   └── sfo_39_the_majority_element_in_an_array_s2.cpp
    │   │   ├── sfo_40_the_smallest_k_numbers_s1/
    │   │   │   └── sfo_40_the_smallest_k_numbers_s1.cpp
    │   │   ├── sfo_40_the_smallest_k_numbers_s2/
    │   │   │   └── sfo_40_the_smallest_k_numbers_s2.cpp
    │   │   ├── sfo_41_find_median_from_data_stream_s1/
    │   │   │   └── sfo_41_find_median_from_data_stream_s1.cpp
    │   │   ├── sfo_42_largest_sum_contiguous_subarray_s1/
    │   │   │   └── sfo_42_largest_sum_contiguous_subarray_s1.cpp
    │   │   ├── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1/
    │   │   │   └── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1.cpp
    │   │   ├── sfo_44_nth_digit_s1/
    │   │   │   └── sfo_44_nth_digit_s1.cpp
    │   │   ├── sfo_45_arrange_an_array_into_the_smallest_number_s1/
    │   │   │   └── sfo_45_arrange_an_array_into_the_smallest_number_s1.cpp
    │   │   ├── sfo_45_arrange_an_array_into_the_smallest_number_s2/
    │   │   │   └── sfo_45_arrange_an_array_into_the_smallest_number_s2.cpp
    │   │   ├── sfo_46_translate_numbers_into_strings_s1/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s1.cpp
    │   │   ├── sfo_46_translate_numbers_into_strings_s2/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s2.cpp
    │   │   ├── sfo_46_translate_numbers_into_strings_s3/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s3.cpp
    │   │   ├── sfo_47_the_maximum_value_of_gifts_s1/
    │   │   │   └── sfo_47_the_maximum_value_of_gifts_s1.cpp
    │   │   ├── sfo_47_the_maximum_value_of_gifts_s2/
    │   │   │   └── sfo_47_the_maximum_value_of_gifts_s2.cpp
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s1/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s1.cpp
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s2/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s2.cpp
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s3/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s3.cpp
    │   │   ├── sfo_49_ugly_numbers_s1/
    │   │   │   └── sfo_49_ugly_numbers_s1.cpp
    │   │   ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1/
    │   │   │   └── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.cpp
    │   │   ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2/
    │   │   │   └── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.cpp
    │   │   ├── sfo_51_reversed_pairs_in_an_array_s1/
    │   │   │   └── sfo_51_reversed_pairs_in_an_array_s1.cpp
    │   │   ├── sfo_52_the_first_common_node_in_two_linked_lists_s1/
    │   │   │   └── sfo_52_the_first_common_node_in_two_linked_lists_s1.cpp
    │   │   ├── sfo_53i_find_a_number_in_a_sorted_array_s1/
    │   │   │   └── sfo_53i_find_a_number_in_a_sorted_array_s1.cpp
    │   │   ├── sfo_53i_find_a_number_in_a_sorted_array_s2/
    │   │   │   └── sfo_53i_find_a_number_in_a_sorted_array_s2.cpp
    │   │   ├── sfo_53ii_the_missing_number_from_0_to_n1_s1/
    │   │   │   └── sfo_53ii_the_missing_number_from_0_to_n1_s1.cpp
    │   │   ├── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.cpp
    │   │   ├── sfo_55i_depth_of_a_binary_tree_s1/
    │   │   │   └── sfo_55i_depth_of_a_binary_tree_s1.cpp
    │   │   ├── sfo_55i_depth_of_a_binary_tree_s2/
    │   │   │   └── sfo_55i_depth_of_a_binary_tree_s2.cpp
    │   │   ├── sfo_55ii_balanced_binary_tree_s1/
    │   │   │   └── sfo_55ii_balanced_binary_tree_s1.cpp
    │   │   ├── sfo_55ii_balanced_binary_tree_s2/
    │   │   │   └── sfo_55ii_balanced_binary_tree_s2.cpp
    │   │   ├── sfo_56i_single_number_i_s1/
    │   │   │   └── sfo_56i_single_number_i_s1.cpp
    │   │   ├── sfo_56ii_single_number_ii_s1/
    │   │   │   └── sfo_56ii_single_number_ii_s1.cpp
    │   │   ├── sfo_56ii_single_number_ii_s2/
    │   │   │   └── sfo_56ii_single_number_ii_s2.cpp
    │   │   ├── sfo_57_two_numbers_with_sum_s_s1/
    │   │   │   └── sfo_57_two_numbers_with_sum_s_s1.cpp
    │   │   ├── sfo_57ii_consecutive_numbers_with_sum_s_s1/
    │   │   │   └── sfo_57ii_consecutive_numbers_with_sum_s_s1.cpp
    │   │   ├── sfo_57ii_consecutive_numbers_with_sum_s_s2/
    │   │   │   └── sfo_57ii_consecutive_numbers_with_sum_s_s2.cpp
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s1/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s1.cpp
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s2/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s2.cpp
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s3/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s3.cpp
    │   │   ├── sfo_59ii_max_queue_s1/
    │   │   │   └── sfo_59ii_max_queue_s1.cpp
    │   │   ├── sfo_60_probabilities_for_rolling_n_dices_s1/
    │   │   │   └── sfo_60_probabilities_for_rolling_n_dices_s1.cpp
    │   │   ├── sfo_61_straight_in_poker_s1/
    │   │   │   └── sfo_61_straight_in_poker_s1.cpp
    │   │   ├── sfo_61_straight_in_poker_s2/
    │   │   │   └── sfo_61_straight_in_poker_s2.cpp
    │   │   ├── sfo_62_josephus_problem_s1/
    │   │   │   └── sfo_62_josephus_problem_s1.cpp
    │   │   ├── sfo_63_the_maximum_profit_of_stocks_s1/
    │   │   │   └── sfo_63_the_maximum_profit_of_stocks_s1.cpp
    │   │   ├── sfo_64_solve_1_2___n_s1/
    │   │   │   └── sfo_64_solve_1_2___n_s1.cpp
    │   │   ├── sfo_65_implement_addition_operation_without_arithmetic_operators_s1/
    │   │   │   └── sfo_65_implement_addition_operation_without_arithmetic_operators_s1.cpp
    │   │   ├── sfo_66_a_product_array_puzzle_s1/
    │   │   │   └── sfo_66_a_product_array_puzzle_s1.cpp
    │   │   ├── sfo_67_convert_string_to_int_s1/
    │   │   │   └── sfo_67_convert_string_to_int_s1.cpp
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.cpp
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.cpp
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.cpp
    │   │   ├── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1/
    │   │   │   └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1.cpp
    │   │   └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2/
    │   │       └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2.cpp
    │   ├── java/
    │   │   ├── include/
    │   │   │   ├── ListNode.java
    │   │   │   ├── PrintUtil.java
    │   │   │   └── TreeNode.java
    │   │   ├── sfo_03_find_duplicate_numbers_in_an_array_s1/
    │   │   │   └── sfo_03_find_duplicate_numbers_in_an_array_s1.java
    │   │   ├── sfo_03_find_duplicate_numbers_in_an_array_s2/
    │   │   │   └── sfo_03_find_duplicate_numbers_in_an_array_s2.java
    │   │   ├── sfo_04_find_a_number_in_2d_matrix_s1/
    │   │   │   └── sfo_04_find_a_number_in_2d_matrix_s1.java
    │   │   ├── sfo_05_replace_spaces_s1/
    │   │   │   └── sfo_05_replace_spaces_s1.java
    │   │   ├── sfo_06_print_a_linked_list_in_reverse_order_s1/
    │   │   │   └── sfo_06_print_a_linked_list_in_reverse_order_s1.java
    │   │   ├── sfo_06_print_a_linked_list_in_reverse_order_s2/
    │   │   │   └── sfo_06_print_a_linked_list_in_reverse_order_s2.java
    │   │   ├── sfo_07_reconstruct_binary_tree_s1/
    │   │   │   └── sfo_07_reconstruct_binary_tree_s1.java
    │   │   ├── sfo_09_implement_a_queue_using_two_stacks_s1/
    │   │   │   └── sfo_09_implement_a_queue_using_two_stacks_s1.java
    │   │   ├── sfo_10i_fibonacci_numbers_s1/
    │   │   │   └── sfo_10i_fibonacci_numbers_s1.java
    │   │   ├── sfo_10ii_frog_jump_s1/
    │   │   │   └── sfo_10ii_frog_jump_s1.java
    │   │   ├── sfo_11_find_minimum_in_rotated_sorted_array_s1/
    │   │   │   └── sfo_11_find_minimum_in_rotated_sorted_array_s1.java
    │   │   ├── sfo_11_find_minimum_in_rotated_sorted_array_s2/
    │   │   │   └── sfo_11_find_minimum_in_rotated_sorted_array_s2.java
    │   │   ├── sfo_12_word_search_s1/
    │   │   │   └── sfo_12_word_search_s1.java
    │   │   ├── sfo_13_range_of_motion_of_a_robot_s1/
    │   │   │   └── sfo_13_range_of_motion_of_a_robot_s1.java
    │   │   ├── sfo_13_range_of_motion_of_a_robot_s2/
    │   │   │   └── sfo_13_range_of_motion_of_a_robot_s2.java
    │   │   ├── sfo_14i_cut_the_rope_i_s1/
    │   │   │   └── sfo_14i_cut_the_rope_i_s1.java
    │   │   ├── sfo_14ii_cut_the_rope_ii_s1/
    │   │   │   └── sfo_14ii_cut_the_rope_ii_s1.java
    │   │   ├── sfo_15_number_of_1_bits_s1/
    │   │   │   └── sfo_15_number_of_1_bits_s1.java
    │   │   ├── sfo_15_number_of_1_bits_s2/
    │   │   │   └── sfo_15_number_of_1_bits_s2.java
    │   │   ├── sfo_16_powers_of_integers_s1/
    │   │   │   └── sfo_16_powers_of_integers_s1.java
    │   │   ├── sfo_17_print_from_1_to_the_largest_n_digits_s1/
    │   │   │   └── sfo_17_print_from_1_to_the_largest_n_digits_s1.java
    │   │   ├── sfo_17_print_from_1_to_the_largest_n_digits_s2/
    │   │   │   └── sfo_17_print_from_1_to_the_largest_n_digits_s2.java
    │   │   ├── sfo_17_print_from_1_to_the_largest_n_digits_s3/
    │   │   │   └── sfo_17_print_from_1_to_the_largest_n_digits_s3.java
    │   │   ├── sfo_17_print_from_1_to_the_largest_n_digits_s4/
    │   │   │   └── sfo_17_print_from_1_to_the_largest_n_digits_s4.java
    │   │   ├── sfo_18_delete_a_node_from_a_linked_list_s1/
    │   │   │   └── sfo_18_delete_a_node_from_a_linked_list_s1.java
    │   │   ├── sfo_19_regular_expression_matching_s1/
    │   │   │   └── sfo_19_regular_expression_matching_s1.java
    │   │   ├── sfo_19_regular_expression_matching_s2/
    │   │   │   └── sfo_19_regular_expression_matching_s2.java
    │   │   ├── sfo_20_a_string_representing_a_numeric_value_s1/
    │   │   │   └── sfo_20_a_string_representing_a_numeric_value_s1.java
    │   │   ├── sfo_21_adjust_the_order_of_numbers_in_an_array_s1/
    │   │   │   └── sfo_21_adjust_the_order_of_numbers_in_an_array_s1.java
    │   │   ├── 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.java
    │   │   ├── 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.java
    │   │   ├── sfo_24_reverse_a_linked_list_s1/
    │   │   │   └── sfo_24_reverse_a_linked_list_s1.java
    │   │   ├── sfo_24_reverse_a_linked_list_s2/
    │   │   │   └── sfo_24_reverse_a_linked_list_s2.java
    │   │   ├── sfo_25_combine_two_sorted_linked_lists_s1/
    │   │   │   └── sfo_25_combine_two_sorted_linked_lists_s1.java
    │   │   ├── sfo_26_substructure_of_a_binary_tree_s1/
    │   │   │   └── sfo_26_substructure_of_a_binary_tree_s1.java
    │   │   ├── sfo_27_mirror_of_a_binary_tree_s1/
    │   │   │   └── sfo_27_mirror_of_a_binary_tree_s1.java
    │   │   ├── sfo_27_mirror_of_a_binary_tree_s2/
    │   │   │   └── sfo_27_mirror_of_a_binary_tree_s2.java
    │   │   ├── sfo_28_symmetric_binary_tree_s1/
    │   │   │   └── sfo_28_symmetric_binary_tree_s1.java
    │   │   ├── sfo_29_print_a_given_matrix_in_spiral_form_s1/
    │   │   │   └── sfo_29_print_a_given_matrix_in_spiral_form_s1.java
    │   │   ├── sfo_30_min_stack_s1/
    │   │   │   └── sfo_30_min_stack_s1.java
    │   │   ├── sfo_31_validate_stack_sequences_s1/
    │   │   │   └── sfo_31_validate_stack_sequences_s1.java
    │   │   ├── sfo_32i_print_a_binary_tree_topbottom_i_s1/
    │   │   │   └── sfo_32i_print_a_binary_tree_topbottom_i_s1.java
    │   │   ├── sfo_32ii_print_a_binary_tree_topbottom_ii_s1/
    │   │   │   └── sfo_32ii_print_a_binary_tree_topbottom_ii_s1.java
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s1/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s1.java
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s2/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s2.java
    │   │   ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s3/
    │   │   │   └── sfo_32iii_print_a_binary_tree_topbottom_iii_s3.java
    │   │   ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_33_postorder_traversal_of_a_binary_search_tree_s1.java
    │   │   ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s2/
    │   │   │   └── sfo_33_postorder_traversal_of_a_binary_search_tree_s2.java
    │   │   ├── sfo_34_all_xsum_paths_in_a_binary_tree_s1/
    │   │   │   └── sfo_34_all_xsum_paths_in_a_binary_tree_s1.java
    │   │   ├── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1/
    │   │   │   └── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1.java
    │   │   ├── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2/
    │   │   │   └── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2.java
    │   │   ├── sfo_36_binary_search_tree_and_doubly_linked_list_s1/
    │   │   │   └── sfo_36_binary_search_tree_and_doubly_linked_list_s1.java
    │   │   ├── sfo_37_serialize_and_deserialize_a_binary_tree_s1/
    │   │   │   └── sfo_37_serialize_and_deserialize_a_binary_tree_s1.java
    │   │   ├── sfo_38_all_permutations_of_a_string_s1/
    │   │   │   └── sfo_38_all_permutations_of_a_string_s1.java
    │   │   ├── sfo_39_the_majority_element_in_an_array_s1/
    │   │   │   └── sfo_39_the_majority_element_in_an_array_s1.java
    │   │   ├── sfo_39_the_majority_element_in_an_array_s2/
    │   │   │   └── sfo_39_the_majority_element_in_an_array_s2.java
    │   │   ├── sfo_40_the_smallest_k_numbers_s1/
    │   │   │   └── sfo_40_the_smallest_k_numbers_s1.java
    │   │   ├── sfo_40_the_smallest_k_numbers_s2/
    │   │   │   └── sfo_40_the_smallest_k_numbers_s2.java
    │   │   ├── sfo_41_find_median_from_data_stream_s1/
    │   │   │   └── sfo_41_find_median_from_data_stream_s1.java
    │   │   ├── sfo_42_largest_sum_contiguous_subarray_s1/
    │   │   │   └── sfo_42_largest_sum_contiguous_subarray_s1.java
    │   │   ├── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1/
    │   │   │   └── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1.java
    │   │   ├── sfo_44_nth_digit_s1/
    │   │   │   └── sfo_44_nth_digit_s1.java
    │   │   ├── sfo_45_arrange_an_array_into_the_smallest_number_s1/
    │   │   │   └── sfo_45_arrange_an_array_into_the_smallest_number_s1.java
    │   │   ├── sfo_45_arrange_an_array_into_the_smallest_number_s2/
    │   │   │   └── sfo_45_arrange_an_array_into_the_smallest_number_s2.java
    │   │   ├── sfo_46_translate_numbers_into_strings_s1/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s1.java
    │   │   ├── sfo_46_translate_numbers_into_strings_s2/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s2.java
    │   │   ├── sfo_46_translate_numbers_into_strings_s3/
    │   │   │   └── sfo_46_translate_numbers_into_strings_s3.java
    │   │   ├── sfo_47_the_maximum_value_of_gifts_s1/
    │   │   │   └── sfo_47_the_maximum_value_of_gifts_s1.java
    │   │   ├── sfo_47_the_maximum_value_of_gifts_s2/
    │   │   │   └── sfo_47_the_maximum_value_of_gifts_s2.java
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s1/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s1.java
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s2/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s2.java
    │   │   ├── sfo_48_the_longest_substring_without_repeated_characters_s3/
    │   │   │   └── sfo_48_the_longest_substring_without_repeated_characters_s3.java
    │   │   ├── sfo_49_ugly_numbers_s1/
    │   │   │   └── sfo_49_ugly_numbers_s1.java
    │   │   ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1/
    │   │   │   └── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.java
    │   │   ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2/
    │   │   │   └── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.java
    │   │   ├── sfo_51_reversed_pairs_in_an_array_s1/
    │   │   │   └── sfo_51_reversed_pairs_in_an_array_s1.java
    │   │   ├── sfo_52_the_first_common_node_in_two_linked_lists_s1/
    │   │   │   └── sfo_52_the_first_common_node_in_two_linked_lists_s1.java
    │   │   ├── sfo_53i_find_a_number_in_a_sorted_array_s1/
    │   │   │   └── sfo_53i_find_a_number_in_a_sorted_array_s1.java
    │   │   ├── sfo_53i_find_a_number_in_a_sorted_array_s2/
    │   │   │   └── sfo_53i_find_a_number_in_a_sorted_array_s2.java
    │   │   ├── sfo_53ii_the_missing_number_from_0_to_n1_s1/
    │   │   │   └── sfo_53ii_the_missing_number_from_0_to_n1_s1.java
    │   │   ├── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.java
    │   │   ├── sfo_55i_depth_of_a_binary_tree_s1/
    │   │   │   └── sfo_55i_depth_of_a_binary_tree_s1.java
    │   │   ├── sfo_55i_depth_of_a_binary_tree_s2/
    │   │   │   └── sfo_55i_depth_of_a_binary_tree_s2.java
    │   │   ├── sfo_55ii_balanced_binary_tree_s1/
    │   │   │   └── sfo_55ii_balanced_binary_tree_s1.java
    │   │   ├── sfo_55ii_balanced_binary_tree_s2/
    │   │   │   └── sfo_55ii_balanced_binary_tree_s2.java
    │   │   ├── sfo_56i_single_number_i_s1/
    │   │   │   └── sfo_56i_single_number_i_s1.java
    │   │   ├── sfo_56ii_single_number_ii_s1/
    │   │   │   └── sfo_56ii_single_number_ii_s1.java
    │   │   ├── sfo_56ii_single_number_ii_s2/
    │   │   │   └── sfo_56ii_single_number_ii_s2.java
    │   │   ├── sfo_57_two_numbers_with_sum_s_s1/
    │   │   │   └── sfo_57_two_numbers_with_sum_s_s1.java
    │   │   ├── sfo_57ii_consecutive_numbers_with_sum_s_s1/
    │   │   │   └── sfo_57ii_consecutive_numbers_with_sum_s_s1.java
    │   │   ├── sfo_57ii_consecutive_numbers_with_sum_s_s2/
    │   │   │   └── sfo_57ii_consecutive_numbers_with_sum_s_s2.java
    │   │   ├── sfo_58i_reverse_order_of_words_s1/
    │   │   │   └── sfo_58i_reverse_order_of_words_s1.java
    │   │   ├── sfo_58i_reverse_order_of_words_s2/
    │   │   │   └── sfo_58i_reverse_order_of_words_s2.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s1/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s1.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s2/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s2.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s3/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s3.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s4/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s4.java
    │   │   ├── sfo_58ii_left_rotation_of_a_string_s5/
    │   │   │   └── sfo_58ii_left_rotation_of_a_string_s5.java
    │   │   ├── sfo_59i_sliding_window_maximum_s1/
    │   │   │   └── sfo_59i_sliding_window_maximum_s1.java
    │   │   ├── sfo_59i_sliding_window_maximum_s2/
    │   │   │   └── sfo_59i_sliding_window_maximum_s2.java
    │   │   ├── sfo_59ii_max_queue_s1/
    │   │   │   └── sfo_59ii_max_queue_s1.java
    │   │   ├── sfo_60_probabilities_for_rolling_n_dices_s1/
    │   │   │   └── sfo_60_probabilities_for_rolling_n_dices_s1.java
    │   │   ├── sfo_61_straight_in_poker_s1/
    │   │   │   └── sfo_61_straight_in_poker_s1.java
    │   │   ├── sfo_61_straight_in_poker_s2/
    │   │   │   └── sfo_61_straight_in_poker_s2.java
    │   │   ├── sfo_62_josephus_problem_s1/
    │   │   │   └── sfo_62_josephus_problem_s1.java
    │   │   ├── sfo_63_the_maximum_profit_of_stocks_s1/
    │   │   │   └── sfo_63_the_maximum_profit_of_stocks_s1.java
    │   │   ├── sfo_64_solve_1_2___n_s1/
    │   │   │   └── sfo_64_solve_1_2___n_s1.java
    │   │   ├── sfo_64_solve_1_2___n_s2/
    │   │   │   └── sfo_64_solve_1_2___n_s2.java
    │   │   ├── sfo_65_implement_addition_operation_without_arithmetic_operators_s1/
    │   │   │   └── sfo_65_implement_addition_operation_without_arithmetic_operators_s1.java
    │   │   ├── sfo_66_a_product_array_puzzle_s1/
    │   │   │   └── sfo_66_a_product_array_puzzle_s1.java
    │   │   ├── sfo_67_convert_string_to_int_s1/
    │   │   │   └── sfo_67_convert_string_to_int_s1.java
    │   │   ├── sfo_67_convert_string_to_int_s2/
    │   │   │   └── sfo_67_convert_string_to_int_s2.java
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.java
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.java
    │   │   ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3/
    │   │   │   └── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.java
    │   │   ├── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1/
    │   │   │   └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1.java
    │   │   └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2/
    │   │       └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2.java
    │   └── python/
    │       ├── include/
    │       │   ├── __init__.py
    │       │   ├── binary_tree.py
    │       │   ├── linked_list.py
    │       │   └── print_util.py
    │       ├── sfo_03_find_duplicate_numbers_in_an_array_s1.py
    │       ├── sfo_03_find_duplicate_numbers_in_an_array_s2.py
    │       ├── sfo_04_find_a_number_in_2d_matrix_s1.py
    │       ├── sfo_05_replace_spaces_s1.py
    │       ├── sfo_06_print_a_linked_list_in_reverse_order_s1.py
    │       ├── sfo_06_print_a_linked_list_in_reverse_order_s2.py
    │       ├── sfo_07_reconstruct_binary_tree_s1.py
    │       ├── sfo_09_implement_a_queue_using_two_stacks_s1.py
    │       ├── sfo_10i_fibonacci_numbers_s1.py
    │       ├── sfo_10i_fibonacci_numbers_s2.py
    │       ├── sfo_10ii_frog_jump_s1.py
    │       ├── sfo_10ii_frog_jump_s2.py
    │       ├── sfo_11_find_minimum_in_rotated_sorted_array_s1.py
    │       ├── sfo_11_find_minimum_in_rotated_sorted_array_s2.py
    │       ├── sfo_12_word_search_s1.py
    │       ├── sfo_13_range_of_motion_of_a_robot_s1.py
    │       ├── sfo_13_range_of_motion_of_a_robot_s2.py
    │       ├── sfo_14i_cut_the_rope_i_s1.py
    │       ├── sfo_14ii_cut_the_rope_ii_s1.py
    │       ├── sfo_14ii_cut_the_rope_ii_s2.py
    │       ├── sfo_15_number_of_1_bits_s1.py
    │       ├── sfo_15_number_of_1_bits_s2.py
    │       ├── sfo_16_powers_of_integers_s1.py
    │       ├── sfo_17_print_from_1_to_the_largest_n_digits_s1.py
    │       ├── sfo_17_print_from_1_to_the_largest_n_digits_s2.py
    │       ├── sfo_17_print_from_1_to_the_largest_n_digits_s3.py
    │       ├── sfo_17_print_from_1_to_the_largest_n_digits_s4.py
    │       ├── sfo_18_delete_a_node_from_a_linked_list_s1.py
    │       ├── sfo_19_regular_expression_matching_s1.py
    │       ├── sfo_19_regular_expression_matching_s2.py
    │       ├── sfo_20_a_string_representing_a_numeric_value_s1.py
    │       ├── sfo_21_adjust_the_order_of_numbers_in_an_array_s1.py
    │       ├── sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1.py
    │       ├── sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2.py
    │       ├── sfo_24_reverse_a_linked_list_s1.py
    │       ├── sfo_24_reverse_a_linked_list_s2.py
    │       ├── sfo_24_reverse_a_linked_list_s3.py
    │       ├── sfo_25_combine_two_sorted_linked_lists_s1.py
    │       ├── sfo_26_substructure_of_a_binary_tree_s1.py
    │       ├── sfo_27_mirror_of_a_binary_tree_s1.py
    │       ├── sfo_27_mirror_of_a_binary_tree_s2.py
    │       ├── sfo_27_mirror_of_a_binary_tree_s3.py
    │       ├── sfo_28_symmetric_binary_tree_s1.py
    │       ├── sfo_29_print_a_given_matrix_in_spiral_form_s1.py
    │       ├── sfo_30_min_stack_s1.py
    │       ├── sfo_31_validate_stack_sequences_s1.py
    │       ├── sfo_32i_print_a_binary_tree_topbottom_i_s1.py
    │       ├── sfo_32ii_print_a_binary_tree_topbottom_ii_s1.py
    │       ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s1.py
    │       ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s2.py
    │       ├── sfo_32iii_print_a_binary_tree_topbottom_iii_s3.py
    │       ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s1.py
    │       ├── sfo_33_postorder_traversal_of_a_binary_search_tree_s2.py
    │       ├── sfo_34_all_xsum_paths_in_a_binary_tree_s1.py
    │       ├── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1.py
    │       ├── sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2.py
    │       ├── sfo_36_binary_search_tree_and_doubly_linked_list_s1.py
    │       ├── sfo_37_serialize_and_deserialize_a_binary_tree_s1.py
    │       ├── sfo_38_all_permutations_of_a_string_s1.py
    │       ├── sfo_39_the_majority_element_in_an_array_s1.py
    │       ├── sfo_39_the_majority_element_in_an_array_s2.py
    │       ├── sfo_40_the_smallest_k_numbers_s1.py
    │       ├── sfo_40_the_smallest_k_numbers_s2.py
    │       ├── sfo_41_find_median_from_data_stream_s1.py
    │       ├── sfo_41_find_median_from_data_stream_s2.py
    │       ├── sfo_42_largest_sum_contiguous_subarray_s1.py
    │       ├── sfo_43_total_number_of_1_in_integers_from_1_to_n_s1.py
    │       ├── sfo_44_nth_digit_s1.py
    │       ├── sfo_45_arrange_an_array_into_the_smallest_number_s1.py
    │       ├── sfo_45_arrange_an_array_into_the_smallest_number_s2.py
    │       ├── sfo_46_translate_numbers_into_strings_s1.py
    │       ├── sfo_46_translate_numbers_into_strings_s2.py
    │       ├── sfo_46_translate_numbers_into_strings_s3.py
    │       ├── sfo_46_translate_numbers_into_strings_s4.py
    │       ├── sfo_46_translate_numbers_into_strings_s5.py
    │       ├── sfo_47_the_maximum_value_of_gifts_s1.py
    │       ├── sfo_47_the_maximum_value_of_gifts_s2.py
    │       ├── sfo_48_the_longest_substring_without_repeated_characters_s1.py
    │       ├── sfo_48_the_longest_substring_without_repeated_characters_s2.py
    │       ├── sfo_48_the_longest_substring_without_repeated_characters_s3.py
    │       ├── sfo_49_ugly_numbers_s1.py
    │       ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.py
    │       ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.py
    │       ├── sfo_50_find_the_first_nonrepeating_character_in_a_string_s3.py
    │       ├── sfo_51_reversed_pairs_in_an_array_s1.py
    │       ├── sfo_52_the_first_common_node_in_two_linked_lists_s1.py
    │       ├── sfo_53i_find_a_number_in_a_sorted_array_s1.py
    │       ├── sfo_53i_find_a_number_in_a_sorted_array_s2.py
    │       ├── sfo_53ii_the_missing_number_from_0_to_n1_s1.py
    │       ├── sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.py
    │       ├── sfo_55i_depth_of_a_binary_tree_s1.py
    │       ├── sfo_55i_depth_of_a_binary_tree_s2.py
    │       ├── sfo_55ii_balanced_binary_tree_s1.py
    │       ├── sfo_55ii_balanced_binary_tree_s2.py
    │       ├── sfo_56i_single_number_i_s1.py
    │       ├── sfo_56ii_single_number_ii_s1.py
    │       ├── sfo_56ii_single_number_ii_s2.py
    │       ├── sfo_57_two_numbers_with_sum_s_s1.py
    │       ├── sfo_57ii_consecutive_numbers_with_sum_s_s1.py
    │       ├── sfo_57ii_consecutive_numbers_with_sum_s_s2.py
    │       ├── sfo_58i_reverse_order_of_words_s1.py
    │       ├── sfo_58i_reverse_order_of_words_s2.py
    │       ├── sfo_58i_reverse_order_of_words_s3.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s1.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s2.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s3.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s4.py
    │       ├── sfo_58ii_left_rotation_of_a_string_s5.py
    │       ├── sfo_59i_sliding_window_maximum_s1.py
    │       ├── sfo_59i_sliding_window_maximum_s2.py
    │       ├── sfo_59ii_max_queue_s1.py
    │       ├── sfo_60_probabilities_for_rolling_n_dices_s1.py
    │       ├── sfo_61_straight_in_poker_s1.py
    │       ├── sfo_61_straight_in_poker_s2.py
    │       ├── sfo_62_josephus_problem_s1.py
    │       ├── sfo_63_the_maximum_profit_of_stocks_s1.py
    │       ├── sfo_64_solve_1_2___n_s1.py
    │       ├── sfo_65_implement_addition_operation_without_arithmetic_operators_s1.py
    │       ├── sfo_66_a_product_array_puzzle_s1.py
    │       ├── sfo_67_convert_string_to_int_s1.py
    │       ├── sfo_67_convert_string_to_int_s2.py
    │       ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.py
    │       ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.py
    │       ├── sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.py
    │       ├── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1.py
    │       └── sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2.py
    ├── docs/
    │   ├── 剑指 Offer 03. 数组中重复的数字.md
    │   ├── 剑指 Offer 04. 二维数组中的查找.md
    │   ├── 剑指 Offer 05. 替换空格.md
    │   ├── 剑指 Offer 06. 从尾到头打印链表.md
    │   ├── 剑指 Offer 07. 重建二叉树.md
    │   ├── 剑指 Offer 09. 用两个栈实现队列.md
    │   ├── 剑指 Offer 10- I. 斐波那契数列.md
    │   ├── 剑指 Offer 10- II. 青蛙跳台阶问题.md
    │   ├── 剑指 Offer 11. 旋转数组的最小数字.md
    │   ├── 剑指 Offer 12. 矩阵中的路径.md
    │   ├── 剑指 Offer 13. 机器人的运动范围.md
    │   ├── 剑指 Offer 14- I. 剪绳子.md
    │   ├── 剑指 Offer 14- II. 剪绳子 II.md
    │   ├── 剑指 Offer 15. 二进制中 1 的个数.md
    │   ├── 剑指 Offer 16. 数值的整数次方.md
    │   ├── 剑指 Offer 17. 打印从 1 到最大的 n 位数.md
    │   ├── 剑指 Offer 18. 删除链表的节点.md
    │   ├── 剑指 Offer 19. 正则表达式匹配.md
    │   ├── 剑指 Offer 20. 表示数值的字符串.md
    │   ├── 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面.md
    │   ├── 剑指 Offer 22. 链表中倒数第 k 个节点.md
    │   ├── 剑指 Offer 24. 反转链表.md
    │   ├── 剑指 Offer 25. 合并两个排序的链表.md
    │   ├── 剑指 Offer 26. 树的子结构.md
    │   ├── 剑指 Offer 27. 二叉树的镜像.md
    │   ├── 剑指 Offer 28. 对称的二叉树.md
    │   ├── 剑指 Offer 29. 顺时针打印矩阵.md
    │   ├── 剑指 Offer 30. 包含 min 函数的栈.md
    │   ├── 剑指 Offer 31. 栈的压入、弹出序列.md
    │   ├── 剑指 Offer 32 - I. 从上到下打印二叉树.md
    │   ├── 剑指 Offer 32 - II. 从上到下打印二叉树 II.md
    │   ├── 剑指 Offer 32 - III. 从上到下打印二叉树 III.md
    │   ├── 剑指 Offer 33. 二叉搜索树的后序遍历序列.md
    │   ├── 剑指 Offer 34. 二叉树中和为某一值的路径.md
    │   ├── 剑指 Offer 35. 复杂链表的复制.md
    │   ├── 剑指 Offer 36. 二叉搜索树与双向链表.md
    │   ├── 剑指 Offer 37. 序列化二叉树.md
    │   ├── 剑指 Offer 38. 字符串的排列.md
    │   ├── 剑指 Offer 39. 数组中出现次数超过一半的数字.md
    │   ├── 剑指 Offer 40. 最小的 k 个数.md
    │   ├── 剑指 Offer 41. 数据流中的中位数.md
    │   ├── 剑指 Offer 42. 连续子数组的最大和.md
    │   ├── 剑指 Offer 43. 1~n 整数中 1 出现的次数.md
    │   ├── 剑指 Offer 44. 数字序列中某一位的数字.md
    │   ├── 剑指 Offer 45. 把数组排成最小的数.md
    │   ├── 剑指 Offer 46. 把数字翻译成字符串.md
    │   ├── 剑指 Offer 47. 礼物的最大价值.md
    │   ├── 剑指 Offer 48. 最长不含重复字符的子字符串.md
    │   ├── 剑指 Offer 49. 丑数.md
    │   ├── 剑指 Offer 50. 第一个只出现一次的字符.md
    │   ├── 剑指 Offer 51. 数组中的逆序对.md
    │   ├── 剑指 Offer 52. 两个链表的第一个公共节点.md
    │   ├── 剑指 Offer 53 - I. 在排序数组中查找数字 I.md
    │   ├── 剑指 Offer 53 - II. 0~n-1 中缺失的数字.md
    │   ├── 剑指 Offer 54. 二叉搜索树的第 k 大节点.md
    │   ├── 剑指 Offer 55 - I. 二叉树的深度.md
    │   ├── 剑指 Offer 55 - II. 平衡二叉树.md
    │   ├── 剑指 Offer 56 - I. 数组中数字出现的次数.md
    │   ├── 剑指 Offer 56 - II. 数组中数字出现的次数 II.md
    │   ├── 剑指 Offer 57 - II. 和为 s 的连续正数序列.md
    │   ├── 剑指 Offer 57. 和为 s 的两个数字.md
    │   ├── 剑指 Offer 58 - I. 翻转单词顺序.md
    │   ├── 剑指 Offer 58 - II. 左旋转字符串.md
    │   ├── 剑指 Offer 59 - I. 滑动窗口的最大值.md
    │   ├── 剑指 Offer 59 - II. 队列的最大值.md
    │   ├── 剑指 Offer 60. n 个骰子的点数.md
    │   ├── 剑指 Offer 61. 扑克牌中的顺子.md
    │   ├── 剑指 Offer 62. 圆圈中最后剩下的数字.md
    │   ├── 剑指 Offer 63. 股票的最大利润.md
    │   ├── 剑指 Offer 64. 求 1 + 2 + … + n.md
    │   ├── 剑指 Offer 65. 不用加减乘除做加法.md
    │   ├── 剑指 Offer 66. 构建乘积数组.md
    │   ├── 剑指 Offer 67. 把字符串转换成整数.md
    │   ├── 剑指 Offer 68 - I. 二叉搜索树的最近公共祖先.md
    │   └── 剑指 Offer 68 - II. 二叉树的最近公共祖先.md
    ├── 剑指 Offer 刷题计划.md
    └── 剑指 Offer 题目分类.md
Download .txt
Showing preview only (231K chars total). Download the full file or copy to clipboard to get everything.
SYMBOL INDEX (2360 symbols across 724 files)

FILE: selected_coding_interview/codes/cpp/include/ListNode.hpp
  type ListNode (line 17) | struct ListNode {
    method ListNode (line 20) | ListNode(int x) : val(x), next(nullptr) {
  function ListNode (line 30) | ListNode *vectorToLinkedList(vector<int> list) {
    method ListNode (line 20) | ListNode(int x) : val(x), next(nullptr) {
  function ListNode (line 47) | ListNode *getListNode(ListNode *head, int val) {
    method ListNode (line 20) | ListNode(int x) : val(x), next(nullptr) {
  class Node (line 58) | class Node {
    method Node (line 64) | Node(int _val) {

FILE: selected_coding_interview/codes/cpp/include/PrintUtil.hpp
  class PrintUtil (line 16) | class PrintUtil {
    method vecFind (line 26) | static int vecFind(const vector<T> &vec, T ele) {
    method string (line 44) | static string strJoin(const string &delim, const T &vec) {
    method string (line 62) | static string strRepeat(string str, int n) {
    method string (line 76) | static string getVectorString(vector<T> &list) {
    method printVector (line 86) | static void printVector(vector<T> &list) {
    method printVectorMatrix (line 96) | static void printVectorMatrix(vector<vector<T>> &matrix) {
    method printLinkedList (line 108) | static void printLinkedList(ListNode *head) {
    type Trunk (line 122) | struct Trunk {
      method Trunk (line 125) | Trunk(Trunk *prev, string str) {
    method showTrunks (line 136) | static void showTrunks(Trunk *p) {
    method printTree (line 150) | static void printTree(TreeNode *root) {
    method printTree (line 161) | static void printTree(TreeNode *root, Trunk *prev, bool isLeft) {

FILE: selected_coding_interview/codes/cpp/include/TreeNode.hpp
  type TreeNode (line 18) | struct TreeNode {
    method TreeNode (line 22) | TreeNode(int x) : val(x), left(nullptr), right(nullptr) {
  function TreeNode (line 32) | TreeNode *vectorToTree(vector<int> list) {
    method TreeNode (line 22) | TreeNode(int x) : val(x), left(nullptr), right(nullptr) {
  function TreeNode (line 62) | TreeNode *getTreeNode(TreeNode *root, int val) {
    method TreeNode (line 22) | TreeNode(int x) : val(x), left(nullptr), right(nullptr) {

FILE: selected_coding_interview/codes/cpp/lc_101_symmetric_tree/lc_101_symmetric_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method isSymmetric (line 12) | bool isSymmetric(TreeNode* root) {
    method recur (line 16) | bool recur(TreeNode* L, TreeNode* R) {
  function main (line 23) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_102_binary_tree_level_order_traversal/lc_102_binary_tree_level_order_traversal_s1.cpp
  class Solution (line 10) | class Solution {
    method levelOrder (line 12) | vector<vector<int>> levelOrder(TreeNode* root) {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s1.cpp
  class Solution (line 10) | class Solution {
    method zigzagLevelOrder (line 12) | vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
  function main (line 47) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s2.cpp
  class Solution (line 10) | class Solution {
    method zigzagLevelOrder (line 12) | vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
  function main (line 32) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_104_maximum_depth_of_binary_tree/lc_104_maximum_depth_of_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method maxDepth (line 12) | int maxDepth(TreeNode* root) {
  function main (line 18) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_104_maximum_depth_of_binary_tree/lc_104_maximum_depth_of_binary_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method maxDepth (line 12) | int maxDepth(TreeNode* root) {
  function main (line 30) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_105_construct_binary_tree_from_preorder_and_inorder_traversal/lc_105_construct_binary_tree_from_preorder_and_inorder_traversal_s1.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
    method TreeNode (line 21) | TreeNode* recur(int root, int left, int right) {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_10_regular_expression_matching/lc_10_regular_expression_matching_s1.cpp
  class Solution (line 10) | class Solution {
    method isMatch (line 12) | bool isMatch(string s, string p) {
  function main (line 29) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_10_regular_expression_matching/lc_10_regular_expression_matching_s2.cpp
  class Solution (line 10) | class Solution {
    method isMatch (line 12) | bool isMatch(string s, string p) {
  function main (line 36) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_110_balanced_binary_tree/lc_110_balanced_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method isBalanced (line 12) | bool isBalanced(TreeNode* root) {
    method recur (line 16) | int recur(TreeNode* root) {
  function main (line 26) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_110_balanced_binary_tree/lc_110_balanced_binary_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method isBalanced (line 12) | bool isBalanced(TreeNode* root) {
    method depth (line 17) | int depth(TreeNode* root) {
  function main (line 23) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_113_path_sum_ii/lc_113_path_sum_ii_s1.cpp
  class Solution (line 10) | class Solution {
    method pathSum (line 12) | vector<vector<int>> pathSum(TreeNode* root, int targetSum) {
    method recur (line 19) | void recur(TreeNode* root, int tar) {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_11_container_with_most_water/lc_11_container_with_most_water_s1.cpp
  class Solution (line 10) | class Solution {
    method maxArea (line 12) | int maxArea(vector<int>& height) {
  function main (line 23) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_121_best_time_to_buy_and_sell_stock/lc_121_best_time_to_buy_and_sell_stock_s1.cpp
  class Solution (line 10) | class Solution {
    method maxProfit (line 12) | int maxProfit(vector<int>& prices) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_136_single_number/lc_136_single_number_s1.cpp
  class Solution (line 10) | class Solution {
    method singleNumber (line 12) | int singleNumber(vector<int>& nums) {
  function main (line 20) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s1.cpp
  class Node (line 11) | class Node {
    method Node (line 15) | Node(int _val) {
  function main (line 21) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s2.cpp
  class Node (line 11) | class Node {
    method Node (line 16) | Node(int _val) {
  function main (line 23) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s3.cpp
  class Solution (line 10) | class Solution {
    method Node (line 12) | Node* copyRandomList(Node* head) {
  function main (line 26) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s4.cpp
  class Solution (line 10) | class Solution {
    method Node (line 12) | Node* copyRandomList(Node* head) {
  function main (line 33) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s5.cpp
  class Solution (line 10) | class Solution {
    method Node (line 12) | Node* copyRandomList(Node* head) {
  function main (line 43) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_1480_running_sum_of_1d_array/lc_1480_running_sum_of_1d_array_s1.cpp
  class Solution (line 10) | class Solution {
    method runningSum (line 12) | vector<int> runningSum(vector<int>& nums) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_154_find_minimum_in_rotated_sorted_array_ii/lc_154_find_minimum_in_rotated_sorted_array_ii_s1.cpp
  class Solution (line 10) | class Solution {
    method findMin (line 12) | int findMin(vector<int>& nums) {
  function main (line 24) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_154_find_minimum_in_rotated_sorted_array_ii/lc_154_find_minimum_in_rotated_sorted_array_ii_s2.cpp
  class Solution (line 10) | class Solution {
    method findMin (line 12) | int findMin(vector<int>& nums) {
  function main (line 30) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_160_intersection_of_two_linked_lists/lc_160_intersection_of_two_linked_lists_s1.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_167_two_sum_ii_input_array_is_sorted/lc_167_two_sum_ii_input_array_is_sorted_s1.cpp
  class Solution (line 10) | class Solution {
    method twoSum (line 12) | vector<int> twoSum(vector<int>& numbers, int target) {
  function main (line 24) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_169_majority_element/lc_169_majority_element_s1.cpp
  class Solution (line 10) | class Solution {
    method majorityElement (line 12) | int majorityElement(vector<int>& nums) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_169_majority_element/lc_169_majority_element_s2.cpp
  class Solution (line 10) | class Solution {
    method majorityElement (line 12) | int majorityElement(vector<int>& nums) {
  function main (line 25) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_179_largest_number/lc_179_largest_number_s1.cpp
  class Solution (line 10) | class Solution {
    method string (line 12) | string largestNumber(vector<int>& nums) {
  function main (line 26) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_179_largest_number/lc_179_largest_number_s2.cpp
  class Solution (line 10) | class Solution {
    method string (line 12) | string largestNumber(vector<int>& nums) {
    method quickSort (line 25) | void quickSort(vector<string>& strs, int l, int r) {
  function main (line 39) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_1823_find_the_winner_of_the_circular_game/lc_1823_find_the_winner_of_the_circular_game_s1.cpp
  class Solution (line 10) | class Solution {
    method findTheWinner (line 12) | int findTheWinner(int n, int k) {
  function main (line 21) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_191_number_of_1_bits/lc_191_number_of_1_bits_s1.cpp
  class Solution (line 10) | class Solution {
    method hammingWeight (line 12) | int hammingWeight(uint32_t n) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_191_number_of_1_bits/lc_191_number_of_1_bits_s2.cpp
  class Solution (line 10) | class Solution {
    method hammingWeight (line 12) | int hammingWeight(uint32_t n) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_205_isomorphic_strings/lc_205_isomorphic_strings_s1.cpp
  class Solution (line 10) | class Solution {
    method isIsomorphic (line 12) | bool isIsomorphic(string s, string t) {
  function main (line 29) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_206_reverse_linked_list/lc_206_reverse_linked_list_s1.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode* reverseList(ListNode* head) {
  function main (line 24) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_206_reverse_linked_list/lc_206_reverse_linked_list_s2.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode* reverseList(ListNode* head) {
    method ListNode (line 16) | ListNode* recur(ListNode* cur, ListNode* pre) {
  function main (line 24) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_215_kth_largest_element_in_an_array/lc_215_kth_largest_element_in_an_array_s1.cpp
  class Solution (line 10) | class Solution {
    method findKthLargest (line 12) | int findKthLargest(vector<int>& nums, int k) {
    method quickSort (line 17) | void quickSort(vector<int>& nums, int l, int r) {
  function main (line 34) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_215_kth_largest_element_in_an_array/lc_215_kth_largest_element_in_an_array_s2.cpp
  class Solution (line 10) | class Solution {
    method findKthLargest (line 12) | int findKthLargest(vector<int>& nums, int k) {
    method quickSort (line 16) | int quickSort(vector<int>& nums, int k, int l, int r) {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_21_merge_two_sorted_lists/lc_21_merge_two_sorted_lists_s1.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_226_invert_binary_tree/lc_226_invert_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode* invertTree(TreeNode* root) {
  function main (line 21) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_226_invert_binary_tree/lc_226_invert_binary_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode* invertTree(TreeNode* root) {
  function main (line 30) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_230_kth_smallest_element_in_a_bst/lc_230_kth_smallest_element_in_a_bst_s1.cpp
  class Solution (line 10) | class Solution {
    method kthSmallest (line 12) | int kthSmallest(TreeNode* root, int k) {
    method dfs (line 19) | void dfs(TreeNode* root) {
  function main (line 28) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_232_implement_queue_using_stacks/lc_232_implement_queue_using_stacks_s1.cpp
  class MyQueue (line 10) | class MyQueue {
    method MyQueue (line 15) | MyQueue() {}
    method push (line 17) | void push(int x) {
    method pop (line 21) | int pop() {
    method peek (line 27) | int peek() {
    method empty (line 37) | bool empty() {
  function main (line 42) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_233_number_of_digit_one/lc_233_number_of_digit_one_s1.cpp
  function main (line 15) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_233_number_of_digit_one/lc_233_number_of_digit_one_s2.cpp
  function main (line 17) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_233_number_of_digit_one/lc_233_number_of_digit_one_s3.cpp
  class Solution (line 10) | class Solution {
    method countDigitOne (line 12) | int countDigitOne(int n) {
  function main (line 28) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_235_lowest_common_ancestor_of_a_binary_search_tree/lc_235_lowest_common_ancestor_of_a_binary_search_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* ...
  function main (line 24) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_235_lowest_common_ancestor_of_a_binary_search_tree/lc_235_lowest_common_ancestor_of_a_binary_search_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* ...
  function main (line 26) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_235_lowest_common_ancestor_of_a_binary_search_tree/lc_235_lowest_common_ancestor_of_a_binary_search_tree_s3.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* ...
  function main (line 21) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_236_lowest_common_ancestor_of_a_binary_tree/lc_236_lowest_common_ancestor_of_a_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* ...
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_236_lowest_common_ancestor_of_a_binary_tree/lc_236_lowest_common_ancestor_of_a_binary_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* ...
  function main (line 23) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_237_delete_node_in_a_linked_list/lc_237_delete_node_in_a_linked_list_s1.cpp
  class Solution (line 10) | class Solution {
    method deleteNode (line 12) | void deleteNode(ListNode* node) {
  function main (line 18) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_237_delete_node_in_a_linked_list/lc_237_delete_node_in_a_linked_list_s2.cpp
  class Solution (line 10) | class Solution {
    method deleteNode (line 12) | void deleteNode(ListNode* node) {
  function main (line 20) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_238_product_of_array_except_self/lc_238_product_of_array_except_self_s1.cpp
  class Solution (line 10) | class Solution {
    method productExceptSelf (line 12) | vector<int> productExceptSelf(vector<int>& nums) {
  function main (line 29) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_239_sliding_window_maximum/lc_239_sliding_window_maximum_s1.cpp
  class Solution (line 10) | class Solution {
    method maxSlidingWindow (line 12) | vector<int> maxSlidingWindow(vector<int>& nums, int k) {
  function main (line 33) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_239_sliding_window_maximum/lc_239_sliding_window_maximum_s2.cpp
  class Solution (line 10) | class Solution {
    method maxSlidingWindow (line 12) | vector<int> maxSlidingWindow(vector<int>& nums, int k) {
  function main (line 36) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_240_search_a_2d_matrix_ii/lc_240_search_a_2d_matrix_ii_s1.cpp
  class Solution (line 10) | class Solution {
    method searchMatrix (line 12) | bool searchMatrix(vector<vector<int>>& matrix, int target) {
  function main (line 24) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_242_valid_anagram/lc_242_valid_anagram_s1.cpp
  class Solution (line 10) | class Solution {
    method isAnagram (line 12) | bool isAnagram(string s, string t) {
  function main (line 30) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_242_valid_anagram/lc_242_valid_anagram_s2.cpp
  class Solution (line 10) | class Solution {
    method isAnagram (line 12) | bool isAnagram(string s, string t) {
  function main (line 37) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_264_ugly_number_ii/lc_264_ugly_number_ii_s1.cpp
  class Solution (line 10) | class Solution {
    method nthUglyNumber (line 12) | int nthUglyNumber(int n) {
  function main (line 27) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_266_palindrome_permutation/lc_266_palindrome_permutation_s1.cpp
  class Solution (line 10) | class Solution {
    method canPermutePalindrome (line 12) | bool canPermutePalindrome(string s) {
  function main (line 28) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_266_palindrome_permutation/lc_266_palindrome_permutation_s2.cpp
  class Solution (line 10) | class Solution {
    method canPermutePalindrome (line 12) | bool canPermutePalindrome(string s) {
  function main (line 33) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_278_first_bad_version/lc_278_first_bad_version_s1.cpp
  class Solution (line 10) | class Solution {
    method firstBadVersion (line 12) | int firstBadVersion(int n) {
  function main (line 27) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_287_find_the_duplicate_number/lc_287_find_the_duplicate_number_s1.cpp
  class Solution (line 10) | class Solution {
    method findDuplicate (line 12) | int findDuplicate(vector<int>& nums) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_287_find_the_duplicate_number/lc_287_find_the_duplicate_number_s2.cpp
  class Solution (line 10) | class Solution {
    method findDuplicate (line 12) | int findDuplicate(vector<int>& nums) {
  function main (line 27) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_287_find_the_duplicate_number/lc_287_find_the_duplicate_number_s3.cpp
  class Solution (line 10) | class Solution {
    method next (line 13) | int next(int index) {
    method findDuplicate (line 17) | int findDuplicate(vector<int>& nums) {
  function main (line 36) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_295_find_median_from_data_stream/lc_295_find_median_from_data_stream_s1.cpp
  class MedianFinder (line 10) | class MedianFinder {
    method MedianFinder (line 14) | MedianFinder() { }
    method addNum (line 15) | void addNum(int num) {
    method findMedian (line 26) | double findMedian() {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_371_sum_of_two_integers/lc_371_sum_of_two_integers_s1.cpp
  class Solution (line 10) | class Solution {
    method getSum (line 12) | int getSum(int a, int b) {
  function main (line 23) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_387_first_unique_character_in_a_string/lc_387_first_unique_character_in_a_string_s1.cpp
  class Solution (line 10) | class Solution {
    method firstUniqChar (line 12) | int firstUniqChar(string s) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_392_is_subsequence/lc_392_is_subsequence_s1.cpp
  class Solution (line 10) | class Solution {
    method isSubsequence (line 12) | bool isSubsequence(string s, string t) {
  function main (line 25) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_3_longest_substring_without_repeating_characters/lc_3_longest_substring_without_repeating_characters_s1.cpp
  class Solution (line 10) | class Solution {
    method lengthOfLongestSubstring (line 12) | int lengthOfLongestSubstring(string s) {
  function main (line 25) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_3_longest_substring_without_repeating_characters/lc_3_longest_substring_without_repeating_characters_s2.cpp
  class Solution (line 10) | class Solution {
    method lengthOfLongestSubstring (line 12) | int lengthOfLongestSubstring(string s) {
  function main (line 26) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_400_nth_digit/lc_400_nth_digit_s1.cpp
  function main (line 20) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_400_nth_digit/lc_400_nth_digit_s2.cpp
  function main (line 12) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_400_nth_digit/lc_400_nth_digit_s3.cpp
  function main (line 13) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_400_nth_digit/lc_400_nth_digit_s4.cpp
  class Solution (line 10) | class Solution {
    method findNthDigit (line 12) | int findNthDigit(int n) {
  function main (line 27) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_409_longest_palindrome/lc_409_longest_palindrome_s1.cpp
  class Solution (line 10) | class Solution {
    method longestPalindrome (line 12) | int longestPalindrome(string s) {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.cpp
  function dfs (line 11) | void dfs(Node* root) {
  function main (line 18) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.cpp
  class Solution (line 10) | class Solution {
    method Node (line 12) | Node* treeToDoublyList(Node* root) {
    method dfs (line 22) | void dfs(Node* cur) {
  function main (line 33) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_46_permutations/lc_46_permutations_s1.cpp
  class Solution (line 10) | class Solution {
    method permute (line 12) | vector<vector<int>> permute(vector<int>& nums) {
    method dfs (line 18) | void dfs(vector<int> nums, int x) {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_47_permutations_ii/lc_47_permutations_ii_s1.cpp
  class Solution (line 10) | class Solution {
    method permuteUnique (line 12) | vector<vector<int>> permuteUnique(vector<int>& nums) {
    method dfs (line 18) | void dfs(vector<int> nums, int x) {
  function main (line 35) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_48_rotate_image/lc_48_rotate_image_s1.cpp
  class Solution (line 10) | class Solution {
    method rotate (line 12) | void rotate(vector<vector<int>>& matrix) {
  function main (line 25) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_48_rotate_image/lc_48_rotate_image_s2.cpp
  class Solution (line 10) | class Solution {
    method rotate (line 12) | void rotate(vector<vector<int>>& matrix) {
  function main (line 26) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_48_rotate_image/lc_48_rotate_image_s3.cpp
  class Solution (line 10) | class Solution {
    method rotate (line 12) | void rotate(vector<vector<int>>& matrix) {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_509_fibonacci_number/lc_509_fibonacci_number_s1.cpp
  class Solution (line 10) | class Solution {
    method fib (line 12) | int fib(int n) {
  function main (line 23) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_53_maximum_subarray/lc_53_maximum_subarray_s1.cpp
  class Solution (line 10) | class Solution {
    method maxSubArray (line 12) | int maxSubArray(vector<int>& nums) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_54_spiral_matrix/lc_54_spiral_matrix_s1.cpp
  class Solution (line 10) | class Solution {
    method spiralOrder (line 12) | vector<int> spiralOrder(vector<vector<int>>& matrix) {
  function main (line 30) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_65_valid_number/lc_65_valid_number_s1.cpp
  class Solution (line 10) | class Solution {
    method isNumber (line 12) | bool isNumber(string s) {
  function main (line 41) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_6_zigzag_conversion/lc_6_zigzag_conversion_s1.cpp
  class Solution (line 10) | class Solution {
    method string (line 12) | string convert(string s, int numRows) {
  function main (line 30) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_704_binary_search/lc_704_binary_search_s1.cpp
  class Solution (line 10) | class Solution {
    method search (line 12) | int search(vector<int>& nums, int target) {
  function main (line 24) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_70_climbing_stairs/lc_70_climbing_stairs_s1.cpp
  class Solution (line 10) | class Solution {
    method climbStairs (line 12) | int climbStairs(int n) {
  function main (line 23) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_724_find_pivot_index/lc_724_find_pivot_index_s1.cpp
  class Solution (line 10) | class Solution {
    method pivotIndex (line 12) | int pivotIndex(vector<int>& nums) {
  function main (line 25) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_796_rotate_string/lc_796_rotate_string_s1.cpp
  class Solution (line 10) | class Solution {
    method rotateString (line 12) | bool rotateString(string s, string goal) {
  function main (line 17) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_79_word_search/lc_79_word_search_s1.cpp
  class Solution (line 10) | class Solution {
    method exist (line 12) | bool exist(vector<vector<char>>& board, string word) {
    method dfs (line 24) | bool dfs(vector<vector<char>>& board, string word, int i, int j, int k) {
  function main (line 35) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_86_partition_list/lc_86_partition_list_s1.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode* partition(ListNode* head, int x) {
  function main (line 31) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_86_partition_list/lc_86_partition_list_s2.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode* partition(ListNode* head, int x) {
  function main (line 36) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_876_middle_of_the_linked_list/lc_876_middle_of_the_linked_list_s1.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode* middleNode(ListNode* head) {
  function main (line 22) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_8_string_to_integer_atoi/lc_8_string_to_integer_atoi_s1.cpp
  class Solution (line 10) | class Solution {
    method myAtoi (line 12) | int myAtoi(string s) {
  function main (line 30) | int main() {

FILE: selected_coding_interview/codes/cpp/lc_946_validate_stack_sequences/lc_946_validate_stack_sequences_s1.cpp
  class Solution (line 10) | class Solution {
    method validateStackSequences (line 12) | bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
  function main (line 26) | int main() {

FILE: selected_coding_interview/codes/java/include/ListNode.java
  class ListNode (line 8) | public class ListNode {
    method ListNode (line 12) | public ListNode(int x) {
    method arrToLinkedList (line 22) | public static ListNode arrToLinkedList(int[] arr) {
    method getListNode (line 39) | public static ListNode getListNode(ListNode head, int val) {

FILE: selected_coding_interview/codes/java/include/PrintUtil.java
  class Trunk (line 5) | class Trunk {
    method Trunk (line 9) | Trunk(Trunk prev, String str) {
  class PrintUtil (line 15) | public class PrintUtil {
    method printLinkedList (line 21) | public static void printLinkedList(ListNode head) {
    method printTree (line 37) | public static void printTree(TreeNode root) {
    method printTree (line 48) | public static void printTree(TreeNode root, Trunk prev, boolean isLeft) {
    method showTrunks (line 79) | public static void showTrunks(Trunk p) {

FILE: selected_coding_interview/codes/java/include/TreeNode.java
  class TreeNode (line 8) | public class TreeNode {
    method TreeNode (line 13) | public TreeNode(int x) {
    method arrToTree (line 23) | public static TreeNode arrToTree(Integer[] arr) {
    method treeToList (line 53) | public static List<Integer> treeToList(TreeNode root) {
    method getTreeNode (line 82) | public static TreeNode getTreeNode(TreeNode root, int val) {

FILE: selected_coding_interview/codes/java/lc_101_symmetric_tree/lc_101_symmetric_tree.java
  class Solution (line 13) | class Solution {
    method isSymmetric (line 14) | public boolean isSymmetric(TreeNode root) {
    method recur (line 17) | boolean recur(TreeNode L, TreeNode R) {
  class lc_101_symmetric_tree (line 24) | public class lc_101_symmetric_tree {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_102_binary_tree_level_order_traversal/lc_102_binary_tree_level_order_traversal.java
  class Solution (line 13) | class Solution {
    method levelOrder (line 14) | public List<List<Integer>> levelOrder(TreeNode root) {
  class lc_102_binary_tree_level_order_traversal (line 32) | public class lc_102_binary_tree_level_order_traversal {
    method main (line 33) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s1.java
  class Solution (line 13) | class Solution {
    method zigzagLevelOrder (line 14) | public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
  class lc_103_binary_tree_zigzag_level_order_traversal_s1 (line 33) | public class lc_103_binary_tree_zigzag_level_order_traversal_s1 {
    method main (line 34) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s2.java
  class Solution (line 13) | class Solution {
    method zigzagLevelOrder (line 14) | public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
  class lc_103_binary_tree_zigzag_level_order_traversal_s2 (line 47) | public class lc_103_binary_tree_zigzag_level_order_traversal_s2 {
    method main (line 48) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s3.java
  class Solution (line 13) | class Solution {
    method zigzagLevelOrder (line 14) | public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
  class lc_103_binary_tree_zigzag_level_order_traversal_s3 (line 33) | public class lc_103_binary_tree_zigzag_level_order_traversal_s3 {
    method main (line 34) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_104_maximum_depth_of_binary_tree/lc_104_maximum_depth_of_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method maxDepth (line 14) | public int maxDepth(TreeNode root) {
  class lc_104_maximum_depth_of_binary_tree_s1 (line 20) | public class lc_104_maximum_depth_of_binary_tree_s1 {
    method main (line 21) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_104_maximum_depth_of_binary_tree/lc_104_maximum_depth_of_binary_tree_s2.java
  class Solution (line 13) | class Solution {
    method maxDepth (line 14) | public int maxDepth(TreeNode root) {
  class lc_104_maximum_depth_of_binary_tree_s2 (line 31) | public class lc_104_maximum_depth_of_binary_tree_s2 {
    method main (line 32) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_105_construct_binary_tree_from_preorder_and_inorder_traversal/lc_105_construct_binary_tree_from_preorder_and_inorder_traversal.java
  class Solution (line 13) | class Solution {
    method buildTree (line 16) | public TreeNode buildTree(int[] preorder, int[] inorder) {
    method recur (line 22) | TreeNode recur(int root, int left, int right) {
  class lc_105_construct_binary_tree_from_preorder_and_inorder_traversal (line 32) | public class lc_105_construct_binary_tree_from_preorder_and_inorder_trav...
    method main (line 33) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_10_regular_expression_matching/lc_10_regular_expression_matching_s1.java
  class Solution (line 13) | class Solution {
    method isMatch (line 14) | public boolean isMatch(String s, String p) {
  class lc_10_regular_expression_matching_s1 (line 31) | public class lc_10_regular_expression_matching_s1 {
    method main (line 32) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_10_regular_expression_matching/lc_10_regular_expression_matching_s2.java
  class Solution (line 13) | class Solution {
    method isMatch (line 14) | public boolean isMatch(String s, String p) {
  class lc_10_regular_expression_matching_s2 (line 38) | public class lc_10_regular_expression_matching_s2 {
    method main (line 39) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_110_balanced_binary_tree/lc_110_balanced_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method isBalanced (line 14) | public boolean isBalanced(TreeNode root) {
    method recur (line 17) | private int recur(TreeNode root) {
  class lc_110_balanced_binary_tree_s1 (line 27) | public class lc_110_balanced_binary_tree_s1 {
    method main (line 28) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_110_balanced_binary_tree/lc_110_balanced_binary_tree_s2.java
  class Solution (line 13) | class Solution {
    method isBalanced (line 14) | public boolean isBalanced(TreeNode root) {
    method depth (line 18) | private int depth(TreeNode root) {
  class lc_110_balanced_binary_tree_s2 (line 24) | public class lc_110_balanced_binary_tree_s2 {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_113_path_sum/lc_113_path_sum.java
  class Solution (line 13) | class Solution {
    method pathSum (line 16) | public List<List<Integer>> pathSum(TreeNode root, int targetSum) {
    method recur (line 20) | void recur(TreeNode root, int tar) {
  class lc_113_path_sum (line 32) | public class lc_113_path_sum {
    method main (line 33) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_11_container_with_most_water/lc_11_container_with_most_water.java
  class Solution (line 13) | class Solution {
    method maxArea (line 14) | public int maxArea(int[] height) {
  class lc_11_container_with_most_water (line 25) | public class lc_11_container_with_most_water {
    method main (line 26) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_121_best_time_to_buy_and_sell_stock/lc_121_best_time_to_buy_and_sell_stock.java
  class Solution (line 13) | class Solution {
    method maxProfit (line 14) | public int maxProfit(int[] prices) {
  class lc_121_best_time_to_buy_and_sell_stock (line 24) | public class lc_121_best_time_to_buy_and_sell_stock {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_122_best_time_to_buy_and_sell_stock/lc_122_best_time_to_buy_and_sell_stock.java
  class Solution (line 13) | class Solution {
    method maxProfit (line 14) | public int maxProfit(int[] prices) {
  class lc_122_best_time_to_buy_and_sell_stock (line 24) | public class lc_122_best_time_to_buy_and_sell_stock {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_135_candy/lc_135_candy.java
  class Solution (line 13) | class Solution {
    method candy (line 14) | public int candy(int[] ratings) {
  class lc_135_candy (line 30) | public class lc_135_candy {
    method main (line 31) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_136_single_number/lc_136_single_number.java
  class Solution (line 13) | class Solution {
    method singleNumber (line 14) | public int singleNumber(int[] nums) {
  class lc_136_single_number (line 22) | public class lc_136_single_number {
    method main (line 23) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_137_single_number/lc_137_single_number_s1.java
  class Solution (line 13) | class Solution {
    method singleNumber (line 14) | public int singleNumber(int[] nums) {
  class lc_137_single_number_s1 (line 24) | public class lc_137_single_number_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_137_single_number/lc_137_single_number_s2.java
  class Solution (line 13) | class Solution {
    method singleNumber (line 14) | public int singleNumber(int[] nums) {
  class lc_137_single_number_s2 (line 31) | public class lc_137_single_number_s2 {
    method main (line 32) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s1.java
  class Node (line 14) | class Node {
    method Node (line 17) | public Node(int val) {
  class lc_138_copy_list_with_random_pointer_s1 (line 23) | public class lc_138_copy_list_with_random_pointer_s1 {
    method main (line 24) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s2.java
  class Node (line 14) | class Node {
    method Node (line 17) | public Node(int val) {
  class lc_138_copy_list_with_random_pointer_s2 (line 24) | public class lc_138_copy_list_with_random_pointer_s2 {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s3.java
  class Solution (line 13) | class Solution {
    method copyRandomList (line 14) | public Node copyRandomList(Node head) {
  class lc_138_copy_list_with_random_pointer_s3 (line 28) | public class lc_138_copy_list_with_random_pointer_s3 {
    method main (line 29) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s4.java
  class Solution (line 13) | class Solution {
    method copyRandomList (line 14) | public Node copyRandomList(Node head) {
  class lc_138_copy_list_with_random_pointer_s4 (line 35) | public class lc_138_copy_list_with_random_pointer_s4 {
    method main (line 36) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s5.java
  class Solution (line 13) | class Solution {
    method copyRandomList (line 14) | public Node copyRandomList(Node head) {
  class lc_138_copy_list_with_random_pointer_s5 (line 45) | public class lc_138_copy_list_with_random_pointer_s5 {
    method main (line 46) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_142_linked_list_cycle/lc_142_linked_list_cycle.java
  class Solution (line 13) | public class Solution {
    method detectCycle (line 14) | public ListNode detectCycle(ListNode head) {
  class lc_142_linked_list_cycle (line 31) | public class lc_142_linked_list_cycle {
    method main (line 32) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_1480_running_sum_of_1d_array/lc_1480_running_sum_of_1d_array.java
  class Solution (line 13) | class Solution {
    method runningSum (line 14) | public int[] runningSum(int[] nums) {
  class lc_1480_running_sum_of_1d_array (line 24) | public class lc_1480_running_sum_of_1d_array {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_151_reverse_words_in_a_string/lc_151_reverse_words_in_a_string_s1.java
  class Solution (line 13) | class Solution {
    method reverseWords (line 14) | public String reverseWords(String s) {
  class lc_151_reverse_words_in_a_string_s1 (line 28) | public class lc_151_reverse_words_in_a_string_s1 {
    method main (line 29) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_151_reverse_words_in_a_string/lc_151_reverse_words_in_a_string_s2.java
  class Solution (line 13) | class Solution {
    method reverseWords (line 14) | public String reverseWords(String s) {
  class lc_151_reverse_words_in_a_string_s2 (line 25) | public class lc_151_reverse_words_in_a_string_s2 {
    method main (line 26) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_154_find_minimum_in_rotated_sorted_array/lc_154_find_minimum_in_rotated_sorted_array_s1.java
  class Solution (line 13) | class Solution {
    method findMin (line 14) | public int findMin(int[] nums) {
  class lc_154_find_minimum_in_rotated_sorted_array_s1 (line 26) | public class lc_154_find_minimum_in_rotated_sorted_array_s1 {
    method main (line 27) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_154_find_minimum_in_rotated_sorted_array/lc_154_find_minimum_in_rotated_sorted_array_s2.java
  class Solution (line 13) | class Solution {
    method findMin (line 14) | public int findMin(int[] nums) {
  class lc_154_find_minimum_in_rotated_sorted_array_s2 (line 32) | public class lc_154_find_minimum_in_rotated_sorted_array_s2 {
    method main (line 33) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_155_min_stack/lc_155_min_stack.java
  class MinStack (line 13) | class MinStack {
    method MinStack (line 16) | public MinStack() {
    method push (line 20) | public void push(int x) {
    method pop (line 25) | public void pop() {
    method top (line 29) | public int top() {
    method getMin (line 32) | public int getMin() {
  class lc_155_min_stack (line 37) | public class lc_155_min_stack {
    method main (line 38) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_15_three_sum/lc_15_three_sum.java
  class Solution (line 13) | class Solution {
    method threeSum (line 14) | public List<List<Integer>> threeSum(int[] nums) {
  class lc_15_three_sum (line 38) | public class lc_15_three_sum {
    method main (line 39) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_160_intersection_of_two_linked_lists/lc_160_intersection_of_two_linked_lists.java
  class Solution (line 13) | public class Solution {
    method getIntersectionNode (line 14) | public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
  class lc_160_intersection_of_two_linked_lists (line 24) | public class lc_160_intersection_of_two_linked_lists {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_167_two_sum/lc_167_two_sum.java
  class Solution (line 13) | class Solution {
    method twoSum (line 14) | public int[] twoSum(int[] numbers, int target) {
  class lc_167_two_sum (line 26) | public class lc_167_two_sum {
    method main (line 27) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_169_majority_element/lc_169_majority_element_s1.java
  class Solution (line 13) | class Solution {
    method majorityElement (line 14) | public int majorityElement(int[] nums) {
  class lc_169_majority_element_s1 (line 24) | public class lc_169_majority_element_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_169_majority_element/lc_169_majority_element_s2.java
  class Solution (line 13) | class Solution {
    method majorityElement (line 14) | public int majorityElement(int[] nums) {
  class lc_169_majority_element_s2 (line 27) | public class lc_169_majority_element_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_179_largest_number/lc_179_largest_number_s1.java
  class Solution (line 13) | class Solution {
    method largestNumber (line 14) | public String largestNumber(int[] nums) {
  class lc_179_largest_number_s1 (line 28) | public class lc_179_largest_number_s1 {
    method main (line 29) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_179_largest_number/lc_179_largest_number_s2.java
  class Solution (line 13) | class Solution {
    method quickSort (line 14) | void quickSort(String[] strs, int l, int r) {
    method largestNumber (line 30) | public String largestNumber(int[] nums) {
  class lc_179_largest_number_s2 (line 44) | public class lc_179_largest_number_s2 {
    method main (line 45) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_1823_find_the_winner_of_the_circular_game/lc_1823_find_the_winner_of_the_circular_game.java
  class Solution (line 13) | class Solution {
    method findTheWinner (line 14) | public int findTheWinner(int n, int k) {
  class lc_1823_find_the_winner_of_the_circular_game (line 23) | public class lc_1823_find_the_winner_of_the_circular_game {
    method main (line 24) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_191_number_of_1_bits/lc_191_number_of_1_bits_s1.java
  class Solution (line 13) | public class Solution {
    method hammingWeight (line 14) | public int hammingWeight(int n) {
  class lc_191_number_of_1_bits_s1 (line 24) | public class lc_191_number_of_1_bits_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_191_number_of_1_bits/lc_191_number_of_1_bits_s2.java
  class Solution (line 13) | public class Solution {
    method hammingWeight (line 14) | public int hammingWeight(int n) {
  class lc_191_number_of_1_bits_s2 (line 24) | public class lc_191_number_of_1_bits_s2 {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_198_house_robber/lc_198_house_robber.java
  class Solution (line 13) | class Solution {
    method rob (line 14) | public int rob(int[] nums) {
  class lc_198_house_robber (line 25) | public class lc_198_house_robber {
    method main (line 26) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_205_isomorphic_strings/lc_205_isomorphic_strings.java
  class Solution (line 13) | class Solution {
    method isIsomorphic (line 14) | public boolean isIsomorphic(String s, String t) {
  class lc_205_isomorphic_strings (line 31) | public class lc_205_isomorphic_strings {
    method main (line 32) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_206_reverse_linked_list/lc_206_reverse_linked_list_s1.java
  class Solution (line 13) | class Solution {
    method reverseList (line 14) | public ListNode reverseList(ListNode head) {
  class lc_206_reverse_linked_list_s1 (line 26) | public class lc_206_reverse_linked_list_s1 {
    method main (line 27) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_206_reverse_linked_list/lc_206_reverse_linked_list_s2.java
  class Solution (line 13) | class Solution {
    method reverseList (line 14) | public ListNode reverseList(ListNode head) {
    method recur (line 17) | private ListNode recur(ListNode cur, ListNode pre) {
  class lc_206_reverse_linked_list_s2 (line 25) | public class lc_206_reverse_linked_list_s2 {
    method main (line 26) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_207_course_schedule/lc_207_course_schedule_s1.java
  class Solution (line 13) | class Solution {
    method canFinish (line 14) | public boolean canFinish(int numCourses, int[][] prerequisites) {
  class lc_207_course_schedule_s1 (line 39) | public class lc_207_course_schedule_s1 {
    method main (line 40) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_207_course_schedule/lc_207_course_schedule_s2.java
  class Solution (line 13) | class Solution {
    method canFinish (line 14) | public boolean canFinish(int numCourses, int[][] prerequisites) {
    method dfs (line 25) | private boolean dfs(List<List<Integer>> adjacency, int[] flags, int i) {
  class lc_207_course_schedule_s2 (line 36) | public class lc_207_course_schedule_s2 {
    method main (line 37) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_20_valid_parentheses/lc_20_valid_parentheses.java
  class Solution (line 13) | class Solution {
    method isValid (line 17) | public boolean isValid(String s) {
  class lc_20_valid_parentheses (line 28) | public class lc_20_valid_parentheses {
    method main (line 29) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_213_house_robber/lc_213_house_robber.java
  class Solution (line 13) | class Solution {
    method rob (line 14) | public int rob(int[] nums) {
    method myRob (line 20) | private int myRob(int[] nums) {
  class lc_213_house_robber (line 31) | public class lc_213_house_robber {
    method main (line 32) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_215_kth_largest_element_in_an_array/lc_215_kth_largest_element_in_an_array_s1.java
  class Solution (line 13) | class Solution {
    method swap (line 14) | private void swap(int[] nums, int i, int j) {
    method quickSort (line 19) | private void quickSort(int[] nums, int l, int r) {
    method findKthLargest (line 34) | public int findKthLargest(int[] nums, int k) {
  class lc_215_kth_largest_element_in_an_array_s1 (line 40) | public class lc_215_kth_largest_element_in_an_array_s1 {
    method main (line 41) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_215_kth_largest_element_in_an_array/lc_215_kth_largest_element_in_an_array_s2.java
  class Solution (line 13) | class Solution {
    method swap (line 14) | private void swap(int[] nums, int i, int j) {
    method quickSort (line 19) | private int quickSort(int[] nums, int k, int l, int r) {
    method findKthLargest (line 32) | public int findKthLargest(int[] nums, int k) {
  class lc_215_kth_largest_element_in_an_array_s2 (line 37) | public class lc_215_kth_largest_element_in_an_array_s2 {
    method main (line 38) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_21_merge_two_sorted_lists/lc_21_merge_two_sorted_lists.java
  class Solution (line 13) | class Solution {
    method mergeTwoLists (line 14) | public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
  class lc_21_merge_two_sorted_lists (line 32) | public class lc_21_merge_two_sorted_lists {
    method main (line 33) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_226_invert_binary_tree/lc_226_invert_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method invertTree (line 14) | public TreeNode invertTree(TreeNode root) {
  class lc_226_invert_binary_tree_s1 (line 23) | public class lc_226_invert_binary_tree_s1 {
    method main (line 24) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_226_invert_binary_tree/lc_226_invert_binary_tree_s2.java
  class Solution (line 13) | class Solution {
    method invertTree (line 14) | public TreeNode invertTree(TreeNode root) {
  class lc_226_invert_binary_tree_s2 (line 29) | public class lc_226_invert_binary_tree_s2 {
    method main (line 30) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_230_kth_smallest_element_in_a_bst/lc_230_kth_smallest_element_in_a_bst.java
  class Solution (line 13) | class Solution {
    method dfs (line 15) | void dfs(TreeNode root) {
    method kthSmallest (line 22) | public int kthSmallest(TreeNode root, int k) {
  class lc_230_kth_smallest_element_in_a_bst (line 29) | public class lc_230_kth_smallest_element_in_a_bst {
    method main (line 30) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_231_power_of_two/lc_231_power_of_two.java
  class Solution (line 13) | class Solution {
    method isPowerOfTwo (line 14) | public boolean isPowerOfTwo(int n) {
  class lc_231_power_of_two (line 19) | public class lc_231_power_of_two {
    method main (line 20) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_232_implement_queue_using_stacks/lc_232_implement_queue_using_stacks.java
  class MyQueue (line 13) | class MyQueue {
    method MyQueue (line 16) | public MyQueue() {
    method push (line 20) | public void push(int x) {
    method pop (line 23) | public int pop() {
    method peek (line 28) | public int peek() {
    method empty (line 36) | public boolean empty() {
  class lc_232_implement_queue_using_stacks (line 41) | public class lc_232_implement_queue_using_stacks {
    method main (line 42) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_233_number_of_digit_one/lc_233_number_of_digit_one_s1.java
  class lc_233_number_of_digit_one_s1 (line 18) | public class lc_233_number_of_digit_one_s1 {
    method main (line 19) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_233_number_of_digit_one/lc_233_number_of_digit_one_s2.java
  class lc_233_number_of_digit_one_s2 (line 20) | public class lc_233_number_of_digit_one_s2 {
    method main (line 21) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_233_number_of_digit_one/lc_233_number_of_digit_one_s3.java
  class Solution (line 13) | class Solution {
    method countDigitOne (line 14) | public int countDigitOne(int n) {
  class lc_233_number_of_digit_one_s3 (line 30) | public class lc_233_number_of_digit_one_s3 {
    method main (line 31) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_235_lowest_common_ancestor_of_bst/lc_235_lowest_common_ancestor_of_bst_s1.java
  class Solution (line 13) | class Solution {
    method lowestCommonAncestor (line 14) | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNo...
  class lc_235_lowest_common_ancestor_of_bst_s1 (line 26) | public class lc_235_lowest_common_ancestor_of_bst_s1 {
    method main (line 27) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_235_lowest_common_ancestor_of_bst/lc_235_lowest_common_ancestor_of_bst_s2.java
  class Solution (line 13) | class Solution {
    method lowestCommonAncestor (line 14) | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNo...
  class lc_235_lowest_common_ancestor_of_bst_s2 (line 31) | public class lc_235_lowest_common_ancestor_of_bst_s2 {
    method main (line 32) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_235_lowest_common_ancestor_of_bst/lc_235_lowest_common_ancestor_of_bst_s3.java
  class Solution (line 13) | class Solution {
    method lowestCommonAncestor (line 14) | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNo...
  class lc_235_lowest_common_ancestor_of_bst_s3 (line 23) | public class lc_235_lowest_common_ancestor_of_bst_s3 {
    method main (line 24) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_236_lowest_common_ancestor_of_binary_tree/lc_236_lowest_common_ancestor_of_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method lowestCommonAncestor (line 14) | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNo...
  class lc_236_lowest_common_ancestor_of_binary_tree_s1 (line 24) | public class lc_236_lowest_common_ancestor_of_binary_tree_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_236_lowest_common_ancestor_of_binary_tree/lc_236_lowest_common_ancestor_of_binary_tree_s2.java
  class Solution (line 13) | class Solution {
    method lowestCommonAncestor (line 14) | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNo...
  class lc_236_lowest_common_ancestor_of_binary_tree_s2 (line 25) | public class lc_236_lowest_common_ancestor_of_binary_tree_s2 {
    method main (line 26) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_237_delete_node_in_linked_list/lc_237_delete_node_in_linked_list_s1.java
  class Solution (line 13) | class Solution {
    method deleteNode (line 14) | public void deleteNode(ListNode node) {
  class lc_237_delete_node_in_linked_list_s1 (line 20) | public class lc_237_delete_node_in_linked_list_s1 {
    method main (line 21) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_237_delete_node_in_linked_list/lc_237_delete_node_in_linked_list_s2.java
  class Solution (line 13) | class Solution {
    method deleteNode (line 14) | public void deleteNode(ListNode node) {
  class lc_237_delete_node_in_linked_list_s2 (line 22) | public class lc_237_delete_node_in_linked_list_s2 {
    method main (line 23) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_238_product_of_array_except_self/lc_238_product_of_array_except_self.java
  class Solution (line 13) | class Solution {
    method productExceptSelf (line 14) | public int[] productExceptSelf(int[] nums) {
  class lc_238_product_of_array_except_self (line 31) | public class lc_238_product_of_array_except_self {
    method main (line 32) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_239_sliding_window_maximum/lc_239_sliding_window_maximum_s1.java
  class Solution (line 13) | class Solution {
    method maxSlidingWindow (line 14) | public int[] maxSlidingWindow(int[] nums, int k) {
  class lc_239_sliding_window_maximum_s1 (line 34) | public class lc_239_sliding_window_maximum_s1 {
    method main (line 35) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_239_sliding_window_maximum/lc_239_sliding_window_maximum_s2.java
  class Solution (line 13) | class Solution {
    method maxSlidingWindow (line 14) | public int[] maxSlidingWindow(int[] nums, int k) {
  class lc_239_sliding_window_maximum_s2 (line 38) | public class lc_239_sliding_window_maximum_s2 {
    method main (line 39) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_240_search_a_2d_matrix/lc_240_search_a_2d_matrix.java
  class Solution (line 13) | class Solution {
    method searchMatrix (line 14) | public boolean searchMatrix(int[][] matrix, int target) {
  class lc_240_search_a_2d_matrix (line 26) | public class lc_240_search_a_2d_matrix {
    method main (line 27) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_242_valid_anagram/lc_242_valid_anagram_s1.java
  class Solution (line 13) | class Solution {
    method isAnagram (line 14) | public boolean isAnagram(String s, String t) {
  class lc_242_valid_anagram_s1 (line 33) | public class lc_242_valid_anagram_s1 {
    method main (line 34) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_242_valid_anagram/lc_242_valid_anagram_s2.java
  class Solution (line 13) | class Solution {
    method isAnagram (line 14) | public boolean isAnagram(String s, String t) {
  class lc_242_valid_anagram_s2 (line 41) | public class lc_242_valid_anagram_s2 {
    method main (line 42) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_264_ugly_number/lc_264_ugly_number.java
  class Solution (line 13) | class Solution {
    method nthUglyNumber (line 14) | public int nthUglyNumber(int n) {
  class lc_264_ugly_number (line 29) | public class lc_264_ugly_number {
    method main (line 30) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_266_palindrome_permutation/lc_266_palindrome_permutation_s1.java
  class Solution (line 13) | class Solution {
    method canPermutePalindrome (line 14) | public boolean canPermutePalindrome(String s) {
  class lc_266_palindrome_permutation_s1 (line 30) | public class lc_266_palindrome_permutation_s1 {
    method main (line 31) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_266_palindrome_permutation/lc_266_palindrome_permutation_s2.java
  class Solution (line 13) | class Solution {
    method canPermutePalindrome (line 14) | public boolean canPermutePalindrome(String s) {
  class lc_266_palindrome_permutation_s2 (line 35) | public class lc_266_palindrome_permutation_s2 {
    method main (line 36) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_278_first_bad_version/lc_278_first_bad_version.java
  class Solution (line 13) | public class Solution extends VersionControl {
    method firstBadVersion (line 14) | public int firstBadVersion(int n) {
  class lc_278_first_bad_version (line 29) | public class lc_278_first_bad_version {
    method main (line 30) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_287_find_the_duplicate_number/lc_287_find_the_duplicate_number_s1.java
  class Solution (line 13) | class Solution {
    method findDuplicate (line 14) | public int findDuplicate(int[] nums) {
  class lc_287_find_the_duplicate_number_s1 (line 24) | public class lc_287_find_the_duplicate_number_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_287_find_the_duplicate_number/lc_287_find_the_duplicate_number_s2.java
  class Solution (line 13) | class Solution {
    method findDuplicate (line 14) | public int findDuplicate(int[] nums) {
  class lc_287_find_the_duplicate_number_s2 (line 30) | public class lc_287_find_the_duplicate_number_s2 {
    method main (line 31) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_287_find_the_duplicate_number/lc_287_find_the_duplicate_number_s3.java
  class Solution (line 13) | public class Solution {
    method next (line 14) | private int next(int[] nums, int index) {
    method findDuplicate (line 17) | public int findDuplicate(int[] nums) {
  class lc_287_find_the_duplicate_number_s3 (line 35) | public class lc_287_find_the_duplicate_number_s3 {
    method main (line 36) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_295_find_median_from_data_stream/lc_295_find_median_from_data_stream.java
  class MedianFinder (line 13) | class MedianFinder {
    method MedianFinder (line 15) | public MedianFinder() {
    method addNum (line 19) | public void addNum(int num) {
    method findMedian (line 28) | public double findMedian() {
  class lc_295_find_median_from_data_stream (line 33) | public class lc_295_find_median_from_data_stream {
    method main (line 34) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_297_serialize_and_deserialize_binary_tree/lc_297_serialize_and_deserialize_binary_tree.java
  class Codec (line 13) | public class Codec {
    method serialize (line 14) | public String serialize(TreeNode root) {
    method deserialize (line 31) | public TreeNode deserialize(String data) {
  class lc_297_serialize_and_deserialize_binary_tree (line 54) | public class lc_297_serialize_and_deserialize_binary_tree {
    method main (line 55) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_300_longest_increasing_subsequence/lc_300_longest_increasing_subsequence_s1.java
  class Solution (line 14) | class Solution {
    method lengthOfLIS (line 15) | public int lengthOfLIS(int[] nums) {
  class lc_300_longest_increasing_subsequence_s1 (line 30) | public class lc_300_longest_increasing_subsequence_s1 {
    method main (line 31) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_300_longest_increasing_subsequence/lc_300_longest_increasing_subsequence_s2.java
  class Solution (line 14) | class Solution {
    method lengthOfLIS (line 15) | public int lengthOfLIS(int[] nums) {
  class lc_300_longest_increasing_subsequence_s2 (line 32) | public class lc_300_longest_increasing_subsequence_s2 {
    method main (line 33) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_343_integer_break/lc_343_integer_break.java
  class Solution (line 13) | class Solution {
    method integerBreak (line 14) | public int integerBreak(int n) {
  class lc_343_integer_break (line 23) | public class lc_343_integer_break {
    method main (line 24) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_371_sum_of_two_integers/lc_371_sum_of_two_integers.java
  class Solution (line 13) | class Solution {
    method getSum (line 14) | public int getSum(int a, int b) {
  class lc_371_sum_of_two_integers (line 25) | public class lc_371_sum_of_two_integers {
    method main (line 26) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_387_first_unique_character_in_a_string/lc_387_first_unique_character_in_a_string.java
  class Solution (line 13) | class Solution {
    method firstUniqChar (line 14) | public int firstUniqChar(String s) {
  class lc_387_first_unique_character_in_a_string (line 25) | public class lc_387_first_unique_character_in_a_string {
    method main (line 26) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_392_is_subsequence/lc_392_is_subsequence.java
  class Solution (line 13) | class Solution {
    method isSubsequence (line 14) | public boolean isSubsequence(String s, String t) {
  class lc_392_is_subsequence (line 27) | public class lc_392_is_subsequence {
    method main (line 28) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_394_decode_string/lc_394_decode_string_s1.java
  class Solution (line 13) | class Solution {
    method decodeString (line 14) | public String decodeString(String s) {
  class lc_394_decode_string_s1 (line 39) | public class lc_394_decode_string_s1 {
    method main (line 40) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_394_decode_string/lc_394_decode_string_s2.java
  class Solution (line 13) | class Solution {
    method decodeString (line 14) | public String decodeString(String s) {
    method dfs (line 17) | private String[] dfs(String s, int i) {
  class lc_394_decode_string_s2 (line 41) | public class lc_394_decode_string_s2 {
    method main (line 42) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_3_longest_substring_without_repeating_characters/lc_3_longest_substring_without_repeating_characters_s1.java
  class Solution (line 13) | class Solution {
    method lengthOfLongestSubstring (line 14) | public int lengthOfLongestSubstring(String s) {
  class lc_3_longest_substring_without_repeating_characters_s1 (line 27) | public class lc_3_longest_substring_without_repeating_characters_s1 {
    method main (line 28) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_3_longest_substring_without_repeating_characters/lc_3_longest_substring_without_repeating_characters_s2.java
  class Solution (line 13) | class Solution {
    method lengthOfLongestSubstring (line 14) | public int lengthOfLongestSubstring(String s) {
  class lc_3_longest_substring_without_repeating_characters_s2 (line 27) | public class lc_3_longest_substring_without_repeating_characters_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_400_nth_digit/lc_400_nth_digit_s1.java
  class lc_400_nth_digit_s1 (line 23) | public class lc_400_nth_digit_s1 {
    method main (line 24) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_400_nth_digit/lc_400_nth_digit_s2.java
  class lc_400_nth_digit_s2 (line 15) | public class lc_400_nth_digit_s2 {
    method main (line 16) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_400_nth_digit/lc_400_nth_digit_s3.java
  class lc_400_nth_digit_s3 (line 16) | public class lc_400_nth_digit_s3 {
    method main (line 17) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_400_nth_digit/lc_400_nth_digit_s4.java
  class Solution (line 13) | class Solution {
    method findNthDigit (line 14) | public int findNthDigit(int n) {
  class lc_400_nth_digit_s4 (line 29) | public class lc_400_nth_digit_s4 {
    method main (line 30) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_409_longest_palindrome/lc_409_longest_palindrome.java
  class Solution (line 13) | class Solution {
    method longestPalindrome (line 14) | public int longestPalindrome(String s) {
  class lc_409_longest_palindrome (line 33) | public class lc_409_longest_palindrome {
    method main (line 34) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_415_add_strings/lc_415_add_strings.java
  class Solution (line 13) | class Solution {
    method addStrings (line 14) | public String addStrings(String num1, String num2) {
  class lc_415_add_strings (line 30) | public class lc_415_add_strings {
    method main (line 31) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.java
  method dfs (line 14) | void dfs(Node root) {
  class lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1 (line 21) | public class lc_426_convert_binary_search_tree_to_sorted_doubly_linked_l...
    method main (line 22) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.java
  class Solution (line 13) | class Solution {
    method dfs (line 15) | void dfs(Node cur) {
    method treeToDoublyList (line 24) | public Node treeToDoublyList(Node root) {
  class lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2 (line 33) | public class lc_426_convert_binary_search_tree_to_sorted_doubly_linked_l...
    method main (line 34) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_46_permutations/lc_46_permutations.java
  class Solution (line 13) | class Solution {
    method swap (line 16) | void swap(int a, int b) {
    method dfs (line 21) | void dfs(int x) {
    method permute (line 32) | public List<List<Integer>> permute(int[] nums) {
  class lc_46_permutations (line 43) | public class lc_46_permutations {
    method main (line 44) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_47_permutations/lc_47_permutations.java
  class Solution (line 13) | class Solution {
    method swap (line 16) | void swap(int a, int b) {
    method dfs (line 21) | void dfs(int x) {
    method permuteUnique (line 36) | public List<List<Integer>> permuteUnique(int[] nums) {
  class lc_47_permutations (line 47) | public class lc_47_permutations {
    method main (line 48) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_48_rotate_image/lc_48_rotate_image_s1.java
  class Solution (line 13) | class Solution {
    method rotate (line 14) | public void rotate(int[][] matrix) {
  class lc_48_rotate_image_s1 (line 29) | public class lc_48_rotate_image_s1 {
    method main (line 30) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_48_rotate_image/lc_48_rotate_image_s2.java
  class Solution (line 13) | class Solution {
    method rotate (line 14) | public void rotate(int[][] matrix) {
  class lc_48_rotate_image_s2 (line 28) | public class lc_48_rotate_image_s2 {
    method main (line 29) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_48_rotate_image/lc_48_rotate_image_s3.java
  class Solution (line 13) | class Solution {
    method rotate (line 14) | public void rotate(int[][] matrix) {
  class lc_48_rotate_image_s3 (line 33) | public class lc_48_rotate_image_s3 {
    method main (line 34) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_509_fibonacci_number/lc_509_fibonacci_number.java
  class Solution (line 13) | class Solution {
    method fib (line 14) | public int fib(int n) {
  class lc_509_fibonacci_number (line 25) | public class lc_509_fibonacci_number {
    method main (line 26) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_50_powx_n/lc_50_powx_n.java
  class Solution (line 13) | class Solution {
    method myPow (line 14) | public double myPow(double x, int n) {
  class lc_50_powx_n (line 31) | public class lc_50_powx_n {
    method main (line 32) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_53_maximum_subarray/lc_53_maximum_subarray.java
  class Solution (line 13) | class Solution {
    method maxSubArray (line 14) | public int maxSubArray(int[] nums) {
  class lc_53_maximum_subarray (line 24) | public class lc_53_maximum_subarray {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_54_spiral_matrix/lc_54_spiral_matrix.java
  class Solution (line 13) | class Solution {
    method spiralOrder (line 14) | public List<Integer> spiralOrder(int[][] matrix) {
  class lc_54_spiral_matrix (line 33) | public class lc_54_spiral_matrix {
    method main (line 34) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_59_spiral_matrix/lc_59_spiral_matrix.java
  class Solution (line 13) | class Solution {
    method generateMatrix (line 14) | public int[][] generateMatrix(int n) {
  class lc_59_spiral_matrix (line 32) | public class lc_59_spiral_matrix {
    method main (line 33) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_64_minimum_path_sum/lc_64_minimum_path_sum.java
  class Solution (line 13) | class Solution {
    method minPathSum (line 14) | public int minPathSum(int[][] grid) {
  class lc_64_minimum_path_sum (line 27) | public class lc_64_minimum_path_sum {
    method main (line 28) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_65_valid_number/lc_65_valid_number.java
  class Solution (line 13) | class Solution {
    method isNumber (line 14) | public boolean isNumber(String s) {
  class lc_65_valid_number (line 41) | public class lc_65_valid_number {
    method main (line 42) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_6_zigzag_conversion/lc_6_zigzag_conversion.java
  class Solution (line 13) | class Solution {
    method convert (line 14) | public String convert(String s, int numRows) {
  class lc_6_zigzag_conversion (line 30) | public class lc_6_zigzag_conversion {
    method main (line 31) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_704_binary_search/lc_704_binary_search.java
  class Solution (line 13) | class Solution {
    method search (line 14) | public int search(int[] nums, int target) {
  class lc_704_binary_search (line 26) | public class lc_704_binary_search {
    method main (line 27) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_70_climbing_stairs/lc_70_climbing_stairs.java
  class Solution (line 13) | class Solution {
    method climbStairs (line 14) | public int climbStairs(int n) {
  class lc_70_climbing_stairs (line 25) | public class lc_70_climbing_stairs {
    method main (line 26) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_724_find_pivot_index/lc_724_find_pivot_index.java
  class Solution (line 13) | class Solution {
    method pivotIndex (line 14) | public int pivotIndex(int[] nums) {
  class lc_724_find_pivot_index (line 27) | public class lc_724_find_pivot_index {
    method main (line 28) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_796_rotate_string/lc_796_rotate_string.java
  class Solution (line 13) | class Solution {
    method rotateString (line 14) | public boolean rotateString(String s, String goal) {
  class lc_796_rotate_string (line 19) | public class lc_796_rotate_string {
    method main (line 20) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_79_word_search/lc_79_word_search.java
  class Solution (line 13) | class Solution {
    method exist (line 14) | public boolean exist(char[][] board, String word) {
    method dfs (line 23) | boolean dfs(char[][] board, char[] word, int i, int j, int k) {
  class lc_79_word_search (line 34) | public class lc_79_word_search {
    method main (line 35) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_86_partition_list/lc_86_partition_list_s1.java
  class Solution (line 13) | class Solution {
    method partition (line 14) | public ListNode partition(ListNode head, int x) {
  class lc_86_partition_list_s1 (line 33) | public class lc_86_partition_list_s1 {
    method main (line 34) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_86_partition_list/lc_86_partition_list_s2.java
  class Solution (line 13) | class Solution {
    method partition (line 14) | public ListNode partition(ListNode head, int x) {
  class lc_86_partition_list_s2 (line 38) | public class lc_86_partition_list_s2 {
    method main (line 39) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_876_middle_of_the_linked_list/lc_876_middle_of_the_linked_list.java
  class Solution (line 13) | class Solution {
    method middleNode (line 14) | public ListNode middleNode(ListNode head) {
  class lc_876_middle_of_the_linked_list (line 24) | public class lc_876_middle_of_the_linked_list {
    method main (line 25) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_89_gray_code/lc_89_gray_code.java
  class Solution (line 13) | class Solution {
    method grayCode (line 14) | public List<Integer> grayCode(int n) {
  class lc_89_gray_code (line 26) | public class lc_89_gray_code {
    method main (line 27) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_8_string_to_integer_atoi/lc_8_string_to_integer_atoi_s1.java
  class Solution (line 13) | class Solution {
    method myAtoi (line 14) | public int myAtoi(String s) {
  class lc_8_string_to_integer_atoi_s1 (line 30) | public class lc_8_string_to_integer_atoi_s1 {
    method main (line 31) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_8_string_to_integer_atoi/lc_8_string_to_integer_atoi_s2.java
  class Solution (line 13) | class Solution {
    method myAtoi (line 14) | public int myAtoi(String s) {
  class lc_8_string_to_integer_atoi_s2 (line 32) | public class lc_8_string_to_integer_atoi_s2 {
    method main (line 33) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/java/lc_946_validate_stack_sequences/lc_946_validate_stack_sequences.java
  class Solution (line 13) | class Solution {
    method validateStackSequences (line 14) | public boolean validateStackSequences(int[] pushed, int[] popped) {
  class lc_946_validate_stack_sequences (line 28) | public class lc_946_validate_stack_sequences {
    method main (line 29) | public static void main(String[] args) {

FILE: selected_coding_interview/codes/python/fix_tests.py
  function fix_missing_arguments (line 9) | def fix_missing_arguments():

FILE: selected_coding_interview/codes/python/include/binary_tree.py
  class TreeNode (line 10) | class TreeNode:
    method __init__ (line 13) | def __init__(self, val=0, left=None, right=None):
  function list_to_tree (line 19) | def list_to_tree(arr):
  function tree_to_list (line 47) | def tree_to_list(root):
  function get_tree_node (line 72) | def get_tree_node(root, val):

FILE: selected_coding_interview/codes/python/include/linked_list.py
  class ListNode (line 8) | class ListNode:
    method __init__ (line 11) | def __init__(self, val=0, next=None):
  function list_to_linked_list (line 16) | def list_to_linked_list(arr):
  function linked_list_to_list (line 33) | def linked_list_to_list(head):
  function get_list_node (line 49) | def get_list_node(head, val):

FILE: selected_coding_interview/codes/python/include/print_util.py
  function print_matrix (line 11) | def print_matrix(mat):
  function print_linked_list (line 24) | def print_linked_list(head):
  class Trunk (line 34) | class Trunk:
    method __init__ (line 35) | def __init__(self, prev=None, str=None):
  function showTrunks (line 40) | def showTrunks(p):
  function print_tree (line 47) | def print_tree(root, prev=None, isLeft=False):

FILE: selected_coding_interview/codes/python/lc_101_symmetric_tree.py
  class Solution (line 11) | class Solution:
    method isSymmetric (line 12) | def isSymmetric(self, root: Optional[TreeNode]) -> bool:

FILE: selected_coding_interview/codes/python/lc_102_binary_tree_level_order_traversal.py
  class Solution (line 11) | class Solution:
    method levelOrder (line 12) | def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:

FILE: selected_coding_interview/codes/python/lc_103_binary_tree_zigzag_level_order_traversal_s1.py
  class Solution (line 11) | class Solution:
    method zigzagLevelOrder (line 12) | def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:

FILE: selected_coding_interview/codes/python/lc_103_binary_tree_zigzag_level_order_traversal_s2.py
  class Solution (line 11) | class Solution:
    method zigzagLevelOrder (line 12) | def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:

FILE: selected_coding_interview/codes/python/lc_103_binary_tree_zigzag_level_order_traversal_s3.py
  class Solution (line 11) | class Solution:
    method zigzagLevelOrder (line 12) | def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:

FILE: selected_coding_interview/codes/python/lc_104_maximum_depth_of_binary_tree_s1.py
  class Solution (line 11) | class Solution:
    method maxDepth (line 12) | def maxDepth(self, root: Optional[TreeNode]) -> int:

FILE: selected_coding_interview/codes/python/lc_104_maximum_depth_of_binary_tree_s2.py
  class Solution (line 11) | class Solution:
    method maxDepth (line 12) | def maxDepth(self, root: TreeNode) -> int:

FILE: selected_coding_interview/codes/python/lc_105_construct_binary_tree_from_preorder_and_inorder_traversal.py
  class Solution (line 11) | class Solution:
    method buildTree (line 12) | def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode:

FILE: selected_coding_interview/codes/python/lc_10_regular_expression_matching_s1.py
  class Solution (line 11) | class Solution:
    method isMatch (line 12) | def isMatch(self, s: str, p: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_10_regular_expression_matching_s2.py
  class Solution (line 11) | class Solution:
    method isMatch (line 12) | def isMatch(self, s: str, p: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_110_balanced_binary_tree_s1.py
  class Solution (line 11) | class Solution:
    method isBalanced (line 12) | def isBalanced(self, root: Optional[TreeNode]) -> bool:

FILE: selected_coding_interview/codes/python/lc_110_balanced_binary_tree_s2.py
  class Solution (line 11) | class Solution:
    method isBalanced (line 12) | def isBalanced(self, root: Optional[TreeNode]) -> bool:
    method depth (line 16) | def depth(self, root):

FILE: selected_coding_interview/codes/python/lc_113_path_sum_ii.py
  class Solution (line 11) | class Solution:
    method pathSum (line 12) | def pathSum(self, root: Optional[TreeNode], targetSum: int) -> List[Li...

FILE: selected_coding_interview/codes/python/lc_11_container_with_most_water.py
  class Solution (line 11) | class Solution:
    method maxArea (line 12) | def maxArea(self, height: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_121_best_time_to_buy_and_sell_stock.py
  class Solution (line 11) | class Solution:
    method maxProfit (line 12) | def maxProfit(self, prices: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_122_best_time_to_buy_and_sell_stock_ii.py
  class Solution (line 11) | class Solution:
    method maxProfit (line 12) | def maxProfit(self, prices: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_135_candy.py
  class Solution (line 11) | class Solution:
    method candy (line 12) | def candy(self, ratings: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_136_single_number.py
  class Solution (line 11) | class Solution:
    method singleNumber (line 12) | def singleNumber(self, nums: List[int]) -> List[int]:

FILE: selected_coding_interview/codes/python/lc_137_single_number_ii_s1.py
  class Solution (line 11) | class Solution:
    method singleNumber (line 12) | def singleNumber(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_137_single_number_ii_s2.py
  class Solution (line 11) | class Solution:
    method singleNumber (line 12) | def singleNumber(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_138_copy_list_with_random_pointer_s1.py
  class Node (line 12) | class Node:
    method __init__ (line 13) | def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):
  class Solution (line 18) | class Solution:
    method copyRandomList (line 19) | def copyRandomList(self, head: 'Node') -> 'Node':

FILE: selected_coding_interview/codes/python/lc_138_copy_list_with_random_pointer_s2.py
  class Node (line 12) | class Node:
    method __init__ (line 13) | def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):
  class Solution (line 18) | class Solution:
    method copyRandomList (line 19) | def copyRandomList(self, head: 'Node') -> 'Node':

FILE: selected_coding_interview/codes/python/lc_138_copy_list_with_random_pointer_s3.py
  class Solution (line 11) | class Solution:
    method copyRandomList (line 12) | def copyRandomList(self, head: 'Node') -> 'Node':

FILE: selected_coding_interview/codes/python/lc_138_copy_list_with_random_pointer_s4.py
  class Solution (line 11) | class Solution:
    method copyRandomList (line 12) | def copyRandomList(self, head: 'Node') -> 'Node':

FILE: selected_coding_interview/codes/python/lc_138_copy_list_with_random_pointer_s5.py
  class Solution (line 11) | class Solution:
    method copyRandomList (line 12) | def copyRandomList(self, head: 'Node') -> 'Node':

FILE: selected_coding_interview/codes/python/lc_142_linked_list_cycle_ii.py
  class Solution (line 11) | class Solution(object):
    method detectCycle (line 12) | def detectCycle(self, head):

FILE: selected_coding_interview/codes/python/lc_1480_running_sum_of_1d_array.py
  class Solution (line 11) | class Solution:
    method runningSum (line 12) | def runningSum(self, nums: List[int]) -> List[int]:

FILE: selected_coding_interview/codes/python/lc_151_reverse_words_in_a_string_s1.py
  class Solution (line 11) | class Solution:
    method reverseWords (line 12) | def reverseWords(self, s: str) -> str:

FILE: selected_coding_interview/codes/python/lc_151_reverse_words_in_a_string_s2.py
  class Solution (line 11) | class Solution:
    method reverseWords (line 12) | def reverseWords(self, s: str) -> str:

FILE: selected_coding_interview/codes/python/lc_151_reverse_words_in_a_string_s3.py
  class Solution (line 11) | class Solution:
    method reverseWords (line 12) | def reverseWords(self, s: str) -> str:

FILE: selected_coding_interview/codes/python/lc_154_find_minimum_in_rotated_sorted_array_ii_s1.py
  class Solution (line 11) | class Solution:
    method findMin (line 12) | def findMin(self, nums: [int]) -> int:

FILE: selected_coding_interview/codes/python/lc_154_find_minimum_in_rotated_sorted_array_ii_s2.py
  class Solution (line 11) | class Solution:
    method findMin (line 12) | def findMin(self, nums: [int]) -> int:

FILE: selected_coding_interview/codes/python/lc_155_min_stack.py
  class MinStack (line 11) | class MinStack:
    method __init__ (line 12) | def __init__(self):
    method push (line 15) | def push(self, x: int) -> None:
    method pop (line 19) | def pop(self) -> None:
    method top (line 22) | def top(self) -> int:
    method getMin (line 24) | def getMin(self) -> int:

FILE: selected_coding_interview/codes/python/lc_15_three_sum.py
  class Solution (line 11) | class Solution:
    method threeSum (line 12) | def threeSum(self, nums: [int]) -> [[int]]:

FILE: selected_coding_interview/codes/python/lc_160_intersection_of_two_linked_lists.py
  class Solution (line 11) | class Solution:
    method getIntersectionNode (line 12) | def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Lis...

FILE: selected_coding_interview/codes/python/lc_167_two_sum_ii.py
  class Solution (line 11) | class Solution:
    method twoSum (line 12) | def twoSum(self, numbers: List[int], target: int) -> List[int]:

FILE: selected_coding_interview/codes/python/lc_169_majority_element_s1.py
  class Solution (line 11) | class Solution:
    method majorityElement (line 12) | def majorityElement(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_169_majority_element_s2.py
  class Solution (line 11) | class Solution:
    method majorityElement (line 12) | def majorityElement(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_179_largest_number_s1.py
  class Solution (line 11) | class Solution:
    method largestNumber (line 12) | def largestNumber(self, nums: List[int]) -> str:

FILE: selected_coding_interview/codes/python/lc_179_largest_number_s2.py
  class Solution (line 11) | class Solution:
    method largestNumber (line 12) | def largestNumber(self, nums: List[int]) -> str:

FILE: selected_coding_interview/codes/python/lc_1823_find_the_winner_of_the_circular_game.py
  class Solution (line 11) | class Solution:
    method findTheWinner (line 12) | def findTheWinner(self, n: int, k: int) -> int:

FILE: selected_coding_interview/codes/python/lc_191_number_of_1_bits_s1.py
  class Solution (line 11) | class Solution:
    method hammingWeight (line 12) | def hammingWeight(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_191_number_of_1_bits_s2.py
  class Solution (line 11) | class Solution:
    method hammingWeight (line 12) | def hammingWeight(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_198_house_robber.py
  class Solution (line 11) | class Solution:
    method rob (line 12) | def rob(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_205_isomorphic_strings.py
  class Solution (line 11) | class Solution:
    method isIsomorphic (line 12) | def isIsomorphic(self, s: str, t: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_206_reverse_linked_list_s1.py
  class Solution (line 11) | class Solution:
    method reverseList (line 12) | def reverseList(self, head: ListNode) -> ListNode:

FILE: selected_coding_interview/codes/python/lc_206_reverse_linked_list_s2.py
  class Solution (line 11) | class Solution:
    method reverseList (line 12) | def reverseList(self, head: ListNode) -> ListNode:

FILE: selected_coding_interview/codes/python/lc_206_reverse_linked_list_s3.py
  class Solution (line 11) | class Solution:
    method reverseList (line 12) | def reverseList(self, head: ListNode) -> ListNode:

FILE: selected_coding_interview/codes/python/lc_207_course_schedule_s1.py
  class Solution (line 12) | class Solution:
    method canFinish (line 13) | def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -...

FILE: selected_coding_interview/codes/python/lc_207_course_schedule_s2.py
  class Solution (line 11) | class Solution:
    method canFinish (line 12) | def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -...

FILE: selected_coding_interview/codes/python/lc_20_valid_parentheses.py
  class Solution (line 11) | class Solution:
    method isValid (line 12) | def isValid(self, s: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_213_house_robber_ii.py
  class Solution (line 11) | class Solution:
    method rob (line 12) | def rob(self, nums: [int]) -> int:

FILE: selected_coding_interview/codes/python/lc_215_kth_largest_element_in_an_array_s1.py
  class Solution (line 11) | class Solution:
    method findKthLargest (line 12) | def findKthLargest(self, nums: List[int], k: int) -> int:

FILE: selected_coding_interview/codes/python/lc_215_kth_largest_element_in_an_array_s2.py
  class Solution (line 11) | class Solution:
    method findKthLargest (line 12) | def findKthLargest(self, nums: List[int], k: int) -> int:

FILE: selected_coding_interview/codes/python/lc_21_merge_two_sorted_lists.py
  class Solution (line 11) | class Solution:
    method mergeTwoLists (line 12) | def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[Lis...

FILE: selected_coding_interview/codes/python/lc_226_invert_binary_tree_s1.py
  class Solution (line 11) | class Solution:
    method invertTree (line 12) | def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:

FILE: selected_coding_interview/codes/python/lc_226_invert_binary_tree_s2.py
  class Solution (line 11) | class Solution:
    method invertTree (line 12) | def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:

FILE: selected_coding_interview/codes/python/lc_226_invert_binary_tree_s3.py
  class Solution (line 11) | class Solution:
    method invertTree (line 12) | def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:

FILE: selected_coding_interview/codes/python/lc_230_kth_smallest_element_in_a_bst.py
  class Solution (line 11) | class Solution:
    method kthSmallest (line 12) | def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:

FILE: selected_coding_interview/codes/python/lc_231_power_of_two.py
  class Solution (line 11) | class Solution:
    method isPowerOfTwo (line 12) | def isPowerOfTwo(self, n: int) -> bool:

FILE: selected_coding_interview/codes/python/lc_232_implement_queue_using_stacks.py
  class MyQueue (line 11) | class MyQueue:
    method __init__ (line 12) | def __init__(self):
    method push (line 14) | def push(self, x: int) -> None:
    method pop (line 16) | def pop(self) -> int:
    method peek (line 20) | def peek(self) -> int:
    method empty (line 27) | def empty(self) -> bool:

FILE: selected_coding_interview/codes/python/lc_233_number_of_digit_one_s1.py
  class Solution (line 11) | class Solution:
    method countDigitOne (line 12) | def countDigitOne(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_233_number_of_digit_one_s2.py
  class Solution (line 11) | class Solution:
    method countDigitOne (line 12) | def countDigitOne(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_233_number_of_digit_one_s3.py
  class Solution (line 11) | class Solution:
    method countDigitOne (line 12) | def countDigitOne(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_235_lowest_common_ancestor_of_a_binary_search_tree_s1.py
  class Solution (line 11) | class Solution:
    method lowestCommonAncestor (line 12) | def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'Tr...

FILE: selected_coding_interview/codes/python/lc_235_lowest_common_ancestor_of_a_binary_search_tree_s2.py
  class Solution (line 11) | class Solution:
    method lowestCommonAncestor (line 12) | def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'Tr...

FILE: selected_coding_interview/codes/python/lc_235_lowest_common_ancestor_of_a_binary_search_tree_s3.py
  class Solution (line 11) | class Solution:
    method lowestCommonAncestor (line 12) | def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'Tr...

FILE: selected_coding_interview/codes/python/lc_236_lowest_common_ancestor_of_a_binary_tree_s1.py
  class Solution (line 11) | class Solution:
    method lowestCommonAncestor (line 12) | def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNod...

FILE: selected_coding_interview/codes/python/lc_236_lowest_common_ancestor_of_a_binary_tree_s2.py
  class Solution (line 11) | class Solution:
    method lowestCommonAncestor (line 12) | def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNod...

FILE: selected_coding_interview/codes/python/lc_237_delete_node_in_a_linked_list_s1.py
  class Solution (line 11) | class Solution:
    method deleteNode (line 12) | def deleteNode(self, node):

FILE: selected_coding_interview/codes/python/lc_237_delete_node_in_a_linked_list_s2.py
  class Solution (line 11) | class Solution:
    method deleteNode (line 12) | def deleteNode(self, node):

FILE: selected_coding_interview/codes/python/lc_238_product_of_array_except_self.py
  class Solution (line 11) | class Solution:
    method productExceptSelf (line 12) | def productExceptSelf(self, nums: List[int]) -> List[int]:

FILE: selected_coding_interview/codes/python/lc_239_sliding_window_maximum_s1.py
  class Solution (line 11) | class Solution:
    method maxSlidingWindow (line 12) | def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:

FILE: selected_coding_interview/codes/python/lc_239_sliding_window_maximum_s2.py
  class Solution (line 11) | class Solution:
    method maxSlidingWindow (line 12) | def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:

FILE: selected_coding_interview/codes/python/lc_240_search_a_2d_matrix_ii.py
  class Solution (line 11) | class Solution:
    method searchMatrix (line 12) | def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:

FILE: selected_coding_interview/codes/python/lc_242_valid_anagram_s1.py
  class Solution (line 11) | class Solution:
    method isAnagram (line 12) | def isAnagram(self, s: str, t: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_242_valid_anagram_s2.py
  class Solution (line 11) | class Solution:
    method isAnagram (line 12) | def isAnagram(self, s: str, t: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_264_ugly_number_ii.py
  class Solution (line 11) | class Solution:
    method nthUglyNumber (line 12) | def nthUglyNumber(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_266_palindrome_permutation_s1.py
  class Solution (line 11) | class Solution:
    method canPermutePalindrome (line 12) | def canPermutePalindrome(self, s: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_266_palindrome_permutation_s2.py
  class Solution (line 11) | class Solution:
    method canPermutePalindrome (line 12) | def canPermutePalindrome(self, s: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_278_first_bad_version.py
  class Solution (line 11) | class Solution:
    method firstBadVersion (line 12) | def firstBadVersion(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_287_find_the_duplicate_number_s1.py
  class Solution (line 11) | class Solution:
    method findDuplicate (line 12) | def findDuplicate(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_287_find_the_duplicate_number_s2.py
  class Solution (line 11) | class Solution:
    method findDuplicate (line 12) | def findDuplicate(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_287_find_the_duplicate_number_s3.py
  class Solution (line 11) | class Solution:
    method findDuplicate (line 12) | def findDuplicate(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_295_find_median_from_data_stream_s1.py
  class MedianFinder (line 12) | class MedianFinder:
    method __init__ (line 13) | def __init__(self):
    method addNum (line 16) | def addNum(self, num: int) -> None:
    method findMedian (line 23) | def findMedian(self) -> float:

FILE: selected_coding_interview/codes/python/lc_295_find_median_from_data_stream_s2.py
  class MedianFinder (line 12) | class MedianFinder:
    method __init__ (line 13) | def __init__(self):
    method addNum (line 16) | def addNum(self, num: int) -> None:
    method findMedian (line 21) | def findMedian(self) -> float:

FILE: selected_coding_interview/codes/python/lc_297_serialize_and_deserialize_binary_tree.py
  class Codec (line 11) | class Codec:
    method serialize (line 12) | def serialize(self, root):
    method deserialize (line 25) | def deserialize(self, data):

FILE: selected_coding_interview/codes/python/lc_300_longest_increasing_subsequence_s1.py
  class Solution (line 12) | class Solution:
    method lengthOfLIS (line 13) | def lengthOfLIS(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_300_longest_increasing_subsequence_s2.py
  class Solution (line 12) | class Solution:
    method lengthOfLIS (line 13) | def lengthOfLIS(self, nums: [int]) -> int:

FILE: selected_coding_interview/codes/python/lc_343_integer_break.py
  class Solution (line 11) | class Solution:
    method integerBreak (line 12) | def integerBreak(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_371_sum_of_two_integers.py
  class Solution (line 11) | class Solution:
    method getSum (line 12) | def getSum(self, a: int, b: int) -> int:

FILE: selected_coding_interview/codes/python/lc_387_first_unique_character_in_a_string.py
  class Solution (line 11) | class Solution:
    method firstUniqChar (line 12) | def firstUniqChar(self, s: str) -> int:

FILE: selected_coding_interview/codes/python/lc_392_is_subsequence.py
  class Solution (line 11) | class Solution:
    method isSubsequence (line 12) | def isSubsequence(self, s: str, t: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_394_decode_string_s1.py
  class Solution (line 11) | class Solution:
    method decodeString (line 12) | def decodeString(self, s: str) -> str:

FILE: selected_coding_interview/codes/python/lc_394_decode_string_s2.py
  class Solution (line 11) | class Solution:
    method decodeString (line 12) | def decodeString(self, s: str) -> str:

FILE: selected_coding_interview/codes/python/lc_39_combination_sum_s1.py
  class Solution (line 11) | class Solution:
    method combinationSum (line 12) | def combinationSum(self, candidates: List[int], target: int) -> List[L...

FILE: selected_coding_interview/codes/python/lc_39_combination_sum_s2.py
  class Solution (line 11) | class Solution:
    method combinationSum (line 12) | def combinationSum(self, candidates: List[int], target: int) -> List[L...

FILE: selected_coding_interview/codes/python/lc_3_longest_substring_without_repeating_characters_s1.py
  class Solution (line 11) | class Solution:
    method lengthOfLongestSubstring (line 12) | def lengthOfLongestSubstring(self, s: str) -> int:

FILE: selected_coding_interview/codes/python/lc_3_longest_substring_without_repeating_characters_s2.py
  class Solution (line 11) | class Solution:
    method lengthOfLongestSubstring (line 12) | def lengthOfLongestSubstring(self, s: str) -> int:

FILE: selected_coding_interview/codes/python/lc_400_nth_digit_s1.py
  class Solution (line 11) | class Solution:
    method findNthDigit (line 12) | def findNthDigit(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_400_nth_digit_s2.py
  class Solution (line 11) | class Solution:
    method findNthDigit (line 12) | def findNthDigit(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_400_nth_digit_s3.py
  class Solution (line 11) | class Solution:
    method findNthDigit (line 12) | def findNthDigit(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_400_nth_digit_s4.py
  class Solution (line 11) | class Solution:
    method findNthDigit (line 12) | def findNthDigit(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_409_longest_palindrome.py
  class Solution (line 11) | class Solution:
    method longestPalindrome (line 12) | def longestPalindrome(self, s: str) -> int:

FILE: selected_coding_interview/codes/python/lc_40_combination_sum_ii_s1.py
  class Solution (line 11) | class Solution:
    method combinationSum2 (line 12) | def combinationSum2(self, candidates: List[int], target: int) -> List[...

FILE: selected_coding_interview/codes/python/lc_40_combination_sum_ii_s2.py
  class Solution (line 11) | class Solution:
    method combinationSum2 (line 12) | def combinationSum2(self, candidates: List[int], target: int) -> List[...

FILE: selected_coding_interview/codes/python/lc_415_add_strings.py
  class Solution (line 11) | class Solution:
    method addStrings (line 12) | def addStrings(self, num1: str, num2: str) -> str:

FILE: selected_coding_interview/codes/python/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.py
  class Solution (line 11) | class Solution:
    method treeToDoublyList (line 12) | def treeToDoublyList(self, root: 'TreeNode') -> 'TreeNode':

FILE: selected_coding_interview/codes/python/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.py
  class Solution (line 11) | class Solution:
    method treeToDoublyList (line 12) | def treeToDoublyList(self, root: 'Optional[Node]') -> 'Optional[Node]':

FILE: selected_coding_interview/codes/python/lc_46_permutations.py
  class Solution (line 11) | class Solution:
    method permute (line 12) | def permute(self, nums: List[int]) -> List[List[int]]:

FILE: selected_coding_interview/codes/python/lc_47_permutations_ii.py
  class Solution (line 11) | class Solution:
    method permuteUnique (line 12) | def permuteUnique(self, nums: List[int]) -> List[List[int]]:

FILE: selected_coding_interview/codes/python/lc_48_rotate_image_s1.py
  class Solution (line 11) | class Solution:
    method rotate (line 12) | def rotate(self, matrix: List[List[int]]) -> None:

FILE: selected_coding_interview/codes/python/lc_48_rotate_image_s2.py
  class Solution (line 11) | class Solution:
    method rotate (line 12) | def rotate(self, matrix: List[List[int]]) -> None:

FILE: selected_coding_interview/codes/python/lc_48_rotate_image_s3.py
  class Solution (line 11) | class Solution:
    method rotate (line 12) | def rotate(self, matrix: List[List[int]]) -> None:

FILE: selected_coding_interview/codes/python/lc_509_fibonacci_number.py
  class Solution (line 11) | class Solution:
    method fib (line 12) | def fib(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_50_powx_n.py
  class Solution (line 11) | class Solution:
    method myPow (line 12) | def myPow(self, x: float, n: int) -> float:

FILE: selected_coding_interview/codes/python/lc_53_maximum_subarray.py
  class Solution (line 11) | class Solution:
    method maxSubArray (line 12) | def maxSubArray(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_54_spiral_matrix.py
  class Solution (line 11) | class Solution:
    method spiralOrder (line 12) | def spiralOrder(self, matrix: List[List[int]]) -> List[int]:

FILE: selected_coding_interview/codes/python/lc_59_spiral_matrix_ii.py
  class Solution (line 11) | class Solution:
    method generateMatrix (line 12) | def generateMatrix(self, n: int) -> [[int]]:

FILE: selected_coding_interview/codes/python/lc_64_minimum_path_sum.py
  class Solution (line 11) | class Solution:
    method minPathSum (line 12) | def minPathSum(self, grid: [[int]]) -> int:

FILE: selected_coding_interview/codes/python/lc_65_valid_number.py
  class Solution (line 11) | class Solution:
    method isNumber (line 12) | def isNumber(self, s: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_6_zigzag_conversion.py
  class Solution (line 11) | class Solution:
    method convert (line 12) | def convert(self, s: str, numRows: int) -> str:

FILE: selected_coding_interview/codes/python/lc_704_binary_search.py
  class Solution (line 11) | class Solution:
    method search (line 12) | def search(self, nums: List[int], target: int) -> int:

FILE: selected_coding_interview/codes/python/lc_70_climbing_stairs.py
  class Solution (line 11) | class Solution:
    method climbStairs (line 12) | def climbStairs(self, n: int) -> int:

FILE: selected_coding_interview/codes/python/lc_724_find_pivot_index.py
  class Solution (line 11) | class Solution:
    method pivotIndex (line 12) | def pivotIndex(self, nums: List[int]) -> int:

FILE: selected_coding_interview/codes/python/lc_768_max_chunks_to_make_sorted_ii.py
  class Solution (line 11) | class Solution:
    method maxChunksToSorted (line 12) | def maxChunksToSorted(self, arr: [int]) -> int:

FILE: selected_coding_interview/codes/python/lc_796_rotate_string.py
  class Solution (line 11) | class Solution:
    method rotateString (line 12) | def rotateString(self, s: str, goal: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_79_word_search.py
  class Solution (line 11) | class Solution:
    method exist (line 12) | def exist(self, board: List[List[str]], word: str) -> bool:

FILE: selected_coding_interview/codes/python/lc_86_partition_list_s1.py
  class Solution (line 11) | class Solution:
    method partition (line 12) | def partition(self, head: Optional[ListNode], x: int) -> Optional[List...

FILE: selected_coding_interview/codes/python/lc_86_partition_list_s2.py
  class Solution (line 11) | class Solution:
    method partition (line 12) | def partition(self, head: Optional[ListNode], x: int) -> Optional[List...

FILE: selected_coding_interview/codes/python/lc_876_middle_of_the_linked_list.py
  class Solution (line 11) | class Solution:
    method middleNode (line 12) | def middleNode(self, head: ListNode) -> ListNode:

FILE: selected_coding_interview/codes/python/lc_89_gray_code.py
  class Solution (line 11) | class Solution:
    method grayCode (line 12) | def grayCode(self, n: int) -> List[int]:

FILE: selected_coding_interview/codes/python/lc_8_string_to_integer_atoi_s1.py
  class Solution (line 11) | class Solution:
    method myAtoi (line 12) | def myAtoi(self, s: str) -> int:

FILE: selected_coding_interview/codes/python/lc_8_string_to_integer_atoi_s2.py
  class Solution (line 11) | class Solution:
    method myAtoi (line 12) | def myAtoi(self, s: str) -> int:

FILE: selected_coding_interview/codes/python/lc_946_validate_stack_sequences.py
  class Solution (line 11) | class Solution:
    method validateStackSequences (line 12) | def validateStackSequences(self, pushed: List[int], popped: List[int])...

FILE: sword_for_offer/codes/cpp/include/ListNode.hpp
  type ListNode (line 16) | struct ListNode {
    method ListNode (line 19) | ListNode(int x) : val(x), next(nullptr) {
  function ListNode (line 29) | ListNode *vectorToLinkedList(vector<int> list) {
    method ListNode (line 19) | ListNode(int x) : val(x), next(nullptr) {
  function ListNode (line 46) | ListNode *getListNode(ListNode *head, int val) {
    method ListNode (line 19) | ListNode(int x) : val(x), next(nullptr) {

FILE: sword_for_offer/codes/cpp/include/PrintUtil.hpp
  class PrintUtil (line 15) | class PrintUtil {
    method vecFind (line 25) | static int vecFind(const vector<T> &vec, T ele) {
    method string (line 43) | static string strJoin(const string &delim, const T &vec) {
    method string (line 61) | static string strRepeat(string str, int n) {
    method string (line 75) | static string getVectorString(vector<T> &list) {
    method printVector (line 85) | static void printVector(vector<T> &list) {
    method printVectorMatrix (line 95) | static void printVectorMatrix(vector<vector<T>> &matrix) {
    method printLinkedList (line 107) | static void printLinkedList(ListNode *head) {
    type Trunk (line 121) | struct Trunk {
      method Trunk (line 124) | Trunk(Trunk *prev, string str) {
    method showTrunks (line 135) | static void showTrunks(Trunk *p) {
    method printTree (line 149) | static void printTree(TreeNode *root) {
    method printTree (line 160) | static void printTree(TreeNode *root, Trunk *prev, bool isLeft) {

FILE: sword_for_offer/codes/cpp/include/TreeNode.hpp
  type TreeNode (line 13) | struct TreeNode {
    method TreeNode (line 17) | TreeNode(int x) : val(x), left(nullptr), right(nullptr) {
  function TreeNode (line 27) | TreeNode *vectorToTree(vector<int> list) {
    method TreeNode (line 17) | TreeNode(int x) : val(x), left(nullptr), right(nullptr) {
  function TreeNode (line 56) | TreeNode *getTreeNode(TreeNode *root, int val) {
    method TreeNode (line 17) | TreeNode(int x) : val(x), left(nullptr), right(nullptr) {

FILE: sword_for_offer/codes/cpp/sfo_03_find_duplicate_numbers_in_an_array_s1/sfo_03_find_duplicate_numbers_in_an_array_s1.cpp
  class Solution (line 10) | class Solution {
    method findRepeatNumber (line 12) | int findRepeatNumber(vector<int>& nums) {
  function main (line 22) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_03_find_duplicate_numbers_in_an_array_s2/sfo_03_find_duplicate_numbers_in_an_array_s2.cpp
  class Solution (line 10) | class Solution {
    method findRepeatNumber (line 12) | int findRepeatNumber(vector<int> &nums) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_04_find_a_number_in_2d_matrix_s1/sfo_04_find_a_number_in_2d_matrix_s1.cpp
  class Solution (line 10) | class Solution {
    method findNumberIn2DArray (line 12) | bool findNumberIn2DArray(vector<vector<int>> &matrix, int target) {
  function main (line 26) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_05_replace_spaces_s1/sfo_05_replace_spaces_s1.cpp
  class Solution (line 10) | class Solution {
    method string (line 12) | string replaceSpace(string s) {
  function main (line 36) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_06_print_a_linked_list_in_reverse_order_s1/sfo_06_print_a_linked_list_in_reverse_order_s1.cpp
  class Solution (line 10) | class Solution {
    method reversePrint (line 12) | vector<int> reversePrint(ListNode *head) {
    method recur (line 19) | void recur(ListNode *head) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_06_print_a_linked_list_in_reverse_order_s2/sfo_06_print_a_linked_list_in_reverse_order_s2.cpp
  class Solution (line 10) | class Solution {
    method reversePrint (line 12) | vector<int> reversePrint(ListNode *head) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_07_reconstruct_binary_tree_s1/sfo_07_reconstruct_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode *buildTree(vector<int> &preorder, vector<int> &inorder) {
    method TreeNode (line 22) | TreeNode *recur(int root, int left, int right) {
  function main (line 33) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_09_implement_a_queue_using_two_stacks_s1/sfo_09_implement_a_queue_using_two_stacks_s1.cpp
  class CQueue (line 10) | class CQueue {
    method CQueue (line 13) | CQueue() {
    method appendTail (line 15) | void appendTail(int value) {
    method deleteHead (line 18) | int deleteHead() {
  function main (line 37) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_10i_fibonacci_numbers_s1/sfo_10i_fibonacci_numbers_s1.cpp
  class Solution (line 10) | class Solution {
    method fib (line 12) | int fib(int n) {
  function main (line 23) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_10ii_frog_jump_s1/sfo_10ii_frog_jump_s1.cpp
  class Solution (line 10) | class Solution {
    method numWays (line 12) | int numWays(int n) {
  function main (line 23) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_11_find_minimum_in_rotated_sorted_array_s1/sfo_11_find_minimum_in_rotated_sorted_array_s1.cpp
  class Solution (line 10) | class Solution {
    method minArray (line 12) | int minArray(vector<int> &numbers) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_11_find_minimum_in_rotated_sorted_array_s2/sfo_11_find_minimum_in_rotated_sorted_array_s2.cpp
  class Solution (line 10) | class Solution {
    method minArray (line 12) | int minArray(vector<int> &numbers) {
  function main (line 33) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_12_word_search_s1/sfo_12_word_search_s1.cpp
  class Solution (line 10) | class Solution {
    method exist (line 12) | bool exist(vector<vector<char>> &board, string word) {
    method dfs (line 26) | bool dfs(vector<vector<char>> &board, string word, int i, int j, int k) {
  function main (line 39) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_13_range_of_motion_of_a_robot_s1/sfo_13_range_of_motion_of_a_robot_s1.cpp
  class Solution (line 10) | class Solution {
    method movingCount (line 12) | int movingCount(int m, int n, int k) {
    method dfs (line 18) | int dfs(int i, int j, int si, int sj, vector<vector<bool>> &visited, i...
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_13_range_of_motion_of_a_robot_s2/sfo_13_range_of_motion_of_a_robot_s2.cpp
  class Solution (line 10) | class Solution {
    method movingCount (line 12) | int movingCount(int m, int n, int k) {
  function main (line 32) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_14i_cut_the_rope_i_s1/sfo_14i_cut_the_rope_i_s1.cpp
  class Solution (line 10) | class Solution {
    method cuttingRope (line 12) | int cuttingRope(int n) {
  function main (line 24) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_14ii_cut_the_rope_ii_s1/sfo_14ii_cut_the_rope_ii_s1.cpp
  class Solution (line 10) | class Solution {
    method cuttingRope (line 12) | int cuttingRope(int n) {
  function main (line 30) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_15_number_of_1_bits_s1/sfo_15_number_of_1_bits_s1.cpp
  class Solution (line 10) | class Solution {
    method hammingWeight (line 12) | int hammingWeight(uint32_t n) {
  function main (line 22) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_15_number_of_1_bits_s2/sfo_15_number_of_1_bits_s2.cpp
  class Solution (line 10) | class Solution {
    method hammingWeight (line 12) | int hammingWeight(uint32_t n) {
  function main (line 22) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_16_powers_of_integers_s1/sfo_16_powers_of_integers_s1.cpp
  class Solution (line 10) | class Solution {
    method myPow (line 12) | double myPow(double x, int n) {
  function main (line 31) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_18_delete_a_node_from_a_linked_list_s1/sfo_18_delete_a_node_from_a_linked_list_s1.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode *deleteNode(ListNode *head, int val) {
  function main (line 26) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_19_regular_expression_matching_s1/sfo_19_regular_expression_matching_s1.cpp
  class Solution (line 10) | class Solution {
    method isMatch (line 12) | bool isMatch(string s, string p) {
  function main (line 28) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_19_regular_expression_matching_s2/sfo_19_regular_expression_matching_s2.cpp
  class Solution (line 10) | class Solution {
    method isMatch (line 12) | bool isMatch(string s, string p) {
  function main (line 41) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_21_adjust_the_order_of_numbers_in_an_array_s1/sfo_21_adjust_the_order_of_numbers_in_an_array_s1.cpp
  class Solution (line 10) | class Solution {
    method exchange (line 12) | vector<int> exchange(vector<int> &nums) {
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/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
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode *getKthFromEnd(ListNode *head, int k) {
  function main (line 24) | int main() {

FILE: sword_for_offer/codes/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
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode *getKthFromEnd(ListNode *head, int k) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_24_reverse_a_linked_list_s1/sfo_24_reverse_a_linked_list_s1.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode *reverseList(ListNode *head) {
  function main (line 24) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_24_reverse_a_linked_list_s2/sfo_24_reverse_a_linked_list_s2.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode *reverseList(ListNode *head) {
    method ListNode (line 17) | ListNode *recur(ListNode *cur, ListNode *pre) {
  function main (line 26) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_25_combine_two_sorted_linked_lists_s1/sfo_25_combine_two_sorted_linked_lists_s1.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
  function main (line 30) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_26_substructure_of_a_binary_tree_s1/sfo_26_substructure_of_a_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method isSubStructure (line 12) | bool isSubStructure(TreeNode *A, TreeNode *B) {
    method recur (line 18) | bool recur(TreeNode *A, TreeNode *B) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_27_mirror_of_a_binary_tree_s1/sfo_27_mirror_of_a_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode *mirrorTree(TreeNode *root) {
  function main (line 22) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_27_mirror_of_a_binary_tree_s2/sfo_27_mirror_of_a_binary_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode *mirrorTree(TreeNode *root) {
  function main (line 32) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_28_symmetric_binary_tree_s1/sfo_28_symmetric_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method isSymmetric (line 12) | bool isSymmetric(TreeNode *root) {
    method recur (line 17) | bool recur(TreeNode *L, TreeNode *R) {
  function main (line 26) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_29_print_a_given_matrix_in_spiral_form_s1/sfo_29_print_a_given_matrix_in_spiral_form_s1.cpp
  class Solution (line 10) | class Solution {
    method spiralOrder (line 12) | vector<int> spiralOrder(vector<vector<int>> &matrix) {
  function main (line 39) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_30_min_stack_s1/sfo_30_min_stack_s1.cpp
  class MinStack (line 10) | class MinStack {
    method MinStack (line 13) | MinStack() {
    method push (line 15) | void push(int x) {
    method pop (line 20) | void pop() {
    method top (line 25) | int top() {
    method min (line 28) | int min() {
  function main (line 33) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_31_validate_stack_sequences_s1/sfo_31_validate_stack_sequences_s1.cpp
  class Solution (line 10) | class Solution {
    method validateStackSequences (line 12) | bool validateStackSequences(vector<int> &pushed, vector<int> &popped) {
  function main (line 26) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_32i_print_a_binary_tree_topbottom_i_s1/sfo_32i_print_a_binary_tree_topbottom_i_s1.cpp
  class Solution (line 10) | class Solution {
    method levelOrder (line 12) | vector<int> levelOrder(TreeNode *root) {
  function main (line 31) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_32ii_print_a_binary_tree_topbottom_ii_s1/sfo_32ii_print_a_binary_tree_topbottom_ii_s1.cpp
  class Solution (line 10) | class Solution {
    method levelOrder (line 12) | vector<vector<int>> levelOrder(TreeNode *root) {
  function main (line 35) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s1/sfo_32iii_print_a_binary_tree_topbottom_iii_s1.cpp
  class Solution (line 10) | class Solution {
    method levelOrder (line 12) | vector<vector<int>> levelOrder(TreeNode *root) {
  function main (line 53) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_32iii_print_a_binary_tree_topbottom_iii_s2/sfo_32iii_print_a_binary_tree_topbottom_iii_s2.cpp
  class Solution (line 10) | class Solution {
    method levelOrder (line 12) | vector<vector<int>> levelOrder(TreeNode *root) {
  function main (line 36) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_33_postorder_traversal_of_a_binary_search_tree_s1/sfo_33_postorder_traversal_of_a_binary_search_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method verifyPostorder (line 12) | bool verifyPostorder(vector<int> &postorder) {
    method recur (line 17) | bool recur(vector<int> &postorder, int i, int j) {
  function main (line 30) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_33_postorder_traversal_of_a_binary_search_tree_s2/sfo_33_postorder_traversal_of_a_binary_search_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method verifyPostorder (line 12) | bool verifyPostorder(vector<int> &postorder) {
  function main (line 28) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_34_all_xsum_paths_in_a_binary_tree_s1/sfo_34_all_xsum_paths_in_a_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method pathSum (line 12) | vector<vector<int>> pathSum(TreeNode *root, int sum) {
    method recur (line 20) | void recur(TreeNode *root, int tar) {
  function main (line 33) | int main() {

FILE: sword_for_offer/codes/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
  type Node (line 12) | struct Node {
    method Node (line 16) | Node(int x) : val(x), next(nullptr), random(nullptr) {
  class Solution (line 21) | class Solution {
    method Node (line 23) | Node *copyRandomList(Node *head) {
  function main (line 45) | int main() {

FILE: sword_for_offer/codes/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
  type Node (line 12) | struct Node {
    method Node (line 16) | Node(int x) : val(x), next(nullptr), random(nullptr) {
  class Solution (line 21) | class Solution {
    method Node (line 23) | Node *copyRandomList(Node *head) {
  function main (line 55) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_36_binary_search_tree_and_doubly_linked_list_s1/sfo_36_binary_search_tree_and_doubly_linked_list_s1.cpp
  type Node (line 12) | struct Node {
    method Node (line 16) | Node(int x) : val(x), left(nullptr), right(nullptr) {
  class Solution (line 21) | class Solution {
    method Node (line 23) | Node *treeToDoublyList(Node *root) {
    method dfs (line 34) | void dfs(Node *cur) {
  function main (line 48) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_37_serialize_and_deserialize_a_binary_tree_s1/sfo_37_serialize_and_deserialize_a_binary_tree_s1.cpp
  class Codec (line 9) | class Codec {
    method string (line 12) | string serialize(TreeNode *root) {
    method TreeNode (line 34) | TreeNode *deserialize(string data) {
    method split (line 59) | vector<string> split(string str, string delim) {
  function main (line 72) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_38_all_permutations_of_a_string_s1/sfo_38_all_permutations_of_a_string_s1.cpp
  class Solution (line 10) | class Solution {
    method permutation (line 12) | vector<string> permutation(string s) {
    method dfs (line 19) | void dfs(string s, int x) {
  function main (line 36) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_39_the_majority_element_in_an_array_s1/sfo_39_the_majority_element_in_an_array_s1.cpp
  class Solution (line 10) | class Solution {
    method majorityElement (line 12) | int majorityElement(vector<int> &nums) {
  function main (line 23) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_39_the_majority_element_in_an_array_s2/sfo_39_the_majority_element_in_an_array_s2.cpp
  class Solution (line 10) | class Solution {
    method majorityElement (line 12) | int majorityElement(vector<int> &nums) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_40_the_smallest_k_numbers_s1/sfo_40_the_smallest_k_numbers_s1.cpp
  class Solution (line 10) | class Solution {
    method getLeastNumbers (line 12) | vector<int> getLeastNumbers(vector<int> &arr, int k) {
    method quickSort (line 20) | void quickSort(vector<int> &arr, int l, int r) {
  function main (line 40) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_40_the_smallest_k_numbers_s2/sfo_40_the_smallest_k_numbers_s2.cpp
  class Solution (line 10) | class Solution {
    method getLeastNumbers (line 12) | vector<int> getLeastNumbers(vector<int> &arr, int k) {
    method quickSort (line 19) | vector<int> quickSort(vector<int> &arr, int k, int l, int r) {
  function main (line 39) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_41_find_median_from_data_stream_s1/sfo_41_find_median_from_data_stream_s1.cpp
  class MedianFinder (line 10) | class MedianFinder {
    method MedianFinder (line 14) | MedianFinder() {
    method addNum (line 16) | void addNum(int num) {
    method findMedian (line 27) | double findMedian() {
  function main (line 32) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_42_largest_sum_contiguous_subarray_s1/sfo_42_largest_sum_contiguous_subarray_s1.cpp
  class Solution (line 10) | class Solution {
    method maxSubArray (line 12) | int maxSubArray(vector<int> &nums) {
  function main (line 24) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_43_total_number_of_1_in_integers_from_1_to_n_s1/sfo_43_total_number_of_1_in_integers_from_1_to_n_s1.cpp
  class Solution (line 10) | class Solution {
    method countDigitOne (line 12) | int countDigitOne(int n) {
  function main (line 31) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_44_nth_digit_s1/sfo_44_nth_digit_s1.cpp
  class Solution (line 10) | class Solution {
    method findNthDigit (line 12) | int findNthDigit(int n) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_45_arrange_an_array_into_the_smallest_number_s1/sfo_45_arrange_an_array_into_the_smallest_number_s1.cpp
  class Solution (line 10) | class Solution {
    method string (line 12) | string minNumber(vector<int> &nums) {
    method quickSort (line 24) | void quickSort(vector<string> &strs, int l, int r) {
  function main (line 41) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_45_arrange_an_array_into_the_smallest_number_s2/sfo_45_arrange_an_array_into_the_smallest_number_s2.cpp
  class Solution (line 10) | class Solution {
    method string (line 12) | string minNumber(vector<int> &nums) {
  function main (line 24) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_46_translate_numbers_into_strings_s1/sfo_46_translate_numbers_into_strings_s1.cpp
  class Solution (line 10) | class Solution {
    method translateNum (line 12) | int translateNum(int num) {
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_46_translate_numbers_into_strings_s2/sfo_46_translate_numbers_into_strings_s2.cpp
  class Solution (line 10) | class Solution {
    method translateNum (line 12) | int translateNum(int num) {
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_46_translate_numbers_into_strings_s3/sfo_46_translate_numbers_into_strings_s3.cpp
  class Solution (line 10) | class Solution {
    method translateNum (line 12) | int translateNum(int num) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_47_the_maximum_value_of_gifts_s1/sfo_47_the_maximum_value_of_gifts_s1.cpp
  class Solution (line 10) | class Solution {
    method maxValue (line 12) | int maxValue(vector<vector<int>> &grid) {
  function main (line 30) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_47_the_maximum_value_of_gifts_s2/sfo_47_the_maximum_value_of_gifts_s2.cpp
  class Solution (line 10) | class Solution {
    method maxValue (line 12) | int maxValue(vector<vector<int>> &grid) {
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_48_the_longest_substring_without_repeated_characters_s1/sfo_48_the_longest_substring_without_repeated_characters_s1.cpp
  class Solution (line 10) | class Solution {
    method lengthOfLongestSubstring (line 12) | int lengthOfLongestSubstring(string s) {
  function main (line 28) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_48_the_longest_substring_without_repeated_characters_s2/sfo_48_the_longest_substring_without_repeated_characters_s2.cpp
  class Solution (line 10) | class Solution {
    method lengthOfLongestSubstring (line 12) | int lengthOfLongestSubstring(string s) {
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_48_the_longest_substring_without_repeated_characters_s3/sfo_48_the_longest_substring_without_repeated_characters_s3.cpp
  class Solution (line 10) | class Solution {
    method lengthOfLongestSubstring (line 12) | int lengthOfLongestSubstring(string s) {
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_49_ugly_numbers_s1/sfo_49_ugly_numbers_s1.cpp
  class Solution (line 10) | class Solution {
    method nthUglyNumber (line 12) | int nthUglyNumber(int n) {
  function main (line 30) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_50_find_the_first_nonrepeating_character_in_a_string_s1/sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.cpp
  class Solution (line 10) | class Solution {
    method firstUniqChar (line 12) | char firstUniqChar(string s) {
  function main (line 23) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_50_find_the_first_nonrepeating_character_in_a_string_s2/sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.cpp
  class Solution (line 10) | class Solution {
    method firstUniqChar (line 12) | char firstUniqChar(string s) {
  function main (line 28) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_51_reversed_pairs_in_an_array_s1/sfo_51_reversed_pairs_in_an_array_s1.cpp
  class Solution (line 10) | class Solution {
    method reversePairs (line 12) | int reversePairs(vector<int> &nums) {
    method mergeSort (line 18) | int mergeSort(int l, int r, vector<int> &nums, vector<int> &tmp) {
  function main (line 43) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_52_the_first_common_node_in_two_linked_lists_s1/sfo_52_the_first_common_node_in_two_linked_lists_s1.cpp
  class Solution (line 10) | class Solution {
    method ListNode (line 12) | ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
  function main (line 22) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_53i_find_a_number_in_a_sorted_array_s1/sfo_53i_find_a_number_in_a_sorted_array_s1.cpp
  class Solution (line 10) | class Solution {
    method search (line 12) | int search(vector<int> &nums, int target) {
  function main (line 41) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_53i_find_a_number_in_a_sorted_array_s2/sfo_53i_find_a_number_in_a_sorted_array_s2.cpp
  class Solution (line 10) | class Solution {
    method search (line 12) | int search(vector<int> &nums, int target) {
    method helper (line 17) | int helper(vector<int> &nums, int tar) {
  function main (line 30) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_53ii_the_missing_number_from_0_to_n1_s1/sfo_53ii_the_missing_number_from_0_to_n1_s1.cpp
  class Solution (line 10) | class Solution {
    method missingNumber (line 12) | int missingNumber(vector<int> &nums) {
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1/sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method kthLargest (line 12) | int kthLargest(TreeNode *root, int k) {
    method dfs (line 20) | void dfs(TreeNode *root) {
  function main (line 32) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_55i_depth_of_a_binary_tree_s1/sfo_55i_depth_of_a_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method maxDepth (line 12) | int maxDepth(TreeNode *root) {
  function main (line 19) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_55i_depth_of_a_binary_tree_s2/sfo_55i_depth_of_a_binary_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method maxDepth (line 12) | int maxDepth(TreeNode *root) {
  function main (line 33) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_55ii_balanced_binary_tree_s1/sfo_55ii_balanced_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method isBalanced (line 12) | bool isBalanced(TreeNode *root) {
    method recur (line 17) | int recur(TreeNode *root) {
  function main (line 30) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_55ii_balanced_binary_tree_s2/sfo_55ii_balanced_binary_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method isBalanced (line 12) | bool isBalanced(TreeNode *root) {
    method depth (line 19) | int depth(TreeNode *root) {
  function main (line 26) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_56i_single_number_i_s1/sfo_56i_single_number_i_s1.cpp
  class Solution (line 10) | class Solution {
    method singleNumbers (line 12) | vector<int> singleNumbers(vector<int> &nums) {
  function main (line 28) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_56ii_single_number_ii_s1/sfo_56ii_single_number_ii_s1.cpp
  class Solution (line 10) | class Solution {
    method singleNumber (line 12) | int singleNumber(vector<int> &nums) {
  function main (line 22) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_56ii_single_number_ii_s2/sfo_56ii_single_number_ii_s2.cpp
  class Solution (line 10) | class Solution {
    method singleNumber (line 12) | int singleNumber(vector<int> &nums) {
  function main (line 29) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_57_two_numbers_with_sum_s_s1/sfo_57_two_numbers_with_sum_s_s1.cpp
  class Solution (line 10) | class Solution {
    method twoSum (line 12) | vector<int> twoSum(vector<int> &nums, int target) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s1/sfo_57ii_consecutive_numbers_with_sum_s_s1.cpp
  class Solution (line 10) | class Solution {
    method findContinuousSequence (line 12) | vector<vector<int>> findContinuousSequence(int target) {
  function main (line 30) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_57ii_consecutive_numbers_with_sum_s_s2/sfo_57ii_consecutive_numbers_with_sum_s_s2.cpp
  class Solution (line 10) | class Solution {
    method findContinuousSequence (line 12) | vector<vector<int>> findContinuousSequence(int target) {
  function main (line 34) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_58ii_left_rotation_of_a_string_s1/sfo_58ii_left_rotation_of_a_string_s1.cpp
  class Solution (line 10) | class Solution {
    method string (line 12) | string reverseLeftWords(string s, int n) {
  function main (line 17) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_58ii_left_rotation_of_a_string_s2/sfo_58ii_left_rotation_of_a_string_s2.cpp
  class Solution (line 10) | class Solution {
    method string (line 12) | string reverseLeftWords(string s, int n) {
    method reverseString (line 20) | void reverseString(string &s, int i, int j) {
  function main (line 26) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_58ii_left_rotation_of_a_string_s3/sfo_58ii_left_rotation_of_a_string_s3.cpp
  class Solution (line 10) | class Solution {
    method string (line 12) | string reverseLeftWords(string s, int n) {
  function main (line 20) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_59ii_max_queue_s1/sfo_59ii_max_queue_s1.cpp
  class MaxQueue (line 10) | class MaxQueue {
    method MaxQueue (line 15) | MaxQueue() {
    method max_value (line 17) | int max_value() {
    method push_back (line 20) | void push_back(int value) {
    method pop_front (line 26) | int pop_front() {
  function main (line 37) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_60_probabilities_for_rolling_n_dices_s1/sfo_60_probabilities_for_rolling_n_dices_s1.cpp
  class Solution (line 10) | class Solution {
    method dicesProbability (line 12) | vector<double> dicesProbability(int n) {
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_61_straight_in_poker_s1/sfo_61_straight_in_poker_s1.cpp
  class Solution (line 10) | class Solution {
    method isStraight (line 12) | bool isStraight(vector<int> &nums) {
  function main (line 28) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_61_straight_in_poker_s2/sfo_61_straight_in_poker_s2.cpp
  class Solution (line 10) | class Solution {
    method isStraight (line 12) | bool isStraight(vector<int> &nums) {
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_62_josephus_problem_s1/sfo_62_josephus_problem_s1.cpp
  class Solution (line 10) | class Solution {
    method lastRemaining (line 12) | int lastRemaining(int n, int m) {
  function main (line 21) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_63_the_maximum_profit_of_stocks_s1/sfo_63_the_maximum_profit_of_stocks_s1.cpp
  class Solution (line 10) | class Solution {
    method maxProfit (line 12) | int maxProfit(vector<int> &prices) {
  function main (line 22) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_64_solve_1_2___n_s1/sfo_64_solve_1_2___n_s1.cpp
  class Solution (line 10) | class Solution {
    method sumNums (line 12) | int sumNums(int n) {
  function main (line 18) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_65_implement_addition_operation_without_arithmetic_operators_s1/sfo_65_implement_addition_operation_without_arithmetic_operators_s1.cpp
  class Solution (line 10) | class Solution {
    method add (line 12) | int add(int a, int b) {
  function main (line 22) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_66_a_product_array_puzzle_s1/sfo_66_a_product_array_puzzle_s1.cpp
  class Solution (line 10) | class Solution {
    method constructArr (line 12) | vector<int> constructArr(vector<int> &a) {
  function main (line 30) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_67_convert_string_to_int_s1/sfo_67_convert_string_to_int_s1.cpp
  class Solution (line 10) | class Solution {
    method strToInt (line 12) | int strToInt(string str) {
  function main (line 35) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *...
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *...
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s3.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *...
  function main (line 21) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1/sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s1.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *...
  function main (line 25) | int main() {

FILE: sword_for_offer/codes/cpp/sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2/sfo_68ii_the_nearest_common_ancestor_of_a_binary_tree_s2.cpp
  class Solution (line 10) | class Solution {
    method TreeNode (line 12) | TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *...
  function main (line 27) | int main() {

FILE: sword_for_offer/codes/java/include/ListNode.java
  class ListNode (line 8) | public class ListNode {
    method ListNode (line 12) | public ListNode(int x) {
    method arrToLinkedList (line 22) | public static ListNode arrToLinkedList(int[] arr) {
    method getListNode (line 39) | public static ListNode getListNode(ListNode head, int val) {

FILE: sword_for_offer/codes/java/include/PrintUtil.java
  class Trunk (line 5) | class Trunk {
    method Trunk (line 9) | Trunk(Trunk prev, String str) {
  class PrintUtil (line 15) | public class PrintUtil {
    method printLinkedList (line 21) | public static void printLinkedList(ListNode head) {
    method printTree (line 37) | public static void printTree(TreeNode root) {
    method printTree (line 48) | public static void printTree(TreeNode root, Trunk prev, boolean isLeft) {
    method showTrunks (line 79) | public static void showTrunks(Trunk p) {

FILE: sword_for_offer/codes/java/include/TreeNode.java
  class TreeNode (line 8) | public class TreeNode {
    method TreeNode (line 13) | public TreeNode(int x) {
    method arrToTree (line 23) | public static TreeNode arrToTree(Integer[] arr) {
    method treeToList (line 53) | public static List<Integer> treeToList(TreeNode root) {
    method getTreeNode (line 82) | public static TreeNode getTreeNode(TreeNode root, int val) {

FILE: sword_for_offer/codes/java/sfo_03_find_duplicate_numbers_in_an_array_s1/sfo_03_find_duplicate_numbers_in_an_array_s1.java
  class Solution (line 13) | class Solution {
    method findRepeatNumber (line 14) | public int findRepeatNumber(int[] nums) {
  class sfo_03_find_duplicate_numbers_in_an_array_s1 (line 25) | public class sfo_03_find_duplicate_numbers_in_an_array_s1 {
    method main (line 26) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_03_find_duplicate_numbers_in_an_array_s2/sfo_03_find_duplicate_numbers_in_an_array_s2.java
  class Solution (line 13) | class Solution {
    method findRepeatNumber (line 14) | public int findRepeatNumber(int[] nums) {
  class sfo_03_find_duplicate_numbers_in_an_array_s2 (line 31) | public class sfo_03_find_duplicate_numbers_in_an_array_s2 {
    method main (line 32) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_04_find_a_number_in_2d_matrix_s1/sfo_04_find_a_number_in_2d_matrix_s1.java
  class Solution (line 13) | class Solution {
    method findNumberIn2DArray (line 14) | public boolean findNumberIn2DArray(int[][] matrix, int target) {
  class sfo_04_find_a_number_in_2d_matrix_s1 (line 28) | public class sfo_04_find_a_number_in_2d_matrix_s1 {
    method main (line 29) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_05_replace_spaces_s1/sfo_05_replace_spaces_s1.java
  class Solution (line 13) | class Solution {
    method replaceSpace (line 14) | public String replaceSpace(String s) {
  class sfo_05_replace_spaces_s1 (line 26) | public class sfo_05_replace_spaces_s1 {
    method main (line 27) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_06_print_a_linked_list_in_reverse_order_s1/sfo_06_print_a_linked_list_in_reverse_order_s1.java
  class Solution (line 13) | class Solution {
    method reversePrint (line 16) | public int[] reversePrint(ListNode head) {
    method recur (line 24) | void recur(ListNode head) {
  class sfo_06_print_a_linked_list_in_reverse_order_s1 (line 32) | public class sfo_06_print_a_linked_list_in_reverse_order_s1 {
    method main (line 33) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_06_print_a_linked_list_in_reverse_order_s2/sfo_06_print_a_linked_list_in_reverse_order_s2.java
  class Solution (line 13) | class Solution {
    method reversePrint (line 14) | public int[] reversePrint(ListNode head) {
  class sfo_06_print_a_linked_list_in_reverse_order_s2 (line 27) | public class sfo_06_print_a_linked_list_in_reverse_order_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_07_reconstruct_binary_tree_s1/sfo_07_reconstruct_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method buildTree (line 17) | public TreeNode buildTree(int[] preorder, int[] inorder) {
    method recur (line 24) | TreeNode recur(int root, int left, int right) {
  class sfo_07_reconstruct_binary_tree_s1 (line 35) | public class sfo_07_reconstruct_binary_tree_s1 {
    method main (line 36) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_09_implement_a_queue_using_two_stacks_s1/sfo_09_implement_a_queue_using_two_stacks_s1.java
  class CQueue (line 13) | class CQueue {
    method CQueue (line 16) | public CQueue() {
    method appendTail (line 21) | public void appendTail(int value) {
    method deleteHead (line 25) | public int deleteHead() {
  class sfo_09_implement_a_queue_using_two_stacks_s1 (line 36) | public class sfo_09_implement_a_queue_using_two_stacks_s1 {
    method main (line 37) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_10i_fibonacci_numbers_s1/sfo_10i_fibonacci_numbers_s1.java
  class Solution (line 13) | class Solution {
    method fib (line 14) | public int fib(int n) {
  class sfo_10i_fibonacci_numbers_s1 (line 25) | public class sfo_10i_fibonacci_numbers_s1 {
    method main (line 26) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_10ii_frog_jump_s1/sfo_10ii_frog_jump_s1.java
  class Solution (line 13) | class Solution {
    method numWays (line 14) | public int numWays(int n) {
  class sfo_10ii_frog_jump_s1 (line 25) | public class sfo_10ii_frog_jump_s1 {
    method main (line 26) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_11_find_minimum_in_rotated_sorted_array_s1/sfo_11_find_minimum_in_rotated_sorted_array_s1.java
  class Solution (line 13) | class Solution {
    method minArray (line 14) | public int minArray(int[] numbers) {
  class sfo_11_find_minimum_in_rotated_sorted_array_s1 (line 29) | public class sfo_11_find_minimum_in_rotated_sorted_array_s1 {
    method main (line 30) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_11_find_minimum_in_rotated_sorted_array_s2/sfo_11_find_minimum_in_rotated_sorted_array_s2.java
  class Solution (line 13) | class Solution {
    method minArray (line 14) | public int minArray(int[] numbers) {
  class sfo_11_find_minimum_in_rotated_sorted_array_s2 (line 35) | public class sfo_11_find_minimum_in_rotated_sorted_array_s2 {
    method main (line 36) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_12_word_search_s1/sfo_12_word_search_s1.java
  class Solution (line 13) | class Solution {
    method exist (line 14) | public boolean exist(char[][] board, String word) {
    method dfs (line 25) | boolean dfs(char[][] board, char[] word, int i, int j, int k) {
  class sfo_12_word_search_s1 (line 38) | public class sfo_12_word_search_s1 {
    method main (line 39) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_13_range_of_motion_of_a_robot_s1/sfo_13_range_of_motion_of_a_robot_s1.java
  class Solution (line 13) | class Solution {
    method movingCount (line 17) | public int movingCount(int m, int n, int k) {
    method dfs (line 25) | public int dfs(int i, int j, int si, int sj) {
  class sfo_13_range_of_motion_of_a_robot_s1 (line 34) | public class sfo_13_range_of_motion_of_a_robot_s1 {
    method main (line 35) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_13_range_of_motion_of_a_robot_s2/sfo_13_range_of_motion_of_a_robot_s2.java
  class Solution (line 13) | class Solution {
    method movingCount (line 14) | public int movingCount(int m, int n, int k) {
  class sfo_13_range_of_motion_of_a_robot_s2 (line 33) | public class sfo_13_range_of_motion_of_a_robot_s2 {
    method main (line 34) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_14i_cut_the_rope_i_s1/sfo_14i_cut_the_rope_i_s1.java
  class Solution (line 13) | class Solution {
    method cuttingRope (line 14) | public int cuttingRope(int n) {
  class sfo_14i_cut_the_rope_i_s1 (line 26) | public class sfo_14i_cut_the_rope_i_s1 {
    method main (line 27) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_14ii_cut_the_rope_ii_s1/sfo_14ii_cut_the_rope_ii_s1.java
  class Solution (line 13) | class Solution {
    method cuttingRope (line 14) | public int cuttingRope(int n) {
  class sfo_14ii_cut_the_rope_ii_s1 (line 32) | public class sfo_14ii_cut_the_rope_ii_s1 {
    method main (line 33) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_15_number_of_1_bits_s1/sfo_15_number_of_1_bits_s1.java
  class Solution (line 13) | class Solution {
    method hammingWeight (line 14) | public int hammingWeight(int n) {
  class sfo_15_number_of_1_bits_s1 (line 24) | public class sfo_15_number_of_1_bits_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_15_number_of_1_bits_s2/sfo_15_number_of_1_bits_s2.java
  class Solution (line 13) | class Solution {
    method hammingWeight (line 14) | public int hammingWeight(int n) {
  class sfo_15_number_of_1_bits_s2 (line 24) | public class sfo_15_number_of_1_bits_s2 {
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_16_powers_of_integers_s1/sfo_16_powers_of_integers_s1.java
  class Solution (line 13) | class Solution {
    method myPow (line 14) | public double myPow(double x, int n) {
  class sfo_16_powers_of_integers_s1 (line 33) | public class sfo_16_powers_of_integers_s1 {
    method main (line 34) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_17_print_from_1_to_the_largest_n_digits_s1/sfo_17_print_from_1_to_the_largest_n_digits_s1.java
  class Solution (line 13) | class Solution {
    method printNumbers (line 14) | public int[] printNumbers(int n) {
  class sfo_17_print_from_1_to_the_largest_n_digits_s1 (line 23) | public class sfo_17_print_from_1_to_the_largest_n_digits_s1 {
    method main (line 24) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_17_print_from_1_to_the_largest_n_digits_s2/sfo_17_print_from_1_to_the_largest_n_digits_s2.java
  class Solution (line 13) | class Solution {
    method printNumbers (line 18) | public String printNumbers(int n) {
    method dfs (line 27) | void dfs(int x) {
  class sfo_17_print_from_1_to_the_largest_n_digits_s2 (line 39) | public class sfo_17_print_from_1_to_the_largest_n_digits_s2 {
    method main (line 40) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_17_print_from_1_to_the_largest_n_digits_s3/sfo_17_print_from_1_to_the_largest_n_digits_s3.java
  class Solution (line 13) | class Solution {
    method printNumbers (line 18) | public String printNumbers(int n) {
    method dfs (line 28) | void dfs(int x) {
  class sfo_17_print_from_1_to_the_largest_n_digits_s3 (line 47) | public class sfo_17_print_from_1_to_the_largest_n_digits_s3 {
    method main (line 48) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_17_print_from_1_to_the_largest_n_digits_s4/sfo_17_print_from_1_to_the_largest_n_digits_s4.java
  class Solution (line 13) | class Solution {
    method printNumbers (line 18) | public int[] printNumbers(int n) {
    method dfs (line 27) | void dfs(int x) {
  class sfo_17_print_from_1_to_the_largest_n_digits_s4 (line 46) | public class sfo_17_print_from_1_to_the_largest_n_digits_s4 {
    method main (line 47) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_18_delete_a_node_from_a_linked_list_s1/sfo_18_delete_a_node_from_a_linked_list_s1.java
  class Solution (line 13) | class Solution {
    method deleteNode (line 14) | public ListNode deleteNode(ListNode head, int val) {
  class sfo_18_delete_a_node_from_a_linked_list_s1 (line 28) | public class sfo_18_delete_a_node_from_a_linked_list_s1 {
    method main (line 29) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_19_regular_expression_matching_s1/sfo_19_regular_expression_matching_s1.java
  class Solution (line 13) | class Solution {
    method isMatch (line 14) | public boolean isMatch(String s, String p) {
  class sfo_19_regular_expression_matching_s1 (line 31) | public class sfo_19_regular_expression_matching_s1 {
    method main (line 32) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_19_regular_expression_matching_s2/sfo_19_regular_expression_matching_s2.java
  class Solution (line 13) | class Solution {
    method isMatch (line 14) | public boolean isMatch(String s, String p) {
  class sfo_19_regular_expression_matching_s2 (line 43) | public class sfo_19_regular_expression_matching_s2 {
    method main (line 44) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_20_a_string_representing_a_numeric_value_s1/sfo_20_a_string_representing_a_numeric_value_s1.java
  class Solution (line 13) | class Solution {
    method isNumber (line 14) | public boolean isNumber(String s) {
  class sfo_20_a_string_representing_a_numeric_value_s1 (line 94) | public class sfo_20_a_string_representing_a_numeric_value_s1 {
    method main (line 95) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_21_adjust_the_order_of_numbers_in_an_array_s1/sfo_21_adjust_the_order_of_numbers_in_an_array_s1.java
  class Solution (line 13) | class Solution {
    method exchange (line 14) | public int[] exchange(int[] nums) {
  class sfo_21_adjust_the_order_of_numbers_in_an_array_s1 (line 29) | public class sfo_21_adjust_the_order_of_numbers_in_an_array_s1 {
    method main (line 30) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/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.java
  class Solution (line 13) | class Solution {
    method getKthFromEnd (line 14) | public ListNode getKthFromEnd(ListNode head, int k) {
  class sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1 (line 26) | public class sfo_22_the_kth_node_from_the_end_of_a_linked_list_s1 {
    method main (line 27) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/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.java
  class Solution (line 13) | class Solution {
    method getKthFromEnd (line 14) | public ListNode getKthFromEnd(ListNode head, int k) {
  class sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2 (line 29) | public class sfo_22_the_kth_node_from_the_end_of_a_linked_list_s2 {
    method main (line 30) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_24_reverse_a_linked_list_s1/sfo_24_reverse_a_linked_list_s1.java
  class Solution (line 13) | class Solution {
    method reverseList (line 14) | public ListNode reverseList(ListNode head) {
  class sfo_24_reverse_a_linked_list_s1 (line 26) | public class sfo_24_reverse_a_linked_list_s1 {
    method main (line 27) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_24_reverse_a_linked_list_s2/sfo_24_reverse_a_linked_list_s2.java
  class Solution (line 13) | class Solution {
    method reverseList (line 14) | public ListNode reverseList(ListNode head) {
    method recur (line 18) | private ListNode recur(ListNode cur, ListNode pre) {
  class sfo_24_reverse_a_linked_list_s2 (line 27) | public class sfo_24_reverse_a_linked_list_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_25_combine_two_sorted_linked_lists_s1/sfo_25_combine_two_sorted_linked_lists_s1.java
  class Solution (line 13) | class Solution {
    method mergeTwoLists (line 14) | public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
  class sfo_25_combine_two_sorted_linked_lists_s1 (line 31) | public class sfo_25_combine_two_sorted_linked_lists_s1 {
    method main (line 32) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_26_substructure_of_a_binary_tree_s1/sfo_26_substructure_of_a_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method isSubStructure (line 14) | public boolean isSubStructure(TreeNode A, TreeNode B) {
    method recur (line 18) | boolean recur(TreeNode A, TreeNode B) {
  class sfo_26_substructure_of_a_binary_tree_s1 (line 27) | public class sfo_26_substructure_of_a_binary_tree_s1 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_27_mirror_of_a_binary_tree_s1/sfo_27_mirror_of_a_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method mirrorTree (line 14) | public TreeNode mirrorTree(TreeNode root) {
  class sfo_27_mirror_of_a_binary_tree_s1 (line 24) | public class sfo_27_mirror_of_a_binary_tree_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_27_mirror_of_a_binary_tree_s2/sfo_27_mirror_of_a_binary_tree_s2.java
  class Solution (line 13) | class Solution {
    method mirrorTree (line 14) | public TreeNode mirrorTree(TreeNode root) {
  class sfo_27_mirror_of_a_binary_tree_s2 (line 36) | public class sfo_27_mirror_of_a_binary_tree_s2 {
    method main (line 37) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_28_symmetric_binary_tree_s1/sfo_28_symmetric_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method isSymmetric (line 14) | public boolean isSymmetric(TreeNode root) {
    method recur (line 18) | boolean recur(TreeNode L, TreeNode R) {
  class sfo_28_symmetric_binary_tree_s1 (line 27) | public class sfo_28_symmetric_binary_tree_s1 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_29_print_a_given_matrix_in_spiral_form_s1/sfo_29_print_a_given_matrix_in_spiral_form_s1.java
  class Solution (line 13) | class Solution {
    method spiralOrder (line 14) | public int[] spiralOrder(int[][] matrix) {
  class sfo_29_print_a_given_matrix_in_spiral_form_s1 (line 41) | public class sfo_29_print_a_given_matrix_in_spiral_form_s1 {
    method main (line 42) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_30_min_stack_s1/sfo_30_min_stack_s1.java
  class MinStack (line 13) | class MinStack {
    method MinStack (line 16) | public MinStack() {
    method push (line 21) | public void push(int x) {
    method pop (line 27) | public void pop() {
    method top (line 32) | public int top() {
    method min (line 36) | public int min() {
  class sfo_30_min_stack_s1 (line 41) | public class sfo_30_min_stack_s1 {
    method main (line 42) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_31_validate_stack_sequences_s1/sfo_31_validate_stack_sequences_s1.java
  class Solution (line 13) | class Solution {
    method validateStackSequences (line 14) | public boolean validateStackSequences(int[] pushed, int[] popped) {
  class sfo_31_validate_stack_sequences_s1 (line 28) | public class sfo_31_validate_stack_sequences_s1 {
    method main (line 29) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_32i_print_a_binary_tree_topbottom_i_s1/sfo_32i_print_a_binary_tree_topbottom_i_s1.java
  class Solution (line 13) | class Solution {
    method levelOrder (line 14) | public int[] levelOrder(TreeNode root) {
  class sfo_32i_print_a_binary_tree_topbottom_i_s1 (line 38) | public class sfo_32i_print_a_binary_tree_topbottom_i_s1 {
    method main (line 39) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_32ii_print_a_binary_tree_topbottom_ii_s1/sfo_32ii_print_a_binary_tree_topbottom_ii_s1.java
  class Solution (line 13) | class Solution {
    method levelOrder (line 14) | public List<List<Integer>> levelOrder(TreeNode root) {
  class sfo_32ii_print_a_binary_tree_topbottom_ii_s1 (line 35) | public class sfo_32ii_print_a_binary_tree_topbottom_ii_s1 {
    method main (line 36) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_32iii_print_a_binary_tree_topbottom_iii_s1/sfo_32iii_print_a_binary_tree_topbottom_iii_s1.java
  class Solution (line 13) | class Solution {
    method levelOrder (line 14) | public List<List<Integer>> levelOrder(TreeNode root) {
  class sfo_32iii_print_a_binary_tree_topbottom_iii_s1 (line 38) | public class sfo_32iii_print_a_binary_tree_topbottom_iii_s1 {
    method main (line 39) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_32iii_print_a_binary_tree_topbottom_iii_s2/sfo_32iii_print_a_binary_tree_topbottom_iii_s2.java
  class Solution (line 13) | class Solution {
    method levelOrder (line 14) | public List<List<Integer>> levelOrder(TreeNode root) {
  class sfo_32iii_print_a_binary_tree_topbottom_iii_s2 (line 53) | public class sfo_32iii_print_a_binary_tree_topbottom_iii_s2 {
    method main (line 54) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_32iii_print_a_binary_tree_topbottom_iii_s3/sfo_32iii_print_a_binary_tree_topbottom_iii_s3.java
  class Solution (line 13) | class Solution {
    method levelOrder (line 14) | public List<List<Integer>> levelOrder(TreeNode root) {
  class sfo_32iii_print_a_binary_tree_topbottom_iii_s3 (line 37) | public class sfo_32iii_print_a_binary_tree_topbottom_iii_s3 {
    method main (line 38) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_33_postorder_traversal_of_a_binary_search_tree_s1/sfo_33_postorder_traversal_of_a_binary_search_tree_s1.java
  class Solution (line 13) | class Solution {
    method verifyPostorder (line 14) | public boolean verifyPostorder(int[] postorder) {
    method recur (line 18) | boolean recur(int[] postorder, int i, int j) {
  class sfo_33_postorder_traversal_of_a_binary_search_tree_s1 (line 31) | public class sfo_33_postorder_traversal_of_a_binary_search_tree_s1 {
    method main (line 32) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_33_postorder_traversal_of_a_binary_search_tree_s2/sfo_33_postorder_traversal_of_a_binary_search_tree_s2.java
  class Solution (line 13) | class Solution {
    method verifyPostorder (line 14) | public boolean verifyPostorder(int[] postorder) {
  class sfo_33_postorder_traversal_of_a_binary_search_tree_s2 (line 28) | public class sfo_33_postorder_traversal_of_a_binary_search_tree_s2 {
    method main (line 29) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_34_all_xsum_paths_in_a_binary_tree_s1/sfo_34_all_xsum_paths_in_a_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method pathSum (line 17) | public List<List<Integer>> pathSum(TreeNode root, int sum) {
    method recur (line 22) | void recur(TreeNode root, int tar) {
  class sfo_34_all_xsum_paths_in_a_binary_tree_s1 (line 35) | public class sfo_34_all_xsum_paths_in_a_binary_tree_s1 {
    method main (line 36) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1.java
  class Node (line 13) | class Node {
    method Node (line 18) | public Node(int val) {
  class Solution (line 26) | class Solution {
    method copyRandomList (line 27) | public Node copyRandomList(Node head) {
  class sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1 (line 49) | public class sfo_35_clone_a_linked_list_with_next_and_random_pointer_s1 {
    method main (line 50) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2/sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2.java
  class Node (line 13) | class Node {
    method Node (line 18) | public Node(int val) {
  class Solution (line 26) | class Solution {
    method copyRandomList (line 27) | public Node copyRandomList(Node head) {
  class sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2 (line 59) | public class sfo_35_clone_a_linked_list_with_next_and_random_pointer_s2 {
    method main (line 60) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_36_binary_search_tree_and_doubly_linked_list_s1/sfo_36_binary_search_tree_and_doubly_linked_list_s1.java
  class Node (line 13) | class Node {
    method Node (line 18) | public Node(int val) {
  class Solution (line 26) | class Solution {
    method treeToDoublyList (line 29) | public Node treeToDoublyList(Node root) {
    method dfs (line 38) | void dfs(Node cur) {
  class sfo_36_binary_search_tree_and_doubly_linked_list_s1 (line 52) | public class sfo_36_binary_search_tree_and_doubly_linked_list_s1 {
    method main (line 53) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_37_serialize_and_deserialize_a_binary_tree_s1/sfo_37_serialize_and_deserialize_a_binary_tree_s1.java
  class Codec (line 13) | class Codec {
    method serialize (line 14) | public String serialize(TreeNode root) {
    method deserialize (line 37) | public TreeNode deserialize(String data) {
  class sfo_37_serialize_and_deserialize_a_binary_tree_s1 (line 65) | public class sfo_37_serialize_and_deserialize_a_binary_tree_s1 {
    method main (line 66) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_38_all_permutations_of_a_string_s1/sfo_38_all_permutations_of_a_string_s1.java
  class Solution (line 13) | class Solution {
    method permutation (line 17) | public String[] permutation(String s) {
    method dfs (line 23) | void dfs(int x) {
    method swap (line 39) | void swap(int a, int b) {
  class sfo_38_all_permutations_of_a_string_s1 (line 46) | public class sfo_38_all_permutations_of_a_string_s1 {
    method main (line 47) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_39_the_majority_element_in_an_array_s1/sfo_39_the_majority_element_in_an_array_s1.java
  class Solution (line 13) | class Solution {
    method majorityElement (line 14) | public int majorityElement(int[] nums) {
  class sfo_39_the_majority_element_in_an_array_s1 (line 25) | public class sfo_39_the_majority_element_in_an_array_s1 {
    method main (line 26) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_39_the_majority_element_in_an_array_s2/sfo_39_the_majority_element_in_an_array_s2.java
  class Solution (line 13) | class Solution {
    method majorityElement (line 14) | public int majorityElement(int[] nums) {
  class sfo_39_the_majority_element_in_an_array_s2 (line 29) | public class sfo_39_the_majority_element_in_an_array_s2 {
    method main (line 30) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_40_the_smallest_k_numbers_s1/sfo_40_the_smallest_k_numbers_s1.java
  class Solution (line 13) | class Solution {
    method getLeastNumbers (line 14) | public int[] getLeastNumbers(int[] arr, int k) {
    method quickSort (line 19) | private void quickSort(int[] arr, int l, int r) {
    method swap (line 38) | private void swap(int[] arr, int i, int j) {
  class sfo_40_the_smallest_k_numbers_s1 (line 45) | public class sfo_40_the_smallest_k_numbers_s1 {
    method main (line 46) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_40_the_smallest_k_numbers_s2/sfo_40_the_smallest_k_numbers_s2.java
  class Solution (line 13) | class Solution {
    method getLeastNumbers (line 14) | public int[] getLeastNumbers(int[] arr, int k) {
    method quickSort (line 20) | private int[] quickSort(int[] arr, int k, int l, int r) {
    method swap (line 37) | private void swap(int[] arr, int i, int j) {
  class sfo_40_the_smallest_k_numbers_s2 (line 44) | public class sfo_40_the_smallest_k_numbers_s2 {
    method main (line 45) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_41_find_median_from_data_stream_s1/sfo_41_find_median_from_data_stream_s1.java
  class MedianFinder (line 13) | class MedianFinder {
    method MedianFinder (line 16) | public MedianFinder() {
    method addNum (line 21) | public void addNum(int num) {
    method findMedian (line 31) | public double findMedian() {
  class sfo_41_find_median_from_data_stream_s1 (line 36) | public class sfo_41_find_median_from_data_stream_s1 {
    method main (line 37) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_42_largest_sum_contiguous_subarray_s1/sfo_42_largest_sum_contiguous_subarray_s1.java
  class Solution (line 13) | class Solution {
    method maxSubArray (line 14) | public int maxSubArray(int[] nums) {
  class sfo_42_largest_sum_contiguous_subarray_s1 (line 24) | public class sfo_42_largest_sum_contiguous_subarray_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_43_total_number_of_1_in_integers_from_1_to_n_s1/sfo_43_total_number_of_1_in_integers_from_1_to_n_s1.java
  class Solution (line 13) | class Solution {
    method countDigitOne (line 14) | public int countDigitOne(int n) {
  class sfo_43_total_number_of_1_in_integers_from_1_to_n_s1 (line 33) | public class sfo_43_total_number_of_1_in_integers_from_1_to_n_s1 {
    method main (line 34) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_44_nth_digit_s1/sfo_44_nth_digit_s1.java
  class Solution (line 13) | class Solution {
    method findNthDigit (line 14) | public int findNthDigit(int n) {
  class sfo_44_nth_digit_s1 (line 29) | public class sfo_44_nth_digit_s1 {
    method main (line 30) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_45_arrange_an_array_into_the_smallest_number_s1/sfo_45_arrange_an_array_into_the_smallest_number_s1.java
  class Solution (line 13) | class Solution {
    method minNumber (line 14) | public String minNumber(int[] nums) {
    method quickSort (line 25) | void quickSort(String[] strs, int l, int r) {
  class sfo_45_arrange_an_array_into_the_smallest_number_s1 (line 46) | public class sfo_45_arrange_an_array_into_the_smallest_number_s1 {
    method main (line 47) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_45_arrange_an_array_into_the_smallest_number_s2/sfo_45_arrange_an_array_into_the_smallest_number_s2.java
  class Solution (line 13) | class Solution {
    method minNumber (line 14) | public String minNumber(int[] nums) {
  class sfo_45_arrange_an_array_into_the_smallest_number_s2 (line 26) | public class sfo_45_arrange_an_array_into_the_smallest_number_s2 {
    method main (line 27) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_46_translate_numbers_into_strings_s1/sfo_46_translate_numbers_into_strings_s1.java
  class Solution (line 13) | class Solution {
    method translateNum (line 14) | public int translateNum(int num) {
  class sfo_46_translate_numbers_into_strings_s1 (line 27) | public class sfo_46_translate_numbers_into_strings_s1 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_46_translate_numbers_into_strings_s2/sfo_46_translate_numbers_into_strings_s2.java
  class Solution (line 13) | class Solution {
    method translateNum (line 14) | public int translateNum(int num) {
  class sfo_46_translate_numbers_into_strings_s2 (line 27) | public class sfo_46_translate_numbers_into_strings_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_46_translate_numbers_into_strings_s3/sfo_46_translate_numbers_into_strings_s3.java
  class Solution (line 13) | class Solution {
    method translateNum (line 14) | public int translateNum(int num) {
  class sfo_46_translate_numbers_into_strings_s3 (line 29) | public class sfo_46_translate_numbers_into_strings_s3 {
    method main (line 30) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_47_the_maximum_value_of_gifts_s1/sfo_47_the_maximum_value_of_gifts_s1.java
  class Solution (line 13) | class Solution {
    method maxValue (line 14) | public int maxValue(int[][] grid) {
  class sfo_47_the_maximum_value_of_gifts_s1 (line 32) | public class sfo_47_the_maximum_value_of_gifts_s1 {
    method main (line 33) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_47_the_maximum_value_of_gifts_s2/sfo_47_the_maximum_value_of_gifts_s2.java
  class Solution (line 13) | class Solution {
    method maxValue (line 14) | public int maxValue(int[][] grid) {
  class sfo_47_the_maximum_value_of_gifts_s2 (line 27) | public class sfo_47_the_maximum_value_of_gifts_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_48_the_longest_substring_without_repeated_characters_s1/sfo_48_the_longest_substring_without_repeated_characters_s1.java
  class Solution (line 13) | class Solution {
    method lengthOfLongestSubstring (line 14) | public int lengthOfLongestSubstring(String s) {
  class sfo_48_the_longest_substring_without_repeated_characters_s1 (line 27) | public class sfo_48_the_longest_substring_without_repeated_characters_s1 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_48_the_longest_substring_without_repeated_characters_s2/sfo_48_the_longest_substring_without_repeated_characters_s2.java
  class Solution (line 13) | class Solution {
    method lengthOfLongestSubstring (line 14) | public int lengthOfLongestSubstring(String s) {
  class sfo_48_the_longest_substring_without_repeated_characters_s2 (line 27) | public class sfo_48_the_longest_substring_without_repeated_characters_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_48_the_longest_substring_without_repeated_characters_s3/sfo_48_the_longest_substring_without_repeated_characters_s3.java
  class Solution (line 13) | class Solution {
    method lengthOfLongestSubstring (line 14) | public int lengthOfLongestSubstring(String s) {
  class sfo_48_the_longest_substring_without_repeated_characters_s3 (line 27) | public class sfo_48_the_longest_substring_without_repeated_characters_s3 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_49_ugly_numbers_s1/sfo_49_ugly_numbers_s1.java
  class Solution (line 13) | class Solution {
    method nthUglyNumber (line 14) | public int nthUglyNumber(int n) {
  class sfo_49_ugly_numbers_s1 (line 32) | public class sfo_49_ugly_numbers_s1 {
    method main (line 33) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_50_find_the_first_nonrepeating_character_in_a_string_s1/sfo_50_find_the_first_nonrepeating_character_in_a_string_s1.java
  class Solution (line 13) | class Solution {
    method firstUniqChar (line 14) | public char firstUniqChar(String s) {
  class sfo_50_find_the_first_nonrepeating_character_in_a_string_s1 (line 26) | public class sfo_50_find_the_first_nonrepeating_character_in_a_string_s1 {
    method main (line 27) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_50_find_the_first_nonrepeating_character_in_a_string_s2/sfo_50_find_the_first_nonrepeating_character_in_a_string_s2.java
  class Solution (line 13) | class Solution {
    method firstUniqChar (line 14) | public char firstUniqChar(String s) {
  class sfo_50_find_the_first_nonrepeating_character_in_a_string_s2 (line 27) | public class sfo_50_find_the_first_nonrepeating_character_in_a_string_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_51_reversed_pairs_in_an_array_s1/sfo_51_reversed_pairs_in_an_array_s1.java
  class Solution (line 13) | class Solution {
    method reversePairs (line 16) | public int reversePairs(int[] nums) {
    method mergeSort (line 22) | private int mergeSort(int l, int r) {
  class sfo_51_reversed_pairs_in_an_array_s1 (line 47) | public class sfo_51_reversed_pairs_in_an_array_s1 {
    method main (line 48) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_52_the_first_common_node_in_two_linked_lists_s1/sfo_52_the_first_common_node_in_two_linked_lists_s1.java
  class Solution (line 13) | class Solution {
    method getIntersectionNode (line 14) | public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
  class sfo_52_the_first_common_node_in_two_linked_lists_s1 (line 24) | public class sfo_52_the_first_common_node_in_two_linked_lists_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_53i_find_a_number_in_a_sorted_array_s1/sfo_53i_find_a_number_in_a_sorted_array_s1.java
  class Solution (line 13) | class Solution {
    method search (line 14) | public int search(int[] nums, int target) {
  class sfo_53i_find_a_number_in_a_sorted_array_s1 (line 43) | public class sfo_53i_find_a_number_in_a_sorted_array_s1 {
    method main (line 44) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_53i_find_a_number_in_a_sorted_array_s2/sfo_53i_find_a_number_in_a_sorted_array_s2.java
  class Solution (line 13) | class Solution {
    method search (line 14) | public int search(int[] nums, int target) {
    method helper (line 18) | int helper(int[] nums, int tar) {
  class sfo_53i_find_a_number_in_a_sorted_array_s2 (line 31) | public class sfo_53i_find_a_number_in_a_sorted_array_s2 {
    method main (line 32) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_53ii_the_missing_number_from_0_to_n1_s1/sfo_53ii_the_missing_number_from_0_to_n1_s1.java
  class Solution (line 13) | class Solution {
    method missingNumber (line 14) | public int missingNumber(int[] nums) {
  class sfo_53ii_the_missing_number_from_0_to_n1_s1 (line 27) | public class sfo_53ii_the_missing_number_from_0_to_n1_s1 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1/sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1.java
  class Solution (line 13) | class Solution {
    method kthLargest (line 16) | public int kthLargest(TreeNode root, int k) {
    method dfs (line 22) | void dfs(TreeNode root) {
  class sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1 (line 34) | public class sfo_54_the_kth_largest_node_of_a_binary_search_tree_s1 {
    method main (line 35) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_55i_depth_of_a_binary_tree_s1/sfo_55i_depth_of_a_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method maxDepth (line 14) | public int maxDepth(TreeNode root) {
  class sfo_55i_depth_of_a_binary_tree_s1 (line 21) | public class sfo_55i_depth_of_a_binary_tree_s1 {
    method main (line 22) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_55i_depth_of_a_binary_tree_s2/sfo_55i_depth_of_a_binary_tree_s2.java
  class Solution (line 13) | class Solution {
    method maxDepth (line 14) | public int maxDepth(TreeNode root) {
  class sfo_55i_depth_of_a_binary_tree_s2 (line 38) | public class sfo_55i_depth_of_a_binary_tree_s2 {
    method main (line 39) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_55ii_balanced_binary_tree_s1/sfo_55ii_balanced_binary_tree_s1.java
  class Solution (line 13) | class Solution {
    method isBalanced (line 14) | public boolean isBalanced(TreeNode root) {
    method recur (line 18) | private int recur(TreeNode root) {
  class sfo_55ii_balanced_binary_tree_s1 (line 31) | public class sfo_55ii_balanced_binary_tree_s1 {
    method main (line 32) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_55ii_balanced_binary_tree_s2/sfo_55ii_balanced_binary_tree_s2.java
  class Solution (line 13) | class Solution {
    method isBalanced (line 14) | public boolean isBalanced(TreeNode root) {
    method depth (line 20) | private int depth(TreeNode root) {
  class sfo_55ii_balanced_binary_tree_s2 (line 27) | public class sfo_55ii_balanced_binary_tree_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_56i_single_number_i_s1/sfo_56i_single_number_i_s1.java
  class Solution (line 13) | class Solution {
    method singleNumbers (line 14) | public int[] singleNumbers(int[] nums) {
  class sfo_56i_single_number_i_s1 (line 30) | public class sfo_56i_single_number_i_s1 {
    method main (line 31) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_56ii_single_number_ii_s1/sfo_56ii_single_number_ii_s1.java
  class Solution (line 13) | class Solution {
    method singleNumber (line 14) | public int singleNumber(int[] nums) {
  class sfo_56ii_single_number_ii_s1 (line 24) | public class sfo_56ii_single_number_ii_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_56ii_single_number_ii_s2/sfo_56ii_single_number_ii_s2.java
  class Solution (line 13) | class Solution {
    method singleNumber (line 14) | public int singleNumber(int[] nums) {
  class sfo_56ii_single_number_ii_s2 (line 31) | public class sfo_56ii_single_number_ii_s2 {
    method main (line 32) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_57_two_numbers_with_sum_s_s1/sfo_57_two_numbers_with_sum_s_s1.java
  class Solution (line 13) | class Solution {
    method twoSum (line 14) | public int[] twoSum(int[] nums, int target) {
  class sfo_57_two_numbers_with_sum_s_s1 (line 29) | public class sfo_57_two_numbers_with_sum_s_s1 {
    method main (line 30) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_57ii_consecutive_numbers_with_sum_s_s1/sfo_57ii_consecutive_numbers_with_sum_s_s1.java
  class Solution (line 13) | class Solution {
    method findContinuousSequence (line 14) | public int[][] findContinuousSequence(int target) {
  class sfo_57ii_consecutive_numbers_with_sum_s_s1 (line 32) | public class sfo_57ii_consecutive_numbers_with_sum_s_s1 {
    method main (line 33) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_57ii_consecutive_numbers_with_sum_s_s2/sfo_57ii_consecutive_numbers_with_sum_s_s2.java
  class Solution (line 13) | class Solution {
    method findContinuousSequence (line 14) | public int[][] findContinuousSequence(int target) {
  class sfo_57ii_consecutive_numbers_with_sum_s_s2 (line 36) | public class sfo_57ii_consecutive_numbers_with_sum_s_s2 {
    method main (line 37) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_58i_reverse_order_of_words_s1/sfo_58i_reverse_order_of_words_s1.java
  class Solution (line 13) | class Solution {
    method reverseWords (line 14) | public String reverseWords(String s) {
  class sfo_58i_reverse_order_of_words_s1 (line 30) | public class sfo_58i_reverse_order_of_words_s1 {
    method main (line 31) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_58i_reverse_order_of_words_s2/sfo_58i_reverse_order_of_words_s2.java
  class Solution (line 13) | class Solution {
    method reverseWords (line 14) | public String reverseWords(String s) {
  class sfo_58i_reverse_order_of_words_s2 (line 26) | public class sfo_58i_reverse_order_of_words_s2 {
    method main (line 27) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_58ii_left_rotation_of_a_string_s1/sfo_58ii_left_rotation_of_a_string_s1.java
  class Solution (line 13) | class Solution {
    method reverseLeftWords (line 14) | public String reverseLeftWords(String s, int n) {
  class sfo_58ii_left_rotation_of_a_string_s1 (line 19) | public class sfo_58ii_left_rotation_of_a_string_s1 {
    method main (line 20) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_58ii_left_rotation_of_a_string_s2/sfo_58ii_left_rotation_of_a_string_s2.java
  class Solution (line 13) | class Solution {
    method reverseLeftWords (line 14) | public String reverseLeftWords(String s, int n) {
  class sfo_58ii_left_rotation_of_a_string_s2 (line 24) | public class sfo_58ii_left_rotation_of_a_string_s2 {
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_58ii_left_rotation_of_a_string_s3/sfo_58ii_left_rotation_of_a_string_s3.java
  class Solution (line 13) | class Solution {
    method reverseLeftWords (line 14) | public String reverseLeftWords(String s, int n) {
  class sfo_58ii_left_rotation_of_a_string_s3 (line 22) | public class sfo_58ii_left_rotation_of_a_string_s3 {
    method main (line 23) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_58ii_left_rotation_of_a_string_s4/sfo_58ii_left_rotation_of_a_string_s4.java
  class Solution (line 13) | class Solution {
    method reverseLeftWords (line 14) | public String reverseLeftWords(String s, int n) {
  class sfo_58ii_left_rotation_of_a_string_s4 (line 24) | public class sfo_58ii_left_rotation_of_a_string_s4 {
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_58ii_left_rotation_of_a_string_s5/sfo_58ii_left_rotation_of_a_string_s5.java
  class Solution (line 13) | class Solution {
    method reverseLeftWords (line 14) | public String reverseLeftWords(String s, int n) {
  class sfo_58ii_left_rotation_of_a_string_s5 (line 22) | public class sfo_58ii_left_rotation_of_a_string_s5 {
    method main (line 23) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_59i_sliding_window_maximum_s1/sfo_59i_sliding_window_maximum_s1.java
  class Solution (line 13) | class Solution {
    method maxSlidingWindow (line 14) | public int[] maxSlidingWindow(int[] nums, int k) {
  class sfo_59i_sliding_window_maximum_s1 (line 35) | public class sfo_59i_sliding_window_maximum_s1 {
    method main (line 36) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_59i_sliding_window_maximum_s2/sfo_59i_sliding_window_maximum_s2.java
  class Solution (line 13) | class Solution {
    method maxSlidingWindow (line 14) | public int[] maxSlidingWindow(int[] nums, int k) {
  class sfo_59i_sliding_window_maximum_s2 (line 39) | public class sfo_59i_sliding_window_maximum_s2 {
    method main (line 40) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_59ii_max_queue_s1/sfo_59ii_max_queue_s1.java
  class MaxQueue (line 13) | class MaxQueue {
    method MaxQueue (line 17) | public MaxQueue() {
    method max_value (line 22) | public int max_value() {
    method push_back (line 26) | public void push_back(int value) {
    method pop_front (line 33) | public int pop_front() {
  class sfo_59ii_max_queue_s1 (line 42) | public class sfo_59ii_max_queue_s1 {
    method main (line 43) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_60_probabilities_for_rolling_n_dices_s1/sfo_60_probabilities_for_rolling_n_dices_s1.java
  class Solution (line 13) | class Solution {
    method dicesProbability (line 14) | public double[] dicesProbability(int n) {
  class sfo_60_probabilities_for_rolling_n_dices_s1 (line 30) | public class sfo_60_probabilities_for_rolling_n_dices_s1 {
    method main (line 31) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_61_straight_in_poker_s1/sfo_61_straight_in_poker_s1.java
  class Solution (line 13) | class Solution {
    method isStraight (line 14) | public boolean isStraight(int[] nums) {
  class sfo_61_straight_in_poker_s1 (line 30) | public class sfo_61_straight_in_poker_s1 {
    method main (line 31) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_61_straight_in_poker_s2/sfo_61_straight_in_poker_s2.java
  class Solution (line 13) | class Solution {
    method isStraight (line 14) | public boolean isStraight(int[] nums) {
  class sfo_61_straight_in_poker_s2 (line 27) | public class sfo_61_straight_in_poker_s2 {
    method main (line 28) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_62_josephus_problem_s1/sfo_62_josephus_problem_s1.java
  class Solution (line 13) | class Solution {
    method lastRemaining (line 14) | public int lastRemaining(int n, int m) {
  class sfo_62_josephus_problem_s1 (line 23) | public class sfo_62_josephus_problem_s1 {
    method main (line 24) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_63_the_maximum_profit_of_stocks_s1/sfo_63_the_maximum_profit_of_stocks_s1.java
  class Solution (line 13) | class Solution {
    method maxProfit (line 14) | public int maxProfit(int[] prices) {
  class sfo_63_the_maximum_profit_of_stocks_s1 (line 24) | public class sfo_63_the_maximum_profit_of_stocks_s1 {
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_64_solve_1_2___n_s1/sfo_64_solve_1_2___n_s1.java
  class Solution (line 13) | class Solution {
    method sumNums (line 16) | public int sumNums(int n) {
  class sfo_64_solve_1_2___n_s1 (line 23) | public class sfo_64_solve_1_2___n_s1 {
    method main (line 24) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_64_solve_1_2___n_s2/sfo_64_solve_1_2___n_s2.java
  class Solution (line 13) | class Solution {
    method sumNums (line 14) | public int sumNums(int n) {
  class sfo_64_solve_1_2___n_s2 (line 20) | public class sfo_64_solve_1_2___n_s2 {
    method main (line 21) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_65_implement_addition_operation_without_arithmetic_operators_s1/sfo_65_implement_addition_operation_without_arithmetic_operators_s1.java
  class Solution (line 13) | class Solution {
    method add (line 14) | public int add(int a, int b) {
  class sfo_65_implement_addition_operation_without_arithmetic_operators_s1 (line 24) | public class sfo_65_implement_addition_operation_without_arithmetic_oper...
    method main (line 25) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_66_a_product_array_puzzle_s1/sfo_66_a_product_array_puzzle_s1.java
  class Solution (line 13) | class Solution {
    method constructArr (line 14) | public int[] constructArr(int[] a) {
  class sfo_66_a_product_array_puzzle_s1 (line 32) | public class sfo_66_a_product_array_puzzle_s1 {
    method main (line 33) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_67_convert_string_to_int_s1/sfo_67_convert_string_to_int_s1.java
  class Solution (line 13) | class Solution {
    method strToInt (line 14) | public int strToInt(String str) {
  class sfo_67_convert_string_to_int_s1 (line 35) | public class sfo_67_convert_string_to_int_s1 {
    method main (line 36) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_67_convert_string_to_int_s2/sfo_67_convert_string_to_int_s2.java
  class Solution (line 13) | class Solution {
    method strToInt (line 14) | public int strToInt(String str) {
  class sfo_67_convert_string_to_int_s2 (line 37) | public class sfo_67_convert_string_to_int_s2 {
    method main (line 38) | public static void main(String[] args) {

FILE: sword_for_offer/codes/java/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1/sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1.java
  class Solution (line 13) | class Solution {
    method lowestCommonAncestor (line 14) | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNo...
  class sfo_68i_the_nearest_common_ancestor_of_a_binary_search_tree_s1 (li
Condensed preview — 983 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (2,125K chars).
[
  {
    "path": ".gitignore",
    "chars": 37,
    "preview": "__pycache__\n.DS_Store\n.vscode\n*.xlsx\n"
  },
  {
    "path": "LICENSE",
    "chars": 20845,
    "preview": "Attribution-NonCommercial-ShareAlike 4.0 International\n\n================================================================"
  },
  {
    "path": "README.md",
    "chars": 2193,
    "preview": "<p align=\"center\">\n  <a href=\"https://leetcode-cn.com/leetbook/detail/illustration-of-algorithm/\">\n    <img src=\"https:/"
  },
  {
    "path": "leetbook_ioa/docs/# 0 引言.md",
    "chars": 576,
    "preview": "# 引言\r\n\r\n《图解算法数据结构》面向算法初学者、互联网求职者设计,主要内容包括:\r\n\r\n### 精选面试题图文解析\r\n\r\n- 图文详解 75 道题目,覆盖主要算法知识点,非常适合作为算法学习的 **第一份题库**。\r\n- 题库活跃于各大"
  },
  {
    "path": "leetbook_ioa/docs/# 0.1 刷题建议.md",
    "chars": 444,
    "preview": "# 刷题建议\r\n\r\n本书专为算法初学者设计,特别针对有意进入互联网行业的求职者。内容覆盖如下主题:\r\n\r\n- **算法**:搜索、查找、排序、双指针、回溯、分治、动态规划、贪心、位运算、数学等。\r\n- **数据结构**:数组、栈、队列、字符"
  },
  {
    "path": "leetbook_ioa/docs/# 0.2 题目分类.md",
    "chars": 4805,
    "preview": "# 题目分类\n\n题目可能存在多种解法,下表仅列举最优解法(时间与空间复杂度最低)的算法和数据结构分类。\n\n| 题目                             | 算法分类         | 数据结构分类   |\n| ----"
  },
  {
    "path": "leetbook_ioa/docs/# 1.1 数据结构简介.md",
    "chars": 11831,
    "preview": "# 数据结构简介\n\n数据结构是为实现对计算机数据有效使用的各种数据组织形式,服务于各类计算机操作。不同的数据结构具有各自对应的适用场景,旨在降低各种算法计算的时间与空间复杂度,达到最佳的任务执行效率。\n\n如下图所示,常见的数据结构可分为「线"
  },
  {
    "path": "leetbook_ioa/docs/# 1.2 算法复杂度.md",
    "chars": 410,
    "preview": "# 算法复杂度\n\n算法复杂度旨在计算在输入数据量 $N$ 的情况下,算法的「时间使用」和「空间使用」情况;体现算法运行使用的时间和空间随「数据大小 $N$ 」而增大的速度。\n\n算法复杂度主要可从 **时间** 、**空间** 两个角度评价:"
  },
  {
    "path": "leetbook_ioa/docs/# 1.3 时间复杂度.md",
    "chars": 10912,
    "preview": "# 时间复杂度\n\n根据定义,时间复杂度指输入数据大小为 $N$ 时,算法运行所需花费的时间。需要注意:\n\n- 统计的是算法的「计算操作数量」,而不是「运行的绝对时间」。计算操作数量和运行绝对时间呈正相关关系,并不相等。算法运行时间受到「编程"
  },
  {
    "path": "leetbook_ioa/docs/# 1.4 空间复杂度.md",
    "chars": 12423,
    "preview": "# 空间复杂度\r\n\r\n空间复杂度涉及的空间类型有:\r\n\r\n- **输入空间:** 存储输入数据所需的空间大小;\r\n- **暂存空间:** 算法运行过程中,存储所有中间变量和对象等数据所需的空间大小;\r\n- **输出空间:** 算法运行返回时"
  },
  {
    "path": "leetbook_ioa/docs/# 11.1 动态规划解题框架.md",
    "chars": 14980,
    "preview": "# 动态规划解题框架\r\n\r\n动态规划是算法与数据结构的重难点之一,其包含了「分治思想」、「空间换时间」、「最优解」等多种基石算法思想,常作为笔面试中的中等困难题出现。为帮助读者全面理解动态规划,知晓其来龙去脉,本文将从以下几个角度切入介绍:"
  },
  {
    "path": "leetbook_ioa/docs/# 7.1 排序算法简介.md",
    "chars": 4360,
    "preview": "# 排序算法简介\r\n\r\n排序算法用作实现列表的排序,列表元素可以是整数,也可以是浮点数、字符串等其他数据类型。生活中有许多需要排序算法的场景,例如:\r\n\r\n- **整数排序:** 对于一个整数数组,我们希望将所有数字从小到大排序;\r\n- *"
  },
  {
    "path": "leetbook_ioa/docs/# 7.2 冒泡排序.md",
    "chars": 6729,
    "preview": "# 冒泡排序\r\n\r\n冒泡排序是最基础的排序算法,由于其直观性,经常作为首个介绍的排序算法。其原理为:\r\n\r\n- **内循环:** 使用相邻双指针 `j` , `j + 1` 从左至右遍历,依次比较相邻元素大小,若左元素大于右元素则将它们交换"
  },
  {
    "path": "leetbook_ioa/docs/# 7.3 快速排序.md",
    "chars": 7162,
    "preview": "# 快速排序\r\n\r\n快速排序算法有两个核心点,分别为 **哨兵划分** 和 **递归** 。\r\n\r\n**哨兵划分**:以数组某个元素(一般选取首元素)为 **基准数** ,将所有小于基准数的元素移动至其左边,大于基准数的元素移动至其右边。\r"
  },
  {
    "path": "leetbook_ioa/docs/# 7.4 归并排序.md",
    "chars": 4612,
    "preview": "# 归并排序\r\n\r\n归并排序体现了 “分而治之” 的算法思想,具体为:\r\n\r\n- **「分」:** 不断将数组从 **中点位置** 划分开,将原数组的排序问题转化为子数组的排序问题;\r\n- **「治」:** 划分到子数组长度为 1 时,开始"
  },
  {
    "path": "leetbook_ioa/docs/LCR 120. 寻找文件副本.md",
    "chars": 5578,
    "preview": "## 方法一:哈希表\r\n\r\n利用数据结构特点,容易想到使用哈希表(Set)记录数组的各个数字,当查找到重复数字则直接返回。\r\n\r\n### 算法流程:\r\n\r\n1. 初始化: 新建 HashSet ,记为 $hmap$ ;\r\n2. 遍历数组 $"
  },
  {
    "path": "leetbook_ioa/docs/LCR 121. 寻找目标值 - 二维数组.md",
    "chars": 2818,
    "preview": "## 解题思路:\r\n\r\n> 若使用暴力法遍历矩阵 `plants` ,则时间复杂度为 $O(NM)$ 。暴力法未利用矩阵 **“从上到下递增、从左到右递增”** 的特点,显然不是最优解法。\r\n\r\n如下图所示,我们将矩阵逆时针旋转 45° ,"
  },
  {
    "path": "leetbook_ioa/docs/LCR 122. 路径加密.md",
    "chars": 1380,
    "preview": "## 方法一:遍历添加\n\n在 Python 和 Java 等语言中,字符串都被设计成「不可变」的类型,即无法直接修改字符串的某一位字符,需要新建一个字符串实现。\n\n### 算法流程:\n\n1. 初始化一个 `list` (Python) 或 "
  },
  {
    "path": "leetbook_ioa/docs/LCR 123. 图书整理 I.md",
    "chars": 3978,
    "preview": "## 方法一:递归\n\n利用递归,先递推至链表末端;回溯时,依次将节点值加入列表,即可实现链表值的倒序输出。\n\n1. **终止条件:** 当 `head == None` 时,代表越过了链表尾节点,则返回空列表;\n2. **递推工作:** 访"
  },
  {
    "path": "leetbook_ioa/docs/LCR 124. 推理二叉树.md",
    "chars": 4968,
    "preview": "## 解题思路:\r\n\r\n前序遍历性质: 节点按照 `[ 根节点 | 左子树 | 右子树 ]` 排序。\r\n中序遍历性质: 节点按照 `[ 左子树 | 根节点 | 右子树 ]` 排序。\r\n\r\n> 以题目示例为例:\r\n> \r\n> - 前序遍历划分"
  },
  {
    "path": "leetbook_ioa/docs/LCR 125. 图书整理 II.md",
    "chars": 3000,
    "preview": "## 解题思路:\n\n> 我们可将两个书车看作两个“栈”,本题可被转化为“用两个栈实现一个队列”。\n\n栈实现队列的出队操作效率低下:栈底元素(对应队首元素)无法直接删除,需要将上方所有元素出栈。\n\n列表倒序操作可使用双栈实现:设有含三个元素的"
  },
  {
    "path": "leetbook_ioa/docs/LCR 126. 斐波那契数.md",
    "chars": 3397,
    "preview": "## 解题思路:\n\n斐波那契数列的定义是 $f(n + 1) = f(n) + f(n - 1)$ ,生成第 $n$ 项的做法有以下几种:\n\n1. **递归:**\n    - **原理:** 把 $f(n)$ 问题的计算拆分成 $f(n-1"
  },
  {
    "path": "leetbook_ioa/docs/LCR 127. 跳跃训练.md",
    "chars": 3281,
    "preview": "## 解题思路:\n\n设跳上 $n$ 级平台有 $f(n)$ 种跳法。在所有跳法中,青蛙的最后一步只有两种情况: **跳上 $1$ 级或 $2$ 级平台**。\n\n1. **当为 $1$ 级平台:** 剩 $n-1$ 个平台,此情况共有 $f("
  },
  {
    "path": "leetbook_ioa/docs/LCR 128. 库存管理 I.md",
    "chars": 5512,
    "preview": "## 解题思路:\n\n如下图所示,寻找旋转数组的最小元素即为寻找 **右排序数组** 的首个元素 $stock[x]$ ,称 $x$ 为 **旋转点** 。\n\n> 下图中的 `numbers` 对应本题的 `stock` 。\n\n![Pictu"
  },
  {
    "path": "leetbook_ioa/docs/LCR 129. 字母迷宫.md",
    "chars": 5261,
    "preview": "## 解题思路:\n\n本问题是典型的回溯问题,可使用 **深度优先搜索(DFS)+ 剪枝** 解决。\n\n- **深度优先搜索:** 可以理解为暴力法遍历矩阵中所有字符串可能性。DFS 通过递归,先朝一个方向搜到底,再回溯至上个节点,沿另一个方"
  },
  {
    "path": "leetbook_ioa/docs/LCR 130. 衣橱整理.md",
    "chars": 9345,
    "preview": "## 解题思路:\r\n\r\n为提升回溯的计算效率,首先讲述两项前置工作: **数位之和计算** 、 **可达解分析** 。\r\n\r\n### 数位之和计算:\r\n\r\n设一数字 $x$ ,向下取整除法符号 $//$ ,求余符号 $\\odot$ ,则有:"
  },
  {
    "path": "leetbook_ioa/docs/LCR 131. 砍竹子 I.md",
    "chars": 5396,
    "preview": "## 解题思路:\r\n\r\n设将长度为 $n$ 的竹子切为 $a$ 段:\r\n\r\n$$\r\nn = n_1 + n_2 + ... + n_a\r\n$$\r\n\r\n本题等价于求解:\r\n\r\n$$\r\n\\max(n_1 \\times n_2 \\times .."
  },
  {
    "path": "leetbook_ioa/docs/LCR 132. 砍竹子 II.md",
    "chars": 6069,
    "preview": "## 解题思路:\r\n\r\n> 切分规则的推导流程请见上一题「砍竹子 I」。\r\n\r\n### 切分规则:\r\n\r\n1. **最优:** $3$ 。把竹子尽可能切为多个长度为 $3$ 的片段,留下的最后一段竹子的长度可能为 $0,1,2$ 三种情况。"
  },
  {
    "path": "leetbook_ioa/docs/LCR 133. 位 1 的个数.md",
    "chars": 4262,
    "preview": "## 方法一:逐位判断\r\n\r\n根据 **与运算** 定义,设二进制数字 $n$ ,则有:\r\n\r\n- 若 $n \\& 1 = 0$ ,则 $n$ 二进制 **最右一位** 为 $0$ ;\r\n- 若 $n \\& 1 = 1$ ,则 $n$ 二进"
  },
  {
    "path": "leetbook_ioa/docs/LCR 134. Pow(x, n).md",
    "chars": 3355,
    "preview": "## 解题思路:\n\n求 $x^n$ 最简单的方法是通过循环将 $n$ 个 $x$ 乘起来,依次求 $x^1, x^2, ..., x^{n-1}, x^n$ ,时间复杂度为 $O(n)$ 。\n**快速幂法** 可将时间复杂度降低至 $O(\\"
  },
  {
    "path": "leetbook_ioa/docs/LCR 135. 报数.md",
    "chars": 8696,
    "preview": "## 解题思路:\r\n\r\n题目要求打印 “从 $1$ 至 $cnt$ 的数字” ,因此需考虑以下两个问题:\r\n\r\n1. **最大的 $cnt$ 位数(记为 $end$ )和位数 $cnt$ 的关系:** 例如最大的 $1$ 位数是 $9$ ,"
  },
  {
    "path": "leetbook_ioa/docs/LCR 136. 删除链表节点.md",
    "chars": 2224,
    "preview": "## 解题思路:\n\n本题删除值为 `val` 的节点分需为两步:定位节点、修改引用。\n\n1. **定位节点:** 遍历链表,直到 `head.val == val` 时跳出,即可定位目标节点。\n2. **修改引用:** 设节点 `cur` "
  },
  {
    "path": "leetbook_ioa/docs/LCR 137. 模糊搜索验证.md",
    "chars": 8406,
    "preview": "## 解题思路:\r\n\r\n> 设 $s$ 的长度为 $n$ ,$p$ 的长度为 $m$ ;将 $s$ 的第 $i$ 个字符记为 $s_i$ ,$p$ 的第 $j$ 个字符记为 $p_j$ ,将 $s$ 的前 $i$ 个字符组成的子字符串记为 "
  },
  {
    "path": "leetbook_ioa/docs/LCR 138. 有效数字.md",
    "chars": 4636,
    "preview": "## 解题思路:\n\n本题使用有限状态自动机。根据字符类型和合法数值的特点,先定义状态,再画出状态转移图,最后编写代码即可。\n\n**字符类型:**\n\n空格 「   」、数字「 $0—9$ 」 、正负号 「 $+$, $-$ 」 、小数点 「 "
  },
  {
    "path": "leetbook_ioa/docs/LCR 139. 训练计划 I.md",
    "chars": 3580,
    "preview": "## 解题思路:\r\n\r\n考虑定义双指针 $i$ , $j$ 分列数组左右两端,循环执行:\r\n\r\n1. 指针 $i$ 从左向右寻找偶数;\r\n2. 指针 $j$ 从右向左寻找奇数;\r\n3. 将 偶数 $actions[i]$ 和 奇数 $act"
  },
  {
    "path": "leetbook_ioa/docs/LCR 140. 训练计划 II.md",
    "chars": 3543,
    "preview": "## 解题思路:\n\n第一时间想到的解法:\n\n1. 先遍历统计链表长度,记为 $n$ ;\n2. 设置一个指针走 $(n-cnt)$ 步,即可找到链表倒数第 $cnt$ 个节点;\n\n使用双指针则可以不用统计链表长度。\n\n> 下图中的 `k` 对"
  },
  {
    "path": "leetbook_ioa/docs/LCR 141. 训练计划 III.md",
    "chars": 5122,
    "preview": "## 解题思路:\r\n\r\n如下图所示,题目要求将链表反转。本文介绍迭代(双指针)、递归两种实现方法。\r\n\r\n![Picture1.png](https://pic.leetcode-cn.com/1604779288-WXygqL-Pictu"
  },
  {
    "path": "leetbook_ioa/docs/LCR 142. 训练计划 IV.md",
    "chars": 4410,
    "preview": "## 解题思路:\r\n\r\n根据题目描述, 链表 `l1` , `l2` 是 **递增** 的,因此容易想到使用双指针 `l1` 和 `l2` 遍历两链表,根据 `l1.val` 和 `l2.val` 的大小关系确定节点添加顺序,两节点指针交替"
  },
  {
    "path": "leetbook_ioa/docs/LCR 143. 子结构判断.md",
    "chars": 3234,
    "preview": "## 解题思路:\n\n若树 `B` 是树 `A` 的子结构,则子结构的根节点可能为树 `A` 的任意一个节点。因此,判断树 `B` 是否是树 `A` 的子结构,需完成以下两步工作:\n\n1. 先序遍历树 `A` 中的每个节点 `node` ;("
  },
  {
    "path": "leetbook_ioa/docs/LCR 144. 翻转二叉树.md",
    "chars": 7493,
    "preview": "## 解题思路:\r\n\r\n**二叉树镜像定义:** 对于二叉树中任意节点 `root` ,设其左 / 右子节点分别为 `left` , `right` ;则在二叉树的镜像中的对应 `root` 节点,其左 / 右子节点分别为 `right` "
  },
  {
    "path": "leetbook_ioa/docs/LCR 145. 判断对称二叉树.md",
    "chars": 3014,
    "preview": "## 解题思路:\n\n**对称二叉树定义:** 对于树中 **任意两个对称节点** `L` 和 `R `,一定有:\n\n- `L.val = R.val` :即此两对称节点值相等。\n- `L.left.val = R.right.val` :即"
  },
  {
    "path": "leetbook_ioa/docs/LCR 146. 螺旋遍历二维数组.md",
    "chars": 4454,
    "preview": "## 解题思路:\r\n\r\n根据题目示例 `array = [[1,2,3],[4,5,6],[7,8,9]]` 的对应输出 `[1,2,3,6,9,8,7,4,5]` 可以发现,顺时针打印矩阵的顺序是 **“从左向右、从上向下、从右向左、从下"
  },
  {
    "path": "leetbook_ioa/docs/LCR 147. 最小栈.md",
    "chars": 3242,
    "preview": "## 解题思路:\n\n普通栈的 `push()` 和 `pop()` 函数的复杂度为 $O(1)$ ;而获取栈最小值 `getMin()` 函数需要遍历整个栈,复杂度为 $O(N)$ 。\n\n**本题难点:** 将 `getMin()` 函数复"
  },
  {
    "path": "leetbook_ioa/docs/LCR 148. 验证图书取出顺序.md",
    "chars": 3933,
    "preview": "## 解题思路:\r\n\r\n如下图所示,给定一个放入序列 `putIn` 和拿取序列 `takeOut` ,则放入(压栈)和拿取(弹出)操作的顺序是 **唯一确定** 的。\r\n\r\n> 下图中 `pushed` 和 `popped` 分别对应本题"
  },
  {
    "path": "leetbook_ioa/docs/LCR 149. 彩灯装饰记录 I.md",
    "chars": 4446,
    "preview": "## 解题思路:\r\n\r\n题目要求按层打印二叉树,即二叉树的 **广度优先遍历** ,其通常借助 **队列** 的先入先出特性来实现。\r\n\r\n![Picture1.png](https://pic.leetcode-cn.com/a872b5"
  },
  {
    "path": "leetbook_ioa/docs/LCR 150. 彩灯装饰记录 II.md",
    "chars": 4065,
    "preview": "## 解题思路:\r\n\r\n在上一题层序遍历的基础上,本题要求将 **每层打印到一行**。考虑将当前全部节点打印到一行,并将下一层全部节点加入队列,以此类推,即可分为多行打印。\r\n\r\n![Picture1.png](https://pic.le"
  },
  {
    "path": "leetbook_ioa/docs/LCR 151. 彩灯装饰记录 III.md",
    "chars": 11448,
    "preview": "## 方法一:层序遍历 + 双端队列\r\n\r\n利用双端队列的两端皆可添加元素的特性,设打印列表(双端队列) `tmp` ,并规定:\r\n\r\n- 奇数层 则添加至 `tmp` **尾部** 。\r\n- 偶数层 则添加至 `tmp` **头部** 。"
  },
  {
    "path": "leetbook_ioa/docs/LCR 152. 验证二叉搜索树的后序遍历序列.md",
    "chars": 7279,
    "preview": "## 解题思路:\r\n\r\n**后序遍历定义:** `[ 左子树 | 右子树 | 根节点 ]` ,即遍历顺序为 “左、右、根” 。\r\n\r\n**二叉搜索树定义:** 左子树中所有节点的值 $<$ 根节点的值;右子树中所有节点的值 $>$ 根节点的"
  },
  {
    "path": "leetbook_ioa/docs/LCR 153. 二叉树中和为目标值的路径.md",
    "chars": 3805,
    "preview": "## 解题思路:\n\n本题是典型的二叉树方案搜索问题,使用回溯法解决,其包含 **先序遍历 + 路径记录** 两部分。\n\n- **先序遍历:** 按照 “根、左、右” 的顺序,遍历树的所有节点。\n- **路径记录:** 在先序遍历中,记录从根"
  },
  {
    "path": "leetbook_ioa/docs/LCR 154. 随机链表的复制.md",
    "chars": 10503,
    "preview": "## 解题思路:\r\n\r\n普通链表的节点定义如下:\r\n\r\n```Python []\r\n# Definition for a Node.\r\nclass Node:\r\n    def __init__(self, x: int, next: 'N"
  },
  {
    "path": "leetbook_ioa/docs/LCR 155. 将二叉搜索树转化为排序的双向链表.md",
    "chars": 4319,
    "preview": "## 解题思路:\n\n本文解法基于性质:二叉搜索树的中序遍历为 **递增序列** 。\n将 二叉搜索树 转换成一个 “排序的循环双向链表” ,其中包含三个要素:\n\n1. **排序链表:** 节点应从小到大排序,因此应使用 **中序遍历** “从"
  },
  {
    "path": "leetbook_ioa/docs/LCR 156. 序列化与反序列化二叉树.md",
    "chars": 7752,
    "preview": "## 解题思路:\r\n\r\n通常使用的前序、中序、后序、层序遍历记录的二叉树的信息不完整,即唯一的输出序列可能对应着多种二叉树可能性。题目要求的 序列化 和 反序列化 是 **可逆操作** 。因此,序列化的字符串应携带 **完整的二叉树信息**"
  },
  {
    "path": "leetbook_ioa/docs/LCR 157. 套餐内商品的排列顺序.md",
    "chars": 4921,
    "preview": "## 解题思路:\n\n对于一个长度为 $n$ 的字符串(假设字符互不重复),其排列方案数共有:\n\n$$\nn \\times (n-1) \\times (n-2) … \\times 2 \\times 1\n$$\n\n**排列方案的生成:**\n\n根据字"
  },
  {
    "path": "leetbook_ioa/docs/LCR 158. 库存管理 II.md",
    "chars": 4433,
    "preview": "## 解题思路:\n\n> 请注意,数学中众数的定义为 “数组中出现次数最多的数字” ,与本文定义不同。本文将 “数组中出现次数超过一半的数字” 称为 **“众数”**。\n\n本题常见的三种解法:\n\n1. **哈希表统计法:** 遍历数组 `st"
  },
  {
    "path": "leetbook_ioa/docs/LCR 159. 库存管理 III.md",
    "chars": 7783,
    "preview": "## 方法一:快速排序\r\n\r\n本题使用排序算法解决最直观,对数组 `stock` 执行排序,再返回前 $cnt$ 个元素即可。使用任意排序算法皆可,本文采用并介绍 **快速排序** ,为下文 **方法二** 做铺垫。\r\n\r\n### 快速排序"
  },
  {
    "path": "leetbook_ioa/docs/LCR 160. 数据流中的中位数.md",
    "chars": 5640,
    "preview": "## 解题思路:\r\n\r\n> 给定一长度为 $N$ 的无序数组,其中位数的计算方法:首先对数组执行排序(使用 $O(N \\log N)$ 时间),然后返回中间元素即可(使用 $O(1)$ 时间)。\r\n\r\n针对本题,根据以上思路,可以将数据流保"
  },
  {
    "path": "leetbook_ioa/docs/LCR 161. 连续天数的最高销售额.md",
    "chars": 3163,
    "preview": "## 解题思路:\r\n\r\n观察不同解法的复杂度,可知动态规划是本题的最优解法。\r\n\r\n| 常见解法 | 时间复杂度    | 空间复杂度  |\r\n| -------- | ------------- | ----------- |\r\n| 暴力"
  },
  {
    "path": "leetbook_ioa/docs/LCR 162. 数字 1 的个数.md",
    "chars": 4464,
    "preview": "## 解题思路:\n\n> 为简化篇幅,本文将 $num$ 记为 $n$ 。\n\n将 $1$ ~ $n$ 的个位、十位、百位、...的 $1$ 出现次数相加,即为 $1$ 出现的总次数。\n\n设数字 $n$ 是个 $x$ 位数,记 $n$ 的第 $"
  },
  {
    "path": "leetbook_ioa/docs/LCR 163. 找到第 k 位数字.md",
    "chars": 4213,
    "preview": "## 解题思路:\n\n文名词规定如下:\n\n1. 将 $101112 \\cdots$ 中的每一位称为 **数位** ,记为 $k$ ;\n2. 将 $10, 11, 12, \\cdots$  称为 **数字** ,记为 $num$ ;\n3. 数字"
  },
  {
    "path": "leetbook_ioa/docs/LCR 164. 破解闯关密码.md",
    "chars": 5329,
    "preview": "## 解题思路:\r\n\r\n此题求拼接起来的最小数字,本质上是一个排序问题。设数组 $password$ 中任意两数字的字符串为 $x$ 和 $y$ ,则规定 **排序判断规则** 为:\r\n\r\n- 若拼接字符串 $x + y > y + x$ "
  },
  {
    "path": "leetbook_ioa/docs/LCR 165. 解密数字.md",
    "chars": 7035,
    "preview": "## 解题思路:\n\n根据题意,可按照下图的思路,总结出 “递推公式” (即转移方程)。\n\n> 下图中的 `num` 对应本题的 `ciphertext` 。\n\n![Picture1.png](https://pic.leetcode-cn."
  },
  {
    "path": "leetbook_ioa/docs/LCR 166. 珠宝的最高价值.md",
    "chars": 5916,
    "preview": "## 解题思路:\r\n\r\n题目说明:从棋盘的左上角开始拿格子里的珠宝,并每次 **向右** 或者 **向下** 移动一格、直到到达棋盘的右下角。\r\n根据题目说明,易得某单元格只可能从上边单元格或左边单元格到达。\r\n\r\n设 $f(i, j)$ "
  },
  {
    "path": "leetbook_ioa/docs/LCR 167. 招式拆解 I.md",
    "chars": 6264,
    "preview": "## 解题思路:\n\n长度为 $N$ 的字符串共有 $\\frac{(1 + N)N}{2}$ 个子字符串(复杂度为 $O(N^2)$ ),判断长度为 $N$ 的字符串是否有重复字符的复杂度为 $O(N)$ ,因此本题使用暴力法解决的复杂度为 "
  },
  {
    "path": "leetbook_ioa/docs/LCR 168. 丑数.md",
    "chars": 2940,
    "preview": "## 解题思路:\r\n\r\n根据题意,每个丑数都可以由其他较小的丑数通过乘以 $2$ 或 $3$ 或 $5$ 得到。\r\n\r\n所以,可以考虑使用一个优先队列保存所有的丑数,每次取出最小的那个,然后乘以 $2$ , $3$ , $5$ 后放回队列。"
  },
  {
    "path": "leetbook_ioa/docs/LCR 169. 招式拆解 II.md",
    "chars": 5295,
    "preview": "## 解题思路:\r\n\r\n本题考察 **哈希表** 的使用,本文介绍 **哈希表** 和 **有序哈希表** 两种解法。其中,在字符串长度较大、重复字符很多时,“有序哈希表” 解法理论上效率更高。\r\n\r\n## 方法一:哈希表\r\n\r\n1. 遍历"
  },
  {
    "path": "leetbook_ioa/docs/LCR 170. 交易逆序对的总数.md",
    "chars": 5929,
    "preview": "## 解题思路:\r\n\r\n直观来看,使用暴力统计法即可,即遍历数组的所有数字对并统计逆序对数量。此方法时间复杂度为 $O(N^2)$ ,观察题目给定的数组长度范围 $0 \\leq N \\leq 50000$ ,可知此复杂度是不能接受的。\r\n\r"
  },
  {
    "path": "leetbook_ioa/docs/LCR 171. 训练计划 V.md",
    "chars": 2482,
    "preview": "## 解题思路:\r\n\r\n设第一个公共节点为 `node` ,链表 `headA` 的节点数量为 $a$ ,链表 `headB` 的节点数量为 $b$ ,两链表的公共尾部的节点数量为 $c$ ,则有:\r\n\r\n- 头节点 `headA` 到 `"
  },
  {
    "path": "leetbook_ioa/docs/LCR 172. 统计目标成绩的出现次数.md",
    "chars": 5282,
    "preview": "## 解题思路:\n\n> 排序数组中的搜索问题,首先想到 **二分法** 解决。\n\n排序数组 $scores$ 中的所有数字 $target$ 形成一个窗口,记窗口的 **左 / 右边界** 索引分别为 $left$ 和 $right$ ,分"
  },
  {
    "path": "leetbook_ioa/docs/LCR 173. 点名.md",
    "chars": 2143,
    "preview": "## 解题思路:\n\n排序数组中的搜索问题,首先想到 **二分法** 解决。根据题意,数组可以按照以下规则划分为两部分。\n\n- **左子数组:** $records[i] = i$ ;\n- **右子数组:** $records[i] \\ne "
  },
  {
    "path": "leetbook_ioa/docs/LCR 174. 寻找二叉搜索树中的目标节点.md",
    "chars": 3600,
    "preview": "## 解题思路:\n\n本文解法基于性质:二叉搜索树的中序遍历为递增序列。根据此性质,易得二叉搜索树的 **中序遍历倒序** 为 **递减序列** 。\n\n因此,我们可将求 “二叉搜索树第 $cnt$ 大的节点” 可转化为求 “此树的中序遍历倒序"
  },
  {
    "path": "leetbook_ioa/docs/LCR 175. 计算二叉树的深度.md",
    "chars": 4879,
    "preview": "## 解题思路:\r\n\r\n树的遍历方式总体分为两类:\r\n\r\n- **深度优先搜索(DFS):** 先序遍历、中序遍历、后序遍历;\r\n- **广度优先搜索(BFS):** 层序遍历;\r\n\r\n求树的深度需要遍历树的所有节点,本文将介绍基于 **后"
  },
  {
    "path": "leetbook_ioa/docs/LCR 176. 判断是否为平衡二叉树.md",
    "chars": 6312,
    "preview": "## 解题思路:\r\n\r\n以下两种方法均基于以下性质推出: **此树的深度** 等于 **左子树的深度** 与 **右子树的深度** 中的 **最大值** $+1$ 。\r\n\r\n![Picture1.png](https://pic.leetc"
  },
  {
    "path": "leetbook_ioa/docs/LCR 177. 撞色搭配.md",
    "chars": 5298,
    "preview": "## 解题思路:\r\n\r\n题目要求时间复杂度 $O(N)$ ,空间复杂度 $O(1)$ ,因此首先排除 **暴力法** 和 **哈希表统计法** 。\r\n\r\n> **简化问题:** 一个整型数组 `sockets` 里除 **一个** 数字之外"
  },
  {
    "path": "leetbook_ioa/docs/LCR 178. 训练计划 VI.md",
    "chars": 7217,
    "preview": "## 解题思路:\r\n\r\n如下图所示,考虑数字的二进制形式,对于出现三次的数字,各 **二进制位** 出现的次数都是 $3$ 的倍数。\r\n因此,统计所有数字的各二进制位中 $1$ 的出现次数,并对 $3$ 求余,结果则为只出现一次的数字。\r\n"
  },
  {
    "path": "leetbook_ioa/docs/LCR 179. 查找总价格为目标值的两个商品.md",
    "chars": 2500,
    "preview": "## 解题思路:\n\n利用 HashMap 可以通过遍历数组找到数字组合,时间和空间复杂度均为 $O(N)$ 。\n注意本题的 $price$ 是 **排序数组** ,因此可使用 **双指针法** 将空间优化至 $O(1)$ 。\n\n### 算法"
  },
  {
    "path": "leetbook_ioa/docs/LCR 180. 文件组合.md",
    "chars": 5268,
    "preview": "## 方法一:求和公式\n\n设连续正整数序列的左边界 $i$ 和右边界 $j$ ,则此序列的 **元素和** $target$ 等于 **元素平均值 $\\frac{i + j}{2}$** 乘以 **元素数量 $(j - i + 1)$** "
  },
  {
    "path": "leetbook_ioa/docs/LCR 181. 字符串中的单词反转.md",
    "chars": 5176,
    "preview": "## 方法一:双指针\n\n### 算法解析:\n\n- 倒序遍历字符串 $message$ ,记录单词左右索引边界 $i$ , $j$ ;\n- 每确定一个单词的边界,则将其添加至单词列表 $res$ ;\n- 最终,将单词列表拼接为字符串,并返回即"
  },
  {
    "path": "leetbook_ioa/docs/LCR 182. 动态口令.md",
    "chars": 6791,
    "preview": "## 解题思路:\n\n本题解法较多,本文主要介绍 **字符串切片** , **列表遍历拼接** , **字符串遍历拼接** 三种方法,适用于 Python 和 Java 语言。同时,介绍了 **三次翻转法** ,适用于 C++ 语言。\n\n##"
  },
  {
    "path": "leetbook_ioa/docs/LCR 183. 望远镜中最高的海拔.md",
    "chars": 5618,
    "preview": "## 解题思路:\n\n设窗口区间为 $[i, j]$ ,最大值为 $x_j$ 。当窗口向前移动一格,则区间变为 $[i+1,j+1]$ ,即添加了 $heights[j + 1]$ ,删除了 $heights[i]$ 。\n\n若只向窗口 $[i"
  },
  {
    "path": "leetbook_ioa/docs/LCR 184. 设计自助结算系统.md",
    "chars": 4230,
    "preview": "## 解题思路:\r\n\r\n> 对于普通队列,入队 `add()` 和出队 `remove()` 的时间复杂度均为 $O(1)$ ;本题难点为实现查找最大值 `get_max()` 的 $O(1)$ 时间复杂度。\r\n> 假设队列中存储 $N$ "
  },
  {
    "path": "leetbook_ioa/docs/LCR 185. 统计结果概率.md",
    "chars": 4346,
    "preview": "## 方法一:暴力法\n\n> 此方法超时,但为便于理解「方法二」,建议先理解此方法。\n>\n> 为简化篇幅,本文使用 $n$ 代替题目中的 $num$ 。\n\n给定 $n$ 个骰子,可得:\n\n- 每个骰子摇到 $1$ 至 $6$ 的概率相等,都为"
  },
  {
    "path": "leetbook_ioa/docs/LCR 186. 文物朝代判断.md",
    "chars": 4763,
    "preview": "## 解题思路:\n\n根据题意,此 $5$ 个朝代连续的 **充分条件** 如下:\n\n1. 除未知朝代外,所有朝代 **无重复**  ;\n2. 设此 $5$ 个朝代中最大的朝代为 $ma$ ,最小的朝代为 $mi$ (未知朝代除外),则需满足"
  },
  {
    "path": "leetbook_ioa/docs/LCR 187. 破冰游戏.md",
    "chars": 2810,
    "preview": "## 解题思路:\n\n> 为简化篇幅,本文将 $num$ 和 $target$ 分别记为 $n$ 和 $m$ 。\n\n模拟整个删除过程最直观,即构建一个长度为 $n$ 的链表,各节点值为对应的顺序索引;每轮删除第 $m$ 个节点,直至链表长度为"
  },
  {
    "path": "leetbook_ioa/docs/LCR 188. 买卖芯片的最佳时机.md",
    "chars": 2715,
    "preview": "## 解题思路:\r\n\r\n设共有 $n$ 天,第 $a$ 天买,第 $b$ 天卖,则需保证 $a < b$ ;可推出交易方案数共有:\r\n\r\n$$\r\n(n - 1) + (n - 2) + \\cdots + 2 + 1 = n(n - 1) /"
  },
  {
    "path": "leetbook_ioa/docs/LCR 189. 设计机械累加器.md",
    "chars": 4074,
    "preview": "## 解题思路:\r\n\r\n本题在简单问题上做了许多限制,需要使用排除法一步步导向答案。\r\n$1+2+...+(target-1)+target$ 的计算方法主要有三种:平均计算、迭代、递归。\r\n\r\n**方法一:** 平均计算\r\n**问题:**"
  },
  {
    "path": "leetbook_ioa/docs/LCR 190. 加密运算.md",
    "chars": 3667,
    "preview": "## 解题思路:\r\n\r\n本题考察对位运算的灵活使用,即使用位运算实现加法。\r\n\r\n设两数字的二进制形式 $dataA, dataB$ ,其求和 $s = dataA + dataB$ ,$dataA(i)$ 代表 $dataA$ 的二进制第"
  },
  {
    "path": "leetbook_ioa/docs/LCR 191. 按规则计算统计结果.md",
    "chars": 2753,
    "preview": "## 解题思路:\n\n> 本文将 `arrayA` , `arrayB` 简写为 `A` , `B` 。\n\n本题的难点在于 **不能使用除法** ,即需要 **只用乘法** 生成数组 $B$ 。根据题目对 $B[i]$ 的定义,可列如下图所示"
  },
  {
    "path": "leetbook_ioa/docs/LCR 192. 把字符串转换成整数 (atoi).md",
    "chars": 5088,
    "preview": "## 解题思路:\n\n根据题意,有以下四种字符需要考虑:\n\n1. **首部空格:** 删除之即可;\n2. **符号位:** 三种情况,即 ''$+$'' , ''$-$'' , ''无符号\"  ;新建一个变量保存符号位,返回前判断正负即可;\n"
  },
  {
    "path": "leetbook_ioa/docs/LCR 193. 求二叉搜索树的最近公共祖先.md",
    "chars": 6023,
    "preview": "## 解题思路:\n\n**祖先的定义:** 若节点 `p` 在节点 `root` 的左(右)子树中,或 `p = root`,则称 `root` 是 `p` 的祖先。\n\n**最近公共祖先的定义:** 设节点 `root` 为节点 `p` , "
  },
  {
    "path": "leetbook_ioa/docs/LCR 194. 寻找二叉树的最近公共祖先.md",
    "chars": 5845,
    "preview": "## 解题思路:\n\n**祖先的定义:** 若节点 `p` 在节点 `root` 的左(右)子树中,或 `p = root` ,则称 `root` 是 `p` 的祖先。\n\n**最近公共祖先的定义:** 设节点 `root` 为节点 `p` ,"
  },
  {
    "path": "selected_coding_interview/codes/cpp/include/ListNode.hpp",
    "chars": 1166,
    "preview": "/*\n * File: ListNode.hpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#pragma once\n\n#include <iostream>\n#include "
  },
  {
    "path": "selected_coding_interview/codes/cpp/include/PrintUtil.hpp",
    "chars": 4104,
    "preview": "/*\n * File: PrintUtil.hpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#pragma once\n\n#include \"ListNode.hpp\"\n#inc"
  },
  {
    "path": "selected_coding_interview/codes/cpp/include/TreeNode.hpp",
    "chars": 1543,
    "preview": "/*\n * File: TreeNode.hpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#pragma once\n\n#include <climits>\n#include <"
  },
  {
    "path": "selected_coding_interview/codes/cpp/include/include.hpp",
    "chars": 431,
    "preview": "/*\n * File: include.hpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#pragma once\n\n#include <algorithm>\n#include "
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_101_symmetric_tree/lc_101_symmetric_tree_s1.cpp",
    "chars": 831,
    "preview": "/*\n * File: lc_101_symmetric_tree_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_102_binary_tree_level_order_traversal/lc_102_binary_tree_level_order_traversal_s1.cpp",
    "chars": 1092,
    "preview": "/*\n * File: lc_102_binary_tree_level_order_traversal_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s1.cpp",
    "chars": 1658,
    "preview": "/*\n * File: lc_103_binary_tree_zigzag_level_order_traversal_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s2.cpp",
    "chars": 1098,
    "preview": "/*\n * File: lc_103_binary_tree_zigzag_level_order_traversal_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_104_maximum_depth_of_binary_tree/lc_104_maximum_depth_of_binary_tree_s1.cpp",
    "chars": 614,
    "preview": "/*\n * File: lc_104_maximum_depth_of_binary_tree_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_104_maximum_depth_of_binary_tree/lc_104_maximum_depth_of_binary_tree_s2.cpp",
    "chars": 960,
    "preview": "/*\n * File: lc_104_maximum_depth_of_binary_tree_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_105_construct_binary_tree_from_preorder_and_inorder_traversal/lc_105_construct_binary_tree_from_preorder_and_inorder_traversal_s1.cpp",
    "chars": 1270,
    "preview": "/*\n * File: lc_105_construct_binary_tree_from_preorder_and_inorder_traversal_s1.cpp\n * Created Time: 2025-12-30\n * Autho"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_10_regular_expression_matching/lc_10_regular_expression_matching_s1.cpp",
    "chars": 1048,
    "preview": "/*\n * File: lc_10_regular_expression_matching_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../in"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_10_regular_expression_matching/lc_10_regular_expression_matching_s2.cpp",
    "chars": 1390,
    "preview": "/*\n * File: lc_10_regular_expression_matching_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../in"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_110_balanced_binary_tree/lc_110_balanced_binary_tree_s1.cpp",
    "chars": 860,
    "preview": "/*\n * File: lc_110_balanced_binary_tree_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_110_balanced_binary_tree/lc_110_balanced_binary_tree_s2.cpp",
    "chars": 834,
    "preview": "/*\n * File: lc_110_balanced_binary_tree_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_113_path_sum_ii/lc_113_path_sum_ii_s1.cpp",
    "chars": 928,
    "preview": "/*\n * File: lc_113_path_sum_ii_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.h"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_11_container_with_most_water/lc_11_container_with_most_water_s1.cpp",
    "chars": 708,
    "preview": "/*\n * File: lc_11_container_with_most_water_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../incl"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_121_best_time_to_buy_and_sell_stock/lc_121_best_time_to_buy_and_sell_stock_s1.cpp",
    "chars": 684,
    "preview": "/*\n * File: lc_121_best_time_to_buy_and_sell_stock_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \""
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_136_single_number/lc_136_single_number_s1.cpp",
    "chars": 603,
    "preview": "/*\n * File: lc_136_single_number_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s1.cpp",
    "chars": 540,
    "preview": "/*\n * File: lc_138_copy_list_with_random_pointer_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \".."
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s2.cpp",
    "chars": 581,
    "preview": "/*\n * File: lc_138_copy_list_with_random_pointer_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \".."
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s3.cpp",
    "chars": 914,
    "preview": "/*\n * File: lc_138_copy_list_with_random_pointer_s3.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \".."
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s4.cpp",
    "chars": 1010,
    "preview": "/*\n * File: lc_138_copy_list_with_random_pointer_s4.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \".."
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_138_copy_list_with_random_pointer/lc_138_copy_list_with_random_pointer_s5.cpp",
    "chars": 1325,
    "preview": "/*\n * File: lc_138_copy_list_with_random_pointer_s5.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \".."
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_1480_running_sum_of_1d_array/lc_1480_running_sum_of_1d_array_s1.cpp",
    "chars": 678,
    "preview": "/*\n * File: lc_1480_running_sum_of_1d_array_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../incl"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_154_find_minimum_in_rotated_sorted_array_ii/lc_154_find_minimum_in_rotated_sorted_array_ii_s1.cpp",
    "chars": 720,
    "preview": "/*\n * File: lc_154_find_minimum_in_rotated_sorted_array_ii_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_154_find_minimum_in_rotated_sorted_array_ii/lc_154_find_minimum_in_rotated_sorted_array_ii_s2.cpp",
    "chars": 906,
    "preview": "/*\n * File: lc_154_find_minimum_in_rotated_sorted_array_ii_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_160_intersection_of_two_linked_lists/lc_160_intersection_of_two_linked_lists_s1.cpp",
    "chars": 690,
    "preview": "/*\n * File: lc_160_intersection_of_two_linked_lists_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include "
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_167_two_sum_ii_input_array_is_sorted/lc_167_two_sum_ii_input_array_is_sorted_s1.cpp",
    "chars": 803,
    "preview": "/*\n * File: lc_167_two_sum_ii_input_array_is_sorted_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include "
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_169_majority_element/lc_169_majority_element_s1.cpp",
    "chars": 638,
    "preview": "/*\n * File: lc_169_majority_element_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/incl"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_169_majority_element/lc_169_majority_element_s2.cpp",
    "chars": 778,
    "preview": "/*\n * File: lc_169_majority_element_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/incl"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_179_largest_number/lc_179_largest_number_s1.cpp",
    "chars": 843,
    "preview": "/*\n * File: lc_179_largest_number_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_179_largest_number/lc_179_largest_number_s2.cpp",
    "chars": 1259,
    "preview": "/*\n * File: lc_179_largest_number_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_1823_find_the_winner_of_the_circular_game/lc_1823_find_the_winner_of_the_circular_game_s1.cpp",
    "chars": 592,
    "preview": "/*\n * File: lc_1823_find_the_winner_of_the_circular_game_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#inc"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_191_number_of_1_bits/lc_191_number_of_1_bits_s1.cpp",
    "chars": 624,
    "preview": "/*\n * File: lc_191_number_of_1_bits_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/incl"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_191_number_of_1_bits/lc_191_number_of_1_bits_s2.cpp",
    "chars": 597,
    "preview": "/*\n * File: lc_191_number_of_1_bits_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/incl"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_205_isomorphic_strings/lc_205_isomorphic_strings_s1.cpp",
    "chars": 969,
    "preview": "/*\n * File: lc_205_isomorphic_strings_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/in"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_206_reverse_linked_list/lc_206_reverse_linked_list_s1.cpp",
    "chars": 840,
    "preview": "/*\n * File: lc_206_reverse_linked_list_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_206_reverse_linked_list/lc_206_reverse_linked_list_s2.cpp",
    "chars": 870,
    "preview": "/*\n * File: lc_206_reverse_linked_list_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_215_kth_largest_element_in_an_array/lc_215_kth_largest_element_in_an_array_s1.cpp",
    "chars": 1052,
    "preview": "/*\n * File: lc_215_kth_largest_element_in_an_array_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \""
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_215_kth_largest_element_in_an_array/lc_215_kth_largest_element_in_an_array_s2.cpp",
    "chars": 1057,
    "preview": "/*\n * File: lc_215_kth_largest_element_in_an_array_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \""
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_21_merge_two_sorted_lists/lc_21_merge_two_sorted_lists_s1.cpp",
    "chars": 1071,
    "preview": "/*\n * File: lc_21_merge_two_sorted_lists_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_226_invert_binary_tree/lc_226_invert_binary_tree_s1.cpp",
    "chars": 691,
    "preview": "/*\n * File: lc_226_invert_binary_tree_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/in"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_226_invert_binary_tree/lc_226_invert_binary_tree_s2.cpp",
    "chars": 983,
    "preview": "/*\n * File: lc_226_invert_binary_tree_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/in"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_230_kth_smallest_element_in_a_bst/lc_230_kth_smallest_element_in_a_bst_s1.cpp",
    "chars": 801,
    "preview": "/*\n * File: lc_230_kth_smallest_element_in_a_bst_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \".."
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_232_implement_queue_using_stacks/lc_232_implement_queue_using_stacks_s1.cpp",
    "chars": 901,
    "preview": "/*\n * File: lc_232_implement_queue_using_stacks_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_233_number_of_digit_one/lc_233_number_of_digit_one_s1.cpp",
    "chars": 454,
    "preview": "/*\n * File: lc_233_number_of_digit_one_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_233_number_of_digit_one/lc_233_number_of_digit_one_s2.cpp",
    "chars": 626,
    "preview": "/*\n * File: lc_233_number_of_digit_one_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_233_number_of_digit_one/lc_233_number_of_digit_one_s3.cpp",
    "chars": 864,
    "preview": "/*\n * File: lc_233_number_of_digit_one_s3.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_235_lowest_common_ancestor_of_a_binary_search_tree/lc_235_lowest_common_ancestor_of_a_binary_search_tree_s1.cpp",
    "chars": 868,
    "preview": "/*\n * File: lc_235_lowest_common_ancestor_of_a_binary_search_tree_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_235_lowest_common_ancestor_of_a_binary_search_tree/lc_235_lowest_common_ancestor_of_a_binary_search_tree_s2.cpp",
    "chars": 877,
    "preview": "/*\n * File: lc_235_lowest_common_ancestor_of_a_binary_search_tree_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_235_lowest_common_ancestor_of_a_binary_search_tree/lc_235_lowest_common_ancestor_of_a_binary_search_tree_s3.cpp",
    "chars": 771,
    "preview": "/*\n * File: lc_235_lowest_common_ancestor_of_a_binary_search_tree_s3.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_236_lowest_common_ancestor_of_a_binary_tree/lc_236_lowest_common_ancestor_of_a_binary_tree_s1.cpp",
    "chars": 820,
    "preview": "/*\n * File: lc_236_lowest_common_ancestor_of_a_binary_tree_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_236_lowest_common_ancestor_of_a_binary_tree/lc_236_lowest_common_ancestor_of_a_binary_tree_s2.cpp",
    "chars": 943,
    "preview": "/*\n * File: lc_236_lowest_common_ancestor_of_a_binary_tree_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_237_delete_node_in_a_linked_list/lc_237_delete_node_in_a_linked_list_s1.cpp",
    "chars": 616,
    "preview": "/*\n * File: lc_237_delete_node_in_a_linked_list_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_237_delete_node_in_a_linked_list/lc_237_delete_node_in_a_linked_list_s2.cpp",
    "chars": 675,
    "preview": "/*\n * File: lc_237_delete_node_in_a_linked_list_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_238_product_of_array_except_self/lc_238_product_of_array_except_self_s1.cpp",
    "chars": 885,
    "preview": "/*\n * File: lc_238_product_of_array_except_self_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_239_sliding_window_maximum/lc_239_sliding_window_maximum_s1.cpp",
    "chars": 1075,
    "preview": "/*\n * File: lc_239_sliding_window_maximum_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_239_sliding_window_maximum/lc_239_sliding_window_maximum_s2.cpp",
    "chars": 1181,
    "preview": "/*\n * File: lc_239_sliding_window_maximum_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_240_search_a_2d_matrix_ii/lc_240_search_a_2d_matrix_ii_s1.cpp",
    "chars": 900,
    "preview": "/*\n * File: lc_240_search_a_2d_matrix_ii_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_242_valid_anagram/lc_242_valid_anagram_s1.cpp",
    "chars": 838,
    "preview": "/*\n * File: lc_242_valid_anagram_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_242_valid_anagram/lc_242_valid_anagram_s2.cpp",
    "chars": 1048,
    "preview": "/*\n * File: lc_242_valid_anagram_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_264_ugly_number_ii/lc_264_ugly_number_ii_s1.cpp",
    "chars": 805,
    "preview": "/*\n * File: lc_264_ugly_number_ii_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_266_palindrome_permutation/lc_266_palindrome_permutation_s1.cpp",
    "chars": 761,
    "preview": "/*\n * File: lc_266_palindrome_permutation_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_266_palindrome_permutation/lc_266_palindrome_permutation_s2.cpp",
    "chars": 968,
    "preview": "/*\n * File: lc_266_palindrome_permutation_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_278_first_bad_version/lc_278_first_bad_version_s1.cpp",
    "chars": 854,
    "preview": "/*\n * File: lc_278_first_bad_version_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/inc"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_287_find_the_duplicate_number/lc_287_find_the_duplicate_number_s1.cpp",
    "chars": 629,
    "preview": "/*\n * File: lc_287_find_the_duplicate_number_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../inc"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_287_find_the_duplicate_number/lc_287_find_the_duplicate_number_s2.cpp",
    "chars": 753,
    "preview": "/*\n * File: lc_287_find_the_duplicate_number_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../inc"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_287_find_the_duplicate_number/lc_287_find_the_duplicate_number_s3.cpp",
    "chars": 938,
    "preview": "/*\n * File: lc_287_find_the_duplicate_number_s3.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../inc"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_295_find_median_from_data_stream/lc_295_find_median_from_data_stream_s1.cpp",
    "chars": 935,
    "preview": "/*\n * File: lc_295_find_median_from_data_stream_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_371_sum_of_two_integers/lc_371_sum_of_two_integers_s1.cpp",
    "chars": 641,
    "preview": "/*\n * File: lc_371_sum_of_two_integers_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/i"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_387_first_unique_character_in_a_string/lc_387_first_unique_character_in_a_string_s1.cpp",
    "chars": 675,
    "preview": "/*\n * File: lc_387_first_unique_character_in_a_string_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_392_is_subsequence/lc_392_is_subsequence_s1.cpp",
    "chars": 737,
    "preview": "/*\n * File: lc_392_is_subsequence_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_3_longest_substring_without_repeating_characters/lc_3_longest_substring_without_repeating_characters_s1.cpp",
    "chars": 837,
    "preview": "/*\n * File: lc_3_longest_substring_without_repeating_characters_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n *"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_3_longest_substring_without_repeating_characters/lc_3_longest_substring_without_repeating_characters_s2.cpp",
    "chars": 930,
    "preview": "/*\n * File: lc_3_longest_substring_without_repeating_characters_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n *"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_400_nth_digit/lc_400_nth_digit_s1.cpp",
    "chars": 583,
    "preview": "/*\n * File: lc_400_nth_digit_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.hpp"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_400_nth_digit/lc_400_nth_digit_s2.cpp",
    "chars": 409,
    "preview": "/*\n * File: lc_400_nth_digit_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.hpp"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_400_nth_digit/lc_400_nth_digit_s3.cpp",
    "chars": 493,
    "preview": "/*\n * File: lc_400_nth_digit_s3.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.hpp"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_400_nth_digit/lc_400_nth_digit_s4.cpp",
    "chars": 774,
    "preview": "/*\n * File: lc_400_nth_digit_s4.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.hpp"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_409_longest_palindrome/lc_409_longest_palindrome_s1.cpp",
    "chars": 902,
    "preview": "/*\n * File: lc_409_longest_palindrome_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/in"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.cpp",
    "chars": 576,
    "preview": "/*\n * File: lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s1.cpp\n * Created Time: 2025-12-30\n * Author:"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list/lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.cpp",
    "chars": 896,
    "preview": "/*\n * File: lc_426_convert_binary_search_tree_to_sorted_doubly_linked_list_s2.cpp\n * Created Time: 2025-12-30\n * Author:"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_46_permutations/lc_46_permutations_s1.cpp",
    "chars": 962,
    "preview": "/*\n * File: lc_46_permutations_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.h"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_47_permutations_ii/lc_47_permutations_ii_s1.cpp",
    "chars": 1083,
    "preview": "/*\n * File: lc_47_permutations_ii_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_48_rotate_image/lc_48_rotate_image_s1.cpp",
    "chars": 800,
    "preview": "/*\n * File: lc_48_rotate_image_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.h"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_48_rotate_image/lc_48_rotate_image_s2.cpp",
    "chars": 928,
    "preview": "/*\n * File: lc_48_rotate_image_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.h"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_48_rotate_image/lc_48_rotate_image_s3.cpp",
    "chars": 1109,
    "preview": "/*\n * File: lc_48_rotate_image_s3.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.h"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_509_fibonacci_number/lc_509_fibonacci_number_s1.cpp",
    "chars": 575,
    "preview": "/*\n * File: lc_509_fibonacci_number_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/incl"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_53_maximum_subarray/lc_53_maximum_subarray_s1.cpp",
    "chars": 695,
    "preview": "/*\n * File: lc_53_maximum_subarray_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/inclu"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_54_spiral_matrix/lc_54_spiral_matrix_s1.cpp",
    "chars": 1199,
    "preview": "/*\n * File: lc_54_spiral_matrix_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include."
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_65_valid_number/lc_65_valid_number_s1.cpp",
    "chars": 1869,
    "preview": "/*\n * File: lc_65_valid_number_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.h"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_6_zigzag_conversion/lc_6_zigzag_conversion_s1.cpp",
    "chars": 843,
    "preview": "/*\n * File: lc_6_zigzag_conversion_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/inclu"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_704_binary_search/lc_704_binary_search_s1.cpp",
    "chars": 752,
    "preview": "/*\n * File: lc_704_binary_search_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_70_climbing_stairs/lc_70_climbing_stairs_s1.cpp",
    "chars": 593,
    "preview": "/*\n * File: lc_70_climbing_stairs_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/includ"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_724_find_pivot_index/lc_724_find_pivot_index_s1.cpp",
    "chars": 792,
    "preview": "/*\n * File: lc_724_find_pivot_index_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/incl"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_796_rotate_string/lc_796_rotate_string_s1.cpp",
    "chars": 575,
    "preview": "/*\n * File: lc_796_rotate_string_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_79_word_search/lc_79_word_search_s1.cpp",
    "chars": 1357,
    "preview": "/*\n * File: lc_79_word_search_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include.hp"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_86_partition_list/lc_86_partition_list_s1.cpp",
    "chars": 1030,
    "preview": "/*\n * File: lc_86_partition_list_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_86_partition_list/lc_86_partition_list_s2.cpp",
    "chars": 1152,
    "preview": "/*\n * File: lc_86_partition_list_s2.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/include"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_876_middle_of_the_linked_list/lc_876_middle_of_the_linked_list_s1.cpp",
    "chars": 720,
    "preview": "/*\n * File: lc_876_middle_of_the_linked_list_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../inc"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_8_string_to_integer_atoi/lc_8_string_to_integer_atoi_s1.cpp",
    "chars": 998,
    "preview": "/*\n * File: lc_8_string_to_integer_atoi_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../include/"
  },
  {
    "path": "selected_coding_interview/codes/cpp/lc_946_validate_stack_sequences/lc_946_validate_stack_sequences_s1.cpp",
    "chars": 783,
    "preview": "/*\n * File: lc_946_validate_stack_sequences_s1.cpp\n * Created Time: 2025-12-30\n * Author: krahets\n */\n\n#include \"../incl"
  },
  {
    "path": "selected_coding_interview/codes/java/include/ListNode.java",
    "chars": 909,
    "preview": "package include;\n\nimport java.util.List;\n\n/**\n * Definition for a singly-linked list node\n */\npublic class ListNode {\n  "
  },
  {
    "path": "selected_coding_interview/codes/java/include/PrintUtil.java",
    "chars": 1874,
    "preview": "package include;\n\nimport java.util.*;\n\nclass Trunk {\n    Trunk prev;\n    String str;\n\n    Trunk(Trunk prev, String str) "
  },
  {
    "path": "selected_coding_interview/codes/java/include/TreeNode.java",
    "chars": 2181,
    "preview": "package include;\n\nimport java.util.*;\n\n/**\n * Definition for a binary tree node.\n */\npublic class TreeNode {\n    public "
  },
  {
    "path": "selected_coding_interview/codes/java/lc_101_symmetric_tree/lc_101_symmetric_tree.java",
    "chars": 1009,
    "preview": "/*\n* File: lc_101_symmetric_tree.java\n* Created Time: 2025-12-30\n* Author: krahets\n*/\n\npackage lc_101_symmetric_tree;\n\ni"
  },
  {
    "path": "selected_coding_interview/codes/java/lc_102_binary_tree_level_order_traversal/lc_102_binary_tree_level_order_traversal.java",
    "chars": 1376,
    "preview": "/*\n* File: lc_102_binary_tree_level_order_traversal.java\n* Created Time: 2025-12-30\n* Author: krahets\n*/\n\npackage lc_102"
  },
  {
    "path": "selected_coding_interview/codes/java/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s1.java",
    "chars": 1500,
    "preview": "/*\n* File: lc_103_binary_tree_zigzag_level_order_traversal_s1.java\n* Created Time: 2025-12-30\n* Author: krahets\n*/\n\npack"
  },
  {
    "path": "selected_coding_interview/codes/java/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s2.java",
    "chars": 2046,
    "preview": "/*\n* File: lc_103_binary_tree_zigzag_level_order_traversal_s2.java\n* Created Time: 2025-12-30\n* Author: krahets\n*/\n\npack"
  },
  {
    "path": "selected_coding_interview/codes/java/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s3.java",
    "chars": 1482,
    "preview": "/*\n* File: lc_103_binary_tree_zigzag_level_order_traversal_s3.java\n* Created Time: 2025-12-30\n* Author: krahets\n*/\n\npack"
  }
]

// ... and 783 more files (download for full content)

About this extraction

This page contains the full source code of the krahets/LeetCode-Book GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 983 files (1.8 MB), approximately 558.0k tokens, and a symbol index with 2360 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!