diff --git a/README.md b/README.md index fab7185..94f91a0 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0198 |[House Robber](src/main/php/g0101_0200/s0198_house_robber/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 4 | 64.29 #### Day 4 @@ -287,6 +288,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0064 |[Minimum Path Sum](src/main/php/g0001_0100/s0064_minimum_path_sum/Solution.php)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 20 | 81.48 +| 0221 |[Maximal Square](src/main/php/g0201_0300/s0221_maximal_square/Solution.php)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 209 | 83.33 #### Day 17 @@ -491,6 +493,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0200 |[Number of Islands](src/main/php/g0101_0200/s0200_number_of_islands/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 97 | 82.05 #### Day 2 Matrix Related Problems @@ -626,6 +629,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0021 |[Merge Two Sorted Lists](src/main/php/g0001_0100/s0021_merge_two_sorted_lists/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 3 | 90.57 +| 0206 |[Reverse Linked List](src/main/php/g0201_0300/s0206_reverse_linked_list/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 #### Day 4 Linked List @@ -660,6 +664,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0200 |[Number of Islands](src/main/php/g0101_0200/s0200_number_of_islands/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 97 | 82.05 #### Day 10 Dynamic Programming @@ -727,6 +732,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0226 |[Invert Binary Tree](src/main/php/g0201_0300/s0226_invert_binary_tree/Solution.php)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 6 | 62.79 #### Day 7 Tree @@ -759,6 +765,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0198 |[House Robber](src/main/php/g0101_0200/s0198_house_robber/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 4 | 64.29 #### Day 13 Dynamic Programming @@ -784,6 +791,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0155 |[Min Stack](src/main/php/g0101_0200/s0155_min_stack/MinStack.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 19 | 100.00 +| 0208 |[Implement Trie (Prefix Tree)](src/main/php/g0201_0300/s0208_implement_trie_prefix_tree/Trie.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 83 | 46.67 #### Day 17 Interval @@ -840,6 +848,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. |-|-|-|-|-|- | 0121 |[Best Time to Buy and Sell Stock](src/main/php/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 282 | 43.99 | 0001 |[Two Sum](src/main/php/g0001_0100/s0001_two_sum/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 9 | 97.47 +| 0189 |[Rotate Array](src/main/php/g0101_0200/s0189_rotate_array/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 60 | 67.03 | 0055 |[Jump Game](src/main/php/g0001_0100/s0055_jump_game/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 129 | 74.56 | 0075 |[Sort Colors](src/main/php/g0001_0100/s0075_sort_colors/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 3 | 88.78 | 0041 |[First Missing Positive](src/main/php/g0001_0100/s0041_first_missing_positive/Solution.php)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 111 | 90.48 @@ -856,6 +865,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0053 |[Maximum Subarray](src/main/php/g0001_0100/s0053_maximum_subarray/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 185 | 95.51 +| 0169 |[Majority Element](src/main/php/g0101_0200/s0169_majority_element/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 43 | 72.03 #### Udemy Sorting Algorithms @@ -879,6 +889,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | 0024 |[Swap Nodes in Pairs](src/main/php/g0001_0100/s0024_swap_nodes_in_pairs/Solution.php)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 3 | 85.71 | 0142 |[Linked List Cycle II](src/main/php/g0101_0200/s0142_linked_list_cycle_ii/Solution.php)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 7 | 100.00 | 0141 |[Linked List Cycle](src/main/php/g0101_0200/s0141_linked_list_cycle/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 8 | 90.60 +| 0206 |[Reverse Linked List](src/main/php/g0201_0300/s0206_reverse_linked_list/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 | 0021 |[Merge Two Sorted Lists](src/main/php/g0001_0100/s0021_merge_two_sorted_lists/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 3 | 90.57 | 0160 |[Intersection of Two Linked Lists](src/main/php/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 30 | 81.67 | 0138 |[Copy List with Random Pointer](src/main/php/g0101_0200/s0138_copy_list_with_random_pointer/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 2300 | 60.00 @@ -891,6 +902,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. |-|-|-|-|-|- | 0094 |[Binary Tree Inorder Traversal](src/main/php/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 3 | 82.09 | 0102 |[Binary Tree Level Order Traversal](src/main/php/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 4 | 96.08 +| 0226 |[Invert Binary Tree](src/main/php/g0201_0300/s0226_invert_binary_tree/Solution.php)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 6 | 62.79 | 0104 |[Maximum Depth of Binary Tree](src/main/php/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 9 | 63.06 | 0124 |[Binary Tree Maximum Path Sum](src/main/php/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.php)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 16 | 100.00 | 0098 |[Validate Binary Search Tree](src/main/php/g0001_0100/s0098_validate_binary_search_tree/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 10 | 70.97 @@ -899,11 +911,13 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0208 |[Implement Trie (Prefix Tree)](src/main/php/g0201_0300/s0208_implement_trie_prefix_tree/Trie.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 83 | 46.67 #### Udemy Graph | | | | | | |-|-|-|-|-|- +| 0200 |[Number of Islands](src/main/php/g0101_0200/s0200_number_of_islands/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 97 | 82.05 #### Udemy Dynamic Programming @@ -911,6 +925,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. |-|-|-|-|-|- | 0139 |[Word Break](src/main/php/g0101_0200/s0139_word_break/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 7 | 75.00 | 0152 |[Maximum Product Subarray](src/main/php/g0101_0200/s0152_maximum_product_subarray/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 15 | 92.86 +| 0198 |[House Robber](src/main/php/g0101_0200/s0198_house_robber/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 4 | 64.29 | 0070 |[Climbing Stairs](src/main/php/g0001_0100/s0070_climbing_stairs/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 3 | 82.81 | 0064 |[Minimum Path Sum](src/main/php/g0001_0100/s0064_minimum_path_sum/Solution.php)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 20 | 81.48 | 0072 |[Edit Distance](src/main/php/g0001_0100/s0072_edit_distance/Solution.php)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 29 | 75.00 @@ -984,6 +999,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0206 |[Reverse Linked List](src/main/php/g0201_0300/s0206_reverse_linked_list/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 #### Day 9 Stack Queue @@ -1009,6 +1025,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0226 |[Invert Binary Tree](src/main/php/g0201_0300/s0226_invert_binary_tree/Solution.php)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 6 | 62.79 #### Day 13 Tree @@ -1028,6 +1045,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0136 |[Single Number](src/main/php/g0101_0200/s0136_single_number/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 33 | 80.08 +| 0169 |[Majority Element](src/main/php/g0101_0200/s0169_majority_element/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 43 | 72.03 | 0015 |[3Sum](src/main/php/g0001_0100/s0015_3sum/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n^2)_Space_O(1), Big_O_Time_O(n\*log(n))_Space_O(n^2) | 252 | 77.94 #### Day 2 Array @@ -1136,6 +1154,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0215 |[Kth Largest Element in an Array](src/main/php/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 222 | 49.15 #### Day 21 Heap Priority Queue @@ -1154,6 +1173,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0189 |[Rotate Array](src/main/php/g0101_0200/s0189_rotate_array/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 60 | 67.03 #### Day 3 Two Pointers @@ -1197,6 +1217,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0021 |[Merge Two Sorted Lists](src/main/php/g0001_0100/s0021_merge_two_sorted_lists/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 3 | 90.57 +| 0206 |[Reverse Linked List](src/main/php/g0201_0300/s0206_reverse_linked_list/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 #### Day 11 Recursion Backtracking @@ -1209,6 +1230,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0070 |[Climbing Stairs](src/main/php/g0001_0100/s0070_climbing_stairs/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 3 | 82.81 +| 0198 |[House Robber](src/main/php/g0101_0200/s0198_house_robber/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 4 | 64.29 #### Day 13 Bit Manipulation @@ -1258,6 +1280,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0200 |[Number of Islands](src/main/php/g0101_0200/s0200_number_of_islands/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 97 | 82.05 #### Day 7 Breadth First Search Depth First Search @@ -1349,6 +1372,16 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | # | Title | Difficulty | Tag | Time, ms | Time, % |------|----------------|-------------|-------------|----------|--------- +| 0226 |[Invert Binary Tree](src/main/php/g0201_0300/s0226_invert_binary_tree/Solution.php)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_12_Tree, Level_2_Day_6_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 6 | 62.79 +| 0221 |[Maximal Square](src/main/php/g0201_0300/s0221_maximal_square/Solution.php)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Big_O_Time_O(m\*n)_Space_O(m\*n) | 209 | 83.33 +| 0215 |[Kth Largest Element in an Array](src/main/php/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, Data_Structure_II_Day_20_Heap_Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 222 | 49.15 +| 0208 |[Implement Trie (Prefix Tree)](src/main/php/g0201_0300/s0208_implement_trie_prefix_tree/Trie.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Level_2_Day_16_Design, Udemy_Trie_and_Heap, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 83 | 46.67 +| 0207 |[Course Schedule](src/main/php/g0201_0300/s0207_course_schedule/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Big_O_Time_O(N)_Space_O(N) | 25 | 89.29 +| 0206 |[Reverse Linked List](src/main/php/g0201_0300/s0206_reverse_linked_list/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Data_Structure_I_Day_8_Linked_List, Algorithm_I_Day_10_Recursion_Backtracking, Level_1_Day_3_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 +| 0200 |[Number of Islands](src/main/php/g0101_0200/s0200_number_of_islands/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search, Graph_Theory_I_Day_1_Matrix_Related_Problems, Level_1_Day_9_Graph/BFS/DFS, Udemy_Graph, Big_O_Time_O(M\*N)_Space_O(M\*N) | 97 | 82.05 +| 0198 |[House Robber](src/main/php/g0101_0200/s0198_house_robber/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_3, Level_2_Day_12_Dynamic_Programming, Udemy_Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 4 | 64.29 +| 0189 |[Rotate Array](src/main/php/g0101_0200/s0189_rotate_array/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Algorithm_I_Day_2_Two_Pointers, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 60 | 67.03 +| 0169 |[Majority Element](src/main/php/g0101_0200/s0169_majority_element/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Data_Structure_II_Day_1_Array, Udemy_Famous_Algorithm, Big_O_Time_O(n)_Space_O(1) | 43 | 72.03 | 0160 |[Intersection of Two Linked Lists](src/main/php/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_11_Linked_List, Udemy_Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 30 | 81.67 | 0155 |[Min Stack](src/main/php/g0101_0200/s0155_min_stack/MinStack.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Data_Structure_II_Day_14_Stack_Queue, Programming_Skills_II_Day_18, Level_2_Day_16_Design, Udemy_Design, Big_O_Time_O(1)_Space_O(N) | 19 | 100.00 | 0153 |[Find Minimum in Rotated Sorted Array](src/main/php/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.php)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Algorithm_II_Day_2_Binary_Search, Binary_Search_I_Day_12, Udemy_Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 9 | 73.47 diff --git a/src/main/php/g0101_0200/s0169_majority_element/Solution.php b/src/main/php/g0101_0200/s0169_majority_element/Solution.php new file mode 100644 index 0000000..79d7255 --- /dev/null +++ b/src/main/php/g0101_0200/s0169_majority_element/Solution.php @@ -0,0 +1,23 @@ + $value) { + if ($value > $count) { + return $key; + } + } + } +} diff --git a/src/main/php/g0101_0200/s0169_majority_element/readme.md b/src/main/php/g0101_0200/s0169_majority_element/readme.md new file mode 100644 index 0000000..5ea5071 --- /dev/null +++ b/src/main/php/g0101_0200/s0169_majority_element/readme.md @@ -0,0 +1,27 @@ +169\. Majority Element + +Easy + +Given an array `nums` of size `n`, return _the majority element_. + +The majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array. + +**Example 1:** + +**Input:** nums = [3,2,3] + +**Output:** 3 + +**Example 2:** + +**Input:** nums = [2,2,1,1,1,2,2] + +**Output:** 2 + +**Constraints:** + +* `n == nums.length` +* 1 <= n <= 5 * 104 +* -231 <= nums[i] <= 231 - 1 + +**Follow-up:** Could you solve the problem in linear time and in `O(1)` space? \ No newline at end of file diff --git a/src/main/php/g0101_0200/s0189_rotate_array/Solution.php b/src/main/php/g0101_0200/s0189_rotate_array/Solution.php new file mode 100644 index 0000000..c905267 --- /dev/null +++ b/src/main/php/g0101_0200/s0189_rotate_array/Solution.php @@ -0,0 +1,32 @@ +reverse($nums, 0, $t - 1); + $this->reverse($nums, $t, $n - 1); + $this->reverse($nums, 0, $n - 1); + } +} diff --git a/src/main/php/g0101_0200/s0189_rotate_array/readme.md b/src/main/php/g0101_0200/s0189_rotate_array/readme.md new file mode 100644 index 0000000..390f269 --- /dev/null +++ b/src/main/php/g0101_0200/s0189_rotate_array/readme.md @@ -0,0 +1,39 @@ +189\. Rotate Array + +Medium + +Given an array, rotate the array to the right by `k` steps, where `k` is non-negative. + +**Example 1:** + +**Input:** nums = [1,2,3,4,5,6,7], k = 3 + +**Output:** [5,6,7,1,2,3,4] + +**Explanation:** + + rotate 1 steps to the right: [7,1,2,3,4,5,6] + rotate 2 steps to the right: [6,7,1,2,3,4,5] + rotate 3 steps to the right: [5,6,7,1,2,3,4] + +**Example 2:** + +**Input:** nums = [-1,-100,3,99], k = 2 + +**Output:** [3,99,-1,-100] + +**Explanation:** + + rotate 1 steps to the right: [99,-1,-100,3] + rotate 2 steps to the right: [3,99,-1,-100] + +**Constraints:** + +* 1 <= nums.length <= 105 +* -231 <= nums[i] <= 231 - 1 +* 0 <= k <= 105 + +**Follow up:** + +* Try to come up with as many solutions as you can. There are at least **three** different ways to solve this problem. +* Could you do it in-place with `O(1)` extra space? \ No newline at end of file diff --git a/src/main/php/g0101_0200/s0198_house_robber/Solution.php b/src/main/php/g0101_0200/s0198_house_robber/Solution.php new file mode 100644 index 0000000..0aca987 --- /dev/null +++ b/src/main/php/g0101_0200/s0198_house_robber/Solution.php @@ -0,0 +1,34 @@ +dfs($grid, $i, $j); + $islands++; + } + } + } + } + return $islands; + } + + private function dfs(&$grid, $x, $y) { + if ($x < 0 || count($grid) <= $x || $y < 0 || count($grid[0]) <= $y || $grid[$x][$y] != '1') { + return; + } + $grid[$x][$y] = 'x'; + $this->dfs($grid, $x + 1, $y); + $this->dfs($grid, $x - 1, $y); + $this->dfs($grid, $x, $y + 1); + $this->dfs($grid, $x, $y - 1); + } +} diff --git a/src/main/php/g0101_0200/s0200_number_of_islands/readme.md b/src/main/php/g0101_0200/s0200_number_of_islands/readme.md new file mode 100644 index 0000000..0c4292d --- /dev/null +++ b/src/main/php/g0101_0200/s0200_number_of_islands/readme.md @@ -0,0 +1,40 @@ +200\. Number of Islands + +Medium + +Given an `m x n` 2D binary grid `grid` which represents a map of `'1'`s (land) and `'0'`s (water), return _the number of islands_. + +An **island** is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. + +**Example 1:** + +**Input:** + + grid = [ + ["1","1","1","1","0"], + ["1","1","0","1","0"], + ["1","1","0","0","0"], + ["0","0","0","0","0"] + ] + +**Output:** 1 + +**Example 2:** + +**Input:** + + grid = [ + ["1","1","0","0","0"], + ["1","1","0","0","0"], + ["0","0","1","0","0"], + ["0","0","0","1","1"] + ] + +**Output:** 3 + +**Constraints:** + +* `m == grid.length` +* `n == grid[i].length` +* `1 <= m, n <= 300` +* `grid[i][j]` is `'0'` or `'1'`. \ No newline at end of file diff --git a/src/main/php/g0201_0300/s0206_reverse_linked_list/Solution.php b/src/main/php/g0201_0300/s0206_reverse_linked_list/Solution.php new file mode 100644 index 0000000..aaae7ea --- /dev/null +++ b/src/main/php/g0201_0300/s0206_reverse_linked_list/Solution.php @@ -0,0 +1,37 @@ +val = $val; + * $this->next = $next; + * } + * } + */ +class Solution { + /** + * @param ListNode $head + * @return ListNode + */ + public function reverseList($head) { + $prev = null; + $curr = $head; + while ($curr != null) { + $next = $curr->next; + $curr->next = $prev; + $prev = $curr; + $curr = $next; + } + return $prev; + } +} diff --git a/src/main/php/g0201_0300/s0206_reverse_linked_list/readme.md b/src/main/php/g0201_0300/s0206_reverse_linked_list/readme.md new file mode 100644 index 0000000..a764d55 --- /dev/null +++ b/src/main/php/g0201_0300/s0206_reverse_linked_list/readme.md @@ -0,0 +1,34 @@ +206\. Reverse Linked List + +Easy + +Given the `head` of a singly linked list, reverse the list, and return _the reversed list_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg) + +**Input:** head = [1,2,3,4,5] + +**Output:** [5,4,3,2,1] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/02/19/rev1ex2.jpg) + +**Input:** head = [1,2] + +**Output:** [2,1] + +**Example 3:** + +**Input:** head = [] + +**Output:** [] + +**Constraints:** + +* The number of nodes in the list is the range `[0, 5000]`. +* `-5000 <= Node.val <= 5000` + +**Follow up:** A linked list can be reversed either iteratively or recursively. Could you implement both? \ No newline at end of file diff --git a/src/main/php/g0201_0300/s0207_course_schedule/Solution.php b/src/main/php/g0201_0300/s0207_course_schedule/Solution.php new file mode 100644 index 0000000..a80ba98 --- /dev/null +++ b/src/main/php/g0201_0300/s0207_course_schedule/Solution.php @@ -0,0 +1,46 @@ +hasCycle($adj, $i, $colors)) { + return false; + } + } + return true; + } + + private function hasCycle($adj, $node, &$colors) { + $colors[$node] = self::GRAY; + foreach ($adj[$node] as $nei) { + if ($colors[$nei] == self::GRAY) { + return true; + } + if ($colors[$nei] == self::WHITE && $this->hasCycle($adj, $nei, $colors)) { + return true; + } + } + $colors[$node] = self::BLACK; + return false; + } +} diff --git a/src/main/php/g0201_0300/s0207_course_schedule/readme.md b/src/main/php/g0201_0300/s0207_course_schedule/readme.md new file mode 100644 index 0000000..a7b1e9c --- /dev/null +++ b/src/main/php/g0201_0300/s0207_course_schedule/readme.md @@ -0,0 +1,33 @@ +207\. Course Schedule + +Medium + +There are a total of `numCourses` courses you have to take, labeled from `0` to `numCourses - 1`. You are given an array `prerequisites` where prerequisites[i] = [ai, bi] indicates that you **must** take course bi first if you want to take course ai. + +* For example, the pair `[0, 1]`, indicates that to take course `0` you have to first take course `1`. + +Return `true` if you can finish all courses. Otherwise, return `false`. + +**Example 1:** + +**Input:** numCourses = 2, prerequisites = [[1,0]] + +**Output:** true + +**Explanation:** There are a total of 2 courses to take. To take course 1 you should have finished course 0. So it is possible. + +**Example 2:** + +**Input:** numCourses = 2, prerequisites = [[1,0],[0,1]] + +**Output:** false + +**Explanation:** There are a total of 2 courses to take. To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible. + +**Constraints:** + +* 1 <= numCourses <= 105 +* `0 <= prerequisites.length <= 5000` +* `prerequisites[i].length == 2` +* 0 <= ai, bi < numCourses +* All the pairs prerequisites[i] are **unique**. \ No newline at end of file diff --git a/src/main/php/g0201_0300/s0208_implement_trie_prefix_tree/Trie.php b/src/main/php/g0201_0300/s0208_implement_trie_prefix_tree/Trie.php new file mode 100644 index 0000000..cee676b --- /dev/null +++ b/src/main/php/g0201_0300/s0208_implement_trie_prefix_tree/Trie.php @@ -0,0 +1,85 @@ +children = array_fill(0, 26, null); + $this->isWord = false; + } +} + +class Trie { + private $root; + private $startWith; + + function __construct() { + $this->root = new TrieNode(); + $this->startWith = false; + } + + /** + * @param String $word + * @return NULL + */ + public function insert($word) { + $this->insertInternal($word, $this->root, 0); + } + + private function insertInternal($word, $root, $idx) { + if ($idx == strlen($word)) { + $root->isWord = true; + return; + } + $index = ord($word[$idx]) - ord('a'); + if ($root->children[$index] == null) { + $root->children[$index] = new TrieNode(); + } + $this->insertInternal($word, $root->children[$index], $idx + 1); + } + + /** + * @param String $word + * @return Boolean + */ + public function search($word) { + return $this->searchInternal($word, $this->root, 0); + } + + private function searchInternal($word, $root, $idx) { + if ($idx == strlen($word)) { + $this->startWith = true; + return $root->isWord; + } + $index = ord($word[$idx]) - ord('a'); + if ($root->children[$index] == null) { + $this->startWith = false; + return false; + } + return $this->searchInternal($word, $root->children[$index], $idx + 1); + } + + /** + * @param String $prefix + * @return Boolean + */ + public function startsWith($prefix) { + $this->search($prefix); + return $this->startWith; + } +} +/** + * Your Trie object will be instantiated and called as such: + * $obj = Trie(); + * $obj->insert($word); + * $ret_2 = $obj->search($word); + * $ret_3 = $obj->startsWith($prefix); + */ diff --git a/src/main/php/g0201_0300/s0208_implement_trie_prefix_tree/readme.md b/src/main/php/g0201_0300/s0208_implement_trie_prefix_tree/readme.md new file mode 100644 index 0000000..8121de3 --- /dev/null +++ b/src/main/php/g0201_0300/s0208_implement_trie_prefix_tree/readme.md @@ -0,0 +1,36 @@ +208\. Implement Trie (Prefix Tree) + +Medium + +A [**trie**](https://en.wikipedia.org/wiki/Trie) (pronounced as "try") or **prefix tree** is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. + +Implement the Trie class: + +* `Trie()` Initializes the trie object. +* `void insert(String word)` Inserts the string `word` into the trie. +* `boolean search(String word)` Returns `true` if the string `word` is in the trie (i.e., was inserted before), and `false` otherwise. +* `boolean startsWith(String prefix)` Returns `true` if there is a previously inserted string `word` that has the prefix `prefix`, and `false` otherwise. + +**Example 1:** + +**Input** + + ["Trie", "insert", "search", "search", "startsWith", "insert", "search"] + [[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]] + +**Output:** [null, null, true, false, true, null, true] + +**Explanation:** + + Trie trie = new Trie(); + trie.insert("apple"); trie.search("apple"); // return True + trie.search("app"); // return False + trie.startsWith("app"); // return True + trie.insert("app"); + trie.search("app"); // return True + +**Constraints:** + +* `1 <= word.length, prefix.length <= 2000` +* `word` and `prefix` consist only of lowercase English letters. +* At most 3 * 104 calls **in total** will be made to `insert`, `search`, and `startsWith`. \ No newline at end of file diff --git a/src/main/php/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.php b/src/main/php/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.php new file mode 100644 index 0000000..538fe7a --- /dev/null +++ b/src/main/php/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.php @@ -0,0 +1,20 @@ +kth _largest element in the array_. + +Note that it is the kth largest element in the sorted order, not the kth distinct element. + +**Example 1:** + +**Input:** nums = [3,2,1,5,6,4], k = 2 + +**Output:** 5 + +**Example 2:** + +**Input:** nums = [3,2,3,1,2,4,5,5,6], k = 4 + +**Output:** 4 + +**Constraints:** + +* 1 <= k <= nums.length <= 104 +* -104 <= nums[i] <= 104 \ No newline at end of file diff --git a/src/main/php/g0201_0300/s0221_maximal_square/Solution.php b/src/main/php/g0201_0300/s0221_maximal_square/Solution.php new file mode 100644 index 0000000..42388c1 --- /dev/null +++ b/src/main/php/g0201_0300/s0221_maximal_square/Solution.php @@ -0,0 +1,38 @@ + $max) { + $max = $next; + } + $dp[$i + 1][$j + 1] = $next; + } + } + } + return $max * $max; + } +} diff --git a/src/main/php/g0201_0300/s0221_maximal_square/readme.md b/src/main/php/g0201_0300/s0221_maximal_square/readme.md new file mode 100644 index 0000000..d9d3909 --- /dev/null +++ b/src/main/php/g0201_0300/s0221_maximal_square/readme.md @@ -0,0 +1,34 @@ +221\. Maximal Square + +Medium + +Given an `m x n` binary `matrix` filled with `0`'s and `1`'s, _find the largest square containing only_ `1`'s _and return its area_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/26/max1grid.jpg) + +**Input:** matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] + +**Output:** 4 + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/26/max2grid.jpg) + +**Input:** matrix = [["0","1"],["1","0"]] + +**Output:** 1 + +**Example 3:** + +**Input:** matrix = [["0"]] + +**Output:** 0 + +**Constraints:** + +* `m == matrix.length` +* `n == matrix[i].length` +* `1 <= m, n <= 300` +* `matrix[i][j]` is `'0'` or `'1'`. \ No newline at end of file diff --git a/src/main/php/g0201_0300/s0226_invert_binary_tree/Solution.php b/src/main/php/g0201_0300/s0226_invert_binary_tree/Solution.php new file mode 100644 index 0000000..c1ba745 --- /dev/null +++ b/src/main/php/g0201_0300/s0226_invert_binary_tree/Solution.php @@ -0,0 +1,36 @@ +val = $val; + * $this->left = $left; + * $this->right = $right; + * } + * } + */ +class Solution { + /** + * @param TreeNode $root + * @return TreeNode + */ + public function invertTree($root) { + if ($root == null) { + return null; + } + $temp = $root->left; + $root->left = $this->invertTree($root->right); + $root->right = $this->invertTree($temp); + return $root; + } +} diff --git a/src/main/php/g0201_0300/s0226_invert_binary_tree/readme.md b/src/main/php/g0201_0300/s0226_invert_binary_tree/readme.md new file mode 100644 index 0000000..339bf4e --- /dev/null +++ b/src/main/php/g0201_0300/s0226_invert_binary_tree/readme.md @@ -0,0 +1,32 @@ +226\. Invert Binary Tree + +Easy + +Given the `root` of a binary tree, invert the tree, and return _its root_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/14/invert1-tree.jpg) + +**Input:** root = [4,2,7,1,3,6,9] + +**Output:** [4,7,2,9,6,3,1] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/03/14/invert2-tree.jpg) + +**Input:** root = [2,1,3] + +**Output:** [2,3,1] + +**Example 3:** + +**Input:** root = [] + +**Output:** [] + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 100]`. +* `-100 <= Node.val <= 100` \ No newline at end of file diff --git a/src/test/php/g0101_0200/s0169_majority_element/SolutionTest.php b/src/test/php/g0101_0200/s0169_majority_element/SolutionTest.php new file mode 100644 index 0000000..96f2037 --- /dev/null +++ b/src/test/php/g0101_0200/s0169_majority_element/SolutionTest.php @@ -0,0 +1,15 @@ +assertEquals(3, (new Solution())->majorityElement(array(3, 2, 3))); + } + + public function testMajorityElement2() { + $this->assertEquals(2, (new Solution())->majorityElement(array(2, 2, 1, 1, 1, 2, 2))); + } +} diff --git a/src/test/php/g0101_0200/s0189_rotate_array/SolutionTest.php b/src/test/php/g0101_0200/s0189_rotate_array/SolutionTest.php new file mode 100644 index 0000000..4815a59 --- /dev/null +++ b/src/test/php/g0101_0200/s0189_rotate_array/SolutionTest.php @@ -0,0 +1,19 @@ +rotate($array, 3); + $this->assertEquals(array(5, 6, 7, 1, 2, 3, 4), $array); + } + + public function testRotate2() { + $array = array(-1, -100, 3, 99); + (new Solution())->rotate($array, 2); + $this->assertEquals(array(3, 99, -1, -100), $array); + } +} diff --git a/src/test/php/g0101_0200/s0198_house_robber/SolutionTest.php b/src/test/php/g0101_0200/s0198_house_robber/SolutionTest.php new file mode 100644 index 0000000..6332366 --- /dev/null +++ b/src/test/php/g0101_0200/s0198_house_robber/SolutionTest.php @@ -0,0 +1,15 @@ +assertEquals(4, (new Solution())->rob(array(1, 2, 3, 1))); + } + + public function testRob2() { + $this->assertEquals(12, (new Solution())->rob(array(2, 7, 9, 3, 1))); + } +} diff --git a/src/test/php/g0101_0200/s0200_number_of_islands/SolutionTest.php b/src/test/php/g0101_0200/s0200_number_of_islands/SolutionTest.php new file mode 100644 index 0000000..e913334 --- /dev/null +++ b/src/test/php/g0101_0200/s0200_number_of_islands/SolutionTest.php @@ -0,0 +1,25 @@ +assertEquals(1, (new Solution())->numIslands(array( + array('1', '1', '1', '1', '0'), + array('1', '1', '0', '1', '0'), + array('1', '1', '0', '0', '0'), + array('0', '0', '0', '0', '0') + ))); + } + + public function testNumIslands2() { + $this->assertEquals(3, (new Solution())->numIslands(array( + array('1', '1', '0', '0', '0'), + array('1', '1', '0', '0', '0'), + array('0', '0', '1', '0', '0'), + array('0', '0', '0', '1', '1') + ))); + } +} diff --git a/src/test/php/g0201_0300/s0206_reverse_linked_list/SolutionTest.php b/src/test/php/g0201_0300/s0206_reverse_linked_list/SolutionTest.php new file mode 100644 index 0000000..919667c --- /dev/null +++ b/src/test/php/g0201_0300/s0206_reverse_linked_list/SolutionTest.php @@ -0,0 +1,27 @@ +next = new ListNode(2); + $headActual->next->next = new ListNode(3); + $headActual->next->next->next = new ListNode(4); + $headActual->next->next->next->next = new ListNode(5); + $this->assertEquals("5, 4, 3, 2, 1", (new Solution())->reverseList($headActual)->toString()); + } + + public function testReverseList2() { + $headActual = new ListNode(1); + $headActual->next = new ListNode(2); + $this->assertEquals("2, 1", (new Solution())->reverseList($headActual)->toString()); + } + + public function testReverseList3() { + $this->assertEquals(null, (new Solution())->reverseList(null)); + } +} diff --git a/src/test/php/g0201_0300/s0207_course_schedule/SolutionTest.php b/src/test/php/g0201_0300/s0207_course_schedule/SolutionTest.php new file mode 100644 index 0000000..de65a83 --- /dev/null +++ b/src/test/php/g0201_0300/s0207_course_schedule/SolutionTest.php @@ -0,0 +1,15 @@ +assertEquals(true, (new Solution())->canFinish(2, array(array(1, 0)))); + } + + public function testCanFinish2() { + $this->assertEquals(false, (new Solution())->canFinish(2, array(array(1, 0), array(0, 1)))); + } +} diff --git a/src/test/php/g0201_0300/s0208_implement_trie_prefix_tree/TrieTest.php b/src/test/php/g0201_0300/s0208_implement_trie_prefix_tree/TrieTest.php new file mode 100644 index 0000000..d946203 --- /dev/null +++ b/src/test/php/g0201_0300/s0208_implement_trie_prefix_tree/TrieTest.php @@ -0,0 +1,17 @@ +insert("apple"); + $this->assertEquals(true, $trie->search("apple")); + $this->assertEquals(false, $trie->search("app")); + $this->assertEquals(true, $trie->startsWith("app")); + $trie->insert("app"); + $this->assertEquals(true, $trie->search("app")); + } +} diff --git a/src/test/php/g0201_0300/s0215_kth_largest_element_in_an_array/SolutionTest.php b/src/test/php/g0201_0300/s0215_kth_largest_element_in_an_array/SolutionTest.php new file mode 100644 index 0000000..3308f55 --- /dev/null +++ b/src/test/php/g0201_0300/s0215_kth_largest_element_in_an_array/SolutionTest.php @@ -0,0 +1,15 @@ +assertEquals(5, (new Solution())->findKthLargest(array(3, 2, 1, 5, 6, 4), 2)); + } + + public function testFindKthLargest2() { + $this->assertEquals(4, (new Solution())->findKthLargest(array(3, 2, 3, 1, 2, 4, 5, 5, 6), 4)); + } +} diff --git a/src/test/php/g0201_0300/s0221_maximal_square/SolutionTest.php b/src/test/php/g0201_0300/s0221_maximal_square/SolutionTest.php new file mode 100644 index 0000000..4697e34 --- /dev/null +++ b/src/test/php/g0201_0300/s0221_maximal_square/SolutionTest.php @@ -0,0 +1,27 @@ +assertEquals(4, (new Solution())->maximalSquare($input)); + } + + public function testMaximalSquare2() { + $input = array(array('0', '1'), array('1', '0')); + $this->assertEquals(1, (new Solution())->maximalSquare($input)); + } + + public function testMaximalSquare3() { + $input = array(array('0')); + $this->assertEquals(0, (new Solution())->maximalSquare($input)); + } +} diff --git a/src/test/php/g0201_0300/s0226_invert_binary_tree/SolutionTest.php b/src/test/php/g0201_0300/s0226_invert_binary_tree/SolutionTest.php new file mode 100644 index 0000000..b39f7b2 --- /dev/null +++ b/src/test/php/g0201_0300/s0226_invert_binary_tree/SolutionTest.php @@ -0,0 +1,18 @@ +assertEquals("4,7,9,6,2,3,1", (new Solution())->invertTree($root)); + } + + public function testInvertTree2() { + $root = TreeUtils::constructBinaryTree(array(2, 1, 3)); + $this->assertEquals("2,3,1", (new Solution())->invertTree($root)); + } +}