From 571354a942739aca9a4c11f9b99287572f974ff1 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sun, 10 Dec 2023 19:19:52 +0200 Subject: [PATCH] Added tasks 73-98 --- README.md | 28 +++++++ src/main/php/com_github_leetcode/TreeNode.php | 52 +++++++++++++ .../s0073_set_matrix_zeroes/Solution.php | 63 ++++++++++++++++ .../s0073_set_matrix_zeroes/readme.md | 36 +++++++++ .../s0074_search_a_2d_matrix/Solution.php | 35 +++++++++ .../s0074_search_a_2d_matrix/readme.md | 31 ++++++++ .../g0001_0100/s0075_sort_colors/Solution.php | 31 ++++++++ .../g0001_0100/s0075_sort_colors/readme.md | 41 +++++++++++ .../Solution.php | 41 +++++++++++ .../s0076_minimum_window_substring/readme.md | 42 +++++++++++ .../php/g0001_0100/s0078_subsets/Solution.php | 28 +++++++ .../php/g0001_0100/s0078_subsets/readme.md | 25 +++++++ .../g0001_0100/s0079_word_search/Solution.php | 70 ++++++++++++++++++ .../g0001_0100/s0079_word_search/readme.md | 41 +++++++++++ .../Solution.php | 73 +++++++++++++++++++ .../readme.md | 28 +++++++ .../Solution.php | 48 ++++++++++++ .../readme.md | 48 ++++++++++++ .../Solution.php | 23 ++++++ .../readme.md | 23 ++++++ .../Solution.php | 41 +++++++++++ .../readme.md | 34 +++++++++ .../s0073_set_matrix_zeroes/SolutionTest.php | 21 ++++++ .../s0074_search_a_2d_matrix/SolutionTest.php | 19 +++++ .../s0075_sort_colors/SolutionTest.php | 21 ++++++ .../SolutionTest.php | 22 ++++++ .../g0001_0100/s0078_subsets/SolutionTest.php | 19 +++++ .../s0079_word_search/SolutionTest.php | 25 +++++++ .../SolutionTest.php | 17 +++++ .../SolutionTest.php | 27 +++++++ .../SolutionTest.php | 17 +++++ .../SolutionTest.php | 26 +++++++ 32 files changed, 1096 insertions(+) create mode 100644 src/main/php/com_github_leetcode/TreeNode.php create mode 100644 src/main/php/g0001_0100/s0073_set_matrix_zeroes/Solution.php create mode 100644 src/main/php/g0001_0100/s0073_set_matrix_zeroes/readme.md create mode 100644 src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php create mode 100644 src/main/php/g0001_0100/s0074_search_a_2d_matrix/readme.md create mode 100644 src/main/php/g0001_0100/s0075_sort_colors/Solution.php create mode 100644 src/main/php/g0001_0100/s0075_sort_colors/readme.md create mode 100644 src/main/php/g0001_0100/s0076_minimum_window_substring/Solution.php create mode 100644 src/main/php/g0001_0100/s0076_minimum_window_substring/readme.md create mode 100644 src/main/php/g0001_0100/s0078_subsets/Solution.php create mode 100644 src/main/php/g0001_0100/s0078_subsets/readme.md create mode 100644 src/main/php/g0001_0100/s0079_word_search/Solution.php create mode 100644 src/main/php/g0001_0100/s0079_word_search/readme.md create mode 100644 src/main/php/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.php create mode 100644 src/main/php/g0001_0100/s0084_largest_rectangle_in_histogram/readme.md create mode 100644 src/main/php/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.php create mode 100644 src/main/php/g0001_0100/s0094_binary_tree_inorder_traversal/readme.md create mode 100644 src/main/php/g0001_0100/s0096_unique_binary_search_trees/Solution.php create mode 100644 src/main/php/g0001_0100/s0096_unique_binary_search_trees/readme.md create mode 100644 src/main/php/g0001_0100/s0098_validate_binary_search_tree/Solution.php create mode 100644 src/main/php/g0001_0100/s0098_validate_binary_search_tree/readme.md create mode 100644 src/test/php/g0001_0100/s0073_set_matrix_zeroes/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0074_search_a_2d_matrix/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0075_sort_colors/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0076_minimum_window_substring/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0078_subsets/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0079_word_search/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0084_largest_rectangle_in_histogram/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0094_binary_tree_inorder_traversal/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0096_unique_binary_search_trees/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0098_validate_binary_search_tree/SolutionTest.php diff --git a/README.md b/README.md index beedb7d..703881d 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 9 | 68.18 #### Day 9 @@ -254,6 +255,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0096 |[Unique Binary Search Trees](src/main/php/g0001_0100/s0096_unique_binary_search_trees/Solution.php)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 #### Day 12 @@ -642,6 +644,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 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 #### Day 9 Graph/BFS/DFS @@ -723,6 +726,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 9 | 68.18 | 0033 |[Search in Rotated Sorted Array](src/main/php/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 7 | 83.17 #### Day 9 Binary Search Tree @@ -755,6 +759,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- | 0003 |[Longest Substring Without Repeating Characters](src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 4 | 99.33 +| 0076 |[Minimum Window Substring](src/main/php/g0001_0100/s0076_minimum_window_substring/Solution.php)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 21 | 100.00 #### Day 15 Tree @@ -819,6 +824,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. |-|-|-|-|-|- | 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 | 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 #### Udemy Two Pointers @@ -843,7 +849,9 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 9 | 68.18 | 0048 |[Rotate Image](src/main/php/g0001_0100/s0048_rotate_image/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 4 | 81.58 +| 0073 |[Set Matrix Zeroes](src/main/php/g0001_0100/s0073_set_matrix_zeroes/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 37 | 61.76 | 0056 |[Merge Intervals](src/main/php/g0001_0100/s0056_merge_intervals/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 48 | 80.00 #### Udemy Linked List @@ -858,6 +866,8 @@ 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 +| 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 #### Udemy Trie and Heap @@ -884,6 +894,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. |-|-|-|-|-|- | 0022 |[Generate Parentheses](src/main/php/g0001_0100/s0022_generate_parentheses/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 4 | 83.67 | 0039 |[Combination Sum](src/main/php/g0001_0100/s0039_combination_sum/Solution.php)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 11 | 87.10 +| 0078 |[Subsets](src/main/php/g0001_0100/s0078_subsets/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 7 | 69.23 | 0017 |[Letter Combinations of a Phone Number](src/main/php/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 5 | 60.19 | 0046 |[Permutations](src/main/php/g0001_0100/s0046_permutations/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 4 | 92.42 @@ -925,6 +936,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 9 | 68.18 #### Day 6 String @@ -952,6 +964,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 #### Day 11 Tree @@ -972,6 +985,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 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 ### Data Structure II @@ -985,6 +999,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 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 | 0056 |[Merge Intervals](src/main/php/g0001_0100/s0056_merge_intervals/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 48 | 80.00 #### Day 3 Array @@ -1174,6 +1189,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. |-|-|-|-|-|- | 0034 |[Find First and Last Position of Element in Sorted Array](src/main/php/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 19 | 81.01 | 0033 |[Search in Rotated Sorted Array](src/main/php/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 7 | 83.17 +| 0074 |[Search a 2D Matrix](src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 9 | 68.18 #### Day 2 Binary Search @@ -1216,6 +1232,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0078 |[Subsets](src/main/php/g0001_0100/s0078_subsets/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 7 | 69.23 #### Day 10 Recursion Backtracking @@ -1229,6 +1246,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated. |-|-|-|-|-|- | 0017 |[Letter Combinations of a Phone Number](src/main/php/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 5 | 60.19 | 0022 |[Generate Parentheses](src/main/php/g0001_0100/s0022_generate_parentheses/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 4 | 83.67 +| 0079 |[Word Search](src/main/php/g0001_0100/s0079_word_search/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 697 | 100.00 #### Day 12 Dynamic Programming @@ -1289,6 +1307,16 @@ Php-based LeetCode algorithm problem solutions, regularly updated. | # | Title | Difficulty | Tag | Time, ms | Time, % |------|----------------|-------------|-------------|----------|--------- +| 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, Data_Structure_I_Day_14_Tree, Level_1_Day_8_Binary_Search_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(N)_Space_O(log(N)) | 10 | 70.97 +| 0096 |[Unique Binary Search Trees](src/main/php/g0001_0100/s0096_unique_binary_search_trees/Solution.php)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Dynamic_Programming_I_Day_11, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 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, Data_Structure_I_Day_10_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 3 | 82.09 +| 0084 |[Largest Rectangle in Histogram](src/main/php/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.php)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n_log_n)_Space_O(log_n) | 298 | 100.00 +| 0079 |[Word Search](src/main/php/g0001_0100/s0079_word_search/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 697 | 100.00 +| 0078 |[Subsets](src/main/php/g0001_0100/s0078_subsets/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Algorithm_II_Day_9_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 7 | 69.23 +| 0076 |[Minimum Window Substring](src/main/php/g0001_0100/s0076_minimum_window_substring/Solution.php)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Big_O_Time_O(s.length())_Space_O(1) | 21 | 100.00 +| 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, Data_Structure_II_Day_2_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 3 | 88.78 +| 0074 |[Search a 2D Matrix](src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Data_Structure_I_Day_5_Array, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_8, Level_2_Day_8_Binary_Search, Udemy_2D_Arrays/Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 9 | 68.18 +| 0073 |[Set Matrix Zeroes](src/main/php/g0001_0100/s0073_set_matrix_zeroes/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Udemy_2D_Arrays/Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 37 | 61.76 | 0072 |[Edit Distance](src/main/php/g0001_0100/s0072_edit_distance/Solution.php)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 29 | 75.00 | 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, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_2, Level_1_Day_10_Dynamic_Programming, Udemy_Dynamic_Programming, 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, Dynamic_Programming_I_Day_16, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 20 | 81.48 diff --git a/src/main/php/com_github_leetcode/TreeNode.php b/src/main/php/com_github_leetcode/TreeNode.php new file mode 100644 index 0000000..5ee3d70 --- /dev/null +++ b/src/main/php/com_github_leetcode/TreeNode.php @@ -0,0 +1,52 @@ +val = $val; + $this->left = $left; + $this->right = $right; + } + + public static function create($treeValues) { + $root = empty($treeValues) ? null : new TreeNode($treeValues[0]); + $queue = array(); + array_push($queue, $root); + $i = 1; + while ($i < count($treeValues)) { + $curr = array_shift($queue); + if ($treeValues[$i] != null) { + $curr->left = new TreeNode($treeValues[$i]); + array_push($queue, $curr->left); + } + if (++$i < count($treeValues) && $treeValues[$i] != null) { + $curr->right = new TreeNode($treeValues[$i]); + array_push($queue, $curr->right); + } + $i++; + } + return $root; + } + + public function __toString() { + if ($this->left == null && $this->right == null) { + return "" . $this->val; + } else { + $root = "" . $this->val; + $leftValue = "null"; + $rightValue = "null"; + if ($this->left != null) { + $leftValue = $this->left->__toString(); + } + if ($this->right != null) { + $rightValue = $this->right->__toString(); + } + return $root . "," . $leftValue . "," . $rightValue; + } + } +} diff --git a/src/main/php/g0001_0100/s0073_set_matrix_zeroes/Solution.php b/src/main/php/g0001_0100/s0073_set_matrix_zeroes/Solution.php new file mode 100644 index 0000000..d79b08d --- /dev/null +++ b/src/main/php/g0001_0100/s0073_set_matrix_zeroes/Solution.php @@ -0,0 +1,63 @@ +-231 <= matrix[i][j] <= 231 - 1 + +**Follow up:** + +* A straightforward solution using `O(mn)` space is probably a bad idea. +* A simple improvement uses `O(m + n)` space, but still not the best solution. +* Could you devise a constant space solution? \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php b/src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php new file mode 100644 index 0000000..cbaf249 --- /dev/null +++ b/src/main/php/g0001_0100/s0074_search_a_2d_matrix/Solution.php @@ -0,0 +1,35 @@ += $target) { + $targetRow = $i; + break; + } + } + for ($i = 0; $i < $endCol; $i++) { + if ($matrix[$targetRow][$i] == $target) { + $result = true; + break; + } + } + return $result; + } +} diff --git a/src/main/php/g0001_0100/s0074_search_a_2d_matrix/readme.md b/src/main/php/g0001_0100/s0074_search_a_2d_matrix/readme.md new file mode 100644 index 0000000..ce4e033 --- /dev/null +++ b/src/main/php/g0001_0100/s0074_search_a_2d_matrix/readme.md @@ -0,0 +1,31 @@ +74\. Search a 2D Matrix + +Medium + +Write an efficient algorithm that searches for a value in an `m x n` matrix. This matrix has the following properties: + +* Integers in each row are sorted from left to right. +* The first integer of each row is greater than the last integer of the previous row. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/10/05/mat.jpg) + +**Input:** matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3 + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/10/05/mat2.jpg) + +**Input:** matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13 + +**Output:** false + +**Constraints:** + +* `m == matrix.length` +* `n == matrix[i].length` +* `1 <= m, n <= 100` +* -104 <= matrix[i][j], target <= 104 \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0075_sort_colors/Solution.php b/src/main/php/g0001_0100/s0075_sort_colors/Solution.php new file mode 100644 index 0000000..8f49374 --- /dev/null +++ b/src/main/php/g0001_0100/s0075_sort_colors/Solution.php @@ -0,0 +1,31 @@ + 0) { + $count--; + } + while ($count == 0) { + if ($end - $begin < $d) { + $d = $end - $begin; + $head = $begin; + } + if ($map[ord($s[$begin++]) - ord('A')]++ == 0) { + $count++; + } + } + } + return $d == PHP_INT_MAX ? "" : substr($s, $head, $head + $d); + } +} diff --git a/src/main/php/g0001_0100/s0076_minimum_window_substring/readme.md b/src/main/php/g0001_0100/s0076_minimum_window_substring/readme.md new file mode 100644 index 0000000..7c7d492 --- /dev/null +++ b/src/main/php/g0001_0100/s0076_minimum_window_substring/readme.md @@ -0,0 +1,42 @@ +76\. Minimum Window Substring + +Hard + +Given two strings `s` and `t` of lengths `m` and `n` respectively, return _the **minimum window substring** of_ `s` _such that every character in_ `t` _(**including duplicates**) is included in the window. If there is no such substring__, return the empty string_ `""`_._ + +The testcases will be generated such that the answer is **unique**. + +A **substring** is a contiguous sequence of characters within the string. + +**Example 1:** + +**Input:** s = "ADOBECODEBANC", t = "ABC" + +**Output:** "BANC" + +**Explanation:** The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t. + +**Example 2:** + +**Input:** s = "a", t = "a" + +**Output:** "a" + +**Explanation:** The entire string s is the minimum window. + +**Example 3:** + +**Input:** s = "a", t = "aa" + +**Output:** "" + +**Explanation:** Both 'a's from t must be included in the window. Since the largest window of s only has one 'a', return empty string. + +**Constraints:** + +* `m == s.length` +* `n == t.length` +* 1 <= m, n <= 105 +* `s` and `t` consist of uppercase and lowercase English letters. + +**Follow up:** Could you find an algorithm that runs in `O(m + n)` time? \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0078_subsets/Solution.php b/src/main/php/g0001_0100/s0078_subsets/Solution.php new file mode 100644 index 0000000..3b97ae6 --- /dev/null +++ b/src/main/php/g0001_0100/s0078_subsets/Solution.php @@ -0,0 +1,28 @@ +solve($nums, array(), $res, 0); + return $res; + } + + private function solve($nums, $temp, &$res, $start) { + array_push($res, $temp); + for ($i = $start; $i < count($nums); $i++) { + array_push($temp, $nums[$i]); + $this->solve($nums, $temp, $res, $i + 1); + array_pop($temp); + } + } +} diff --git a/src/main/php/g0001_0100/s0078_subsets/readme.md b/src/main/php/g0001_0100/s0078_subsets/readme.md new file mode 100644 index 0000000..2bd42ee --- /dev/null +++ b/src/main/php/g0001_0100/s0078_subsets/readme.md @@ -0,0 +1,25 @@ +78\. Subsets + +Medium + +Given an integer array `nums` of **unique** elements, return _all possible subsets (the power set)_. + +The solution set **must not** contain duplicate subsets. Return the solution in **any order**. + +**Example 1:** + +**Input:** nums = [1,2,3] + +**Output:** [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] + +**Example 2:** + +**Input:** nums = [0] + +**Output:** [[],[0]] + +**Constraints:** + +* `1 <= nums.length <= 10` +* `-10 <= nums[i] <= 10` +* All the numbers of `nums` are **unique**. \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0079_word_search/Solution.php b/src/main/php/g0001_0100/s0079_word_search/Solution.php new file mode 100644 index 0000000..e01f3cb --- /dev/null +++ b/src/main/php/g0001_0100/s0079_word_search/Solution.php @@ -0,0 +1,70 @@ + $items) { + foreach ($items as $colIdx => $item) { + if ($item === $word[0]) { + $positions[] = [$rowIdx, $colIdx]; + } + if (isset($wordCountMap[$item])) { + $wordCountMap[$item]--; + } + } + } + foreach ($wordCountMap as $count) { + if ($count > 0) { + return false; + } + } + foreach ($positions as $position) { + if ($this->dfs($board, $word, 0, $position)) { + return true; + } + } + return false; + } + + function dfs($board, $word, $index, $position) { + [$x, $y] = $position; + if (!isset($board[$x][$y])) { + return false; + } + if ($board[$x][$y] !== $word[$index]) { + return false; + } elseif ($index === strlen($word) - 1) { + return true; + } + $board[$x][$y] = '-1'; + $dirs = [[0, 1], [0, -1], [1, 0], [-1, 0]]; + foreach ($dirs as $dir) { + $newX = $x + $dir[0]; + $newY = $y + $dir[1]; + if ($this->dfs($board, $word, $index + 1, [$newX, $newY])) { + return true; + } + } + return false; + } +} diff --git a/src/main/php/g0001_0100/s0079_word_search/readme.md b/src/main/php/g0001_0100/s0079_word_search/readme.md new file mode 100644 index 0000000..0500297 --- /dev/null +++ b/src/main/php/g0001_0100/s0079_word_search/readme.md @@ -0,0 +1,41 @@ +79\. Word Search + +Medium + +Given an `m x n` grid of characters `board` and a string `word`, return `true` _if_ `word` _exists in the grid_. + +The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/04/word2.jpg) + +**Input:** board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED" + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/04/word-1.jpg) + +**Input:** board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE" + +**Output:** true + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2020/10/15/word3.jpg) + +**Input:** board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB" + +**Output:** false + +**Constraints:** + +* `m == board.length` +* `n = board[i].length` +* `1 <= m, n <= 6` +* `1 <= word.length <= 15` +* `board` and `word` consists of only lowercase and uppercase English letters. + +**Follow up:** Could you use search pruning to make your solution faster with a larger `board`? \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.php b/src/main/php/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.php new file mode 100644 index 0000000..1eaeba5 --- /dev/null +++ b/src/main/php/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.php @@ -0,0 +1,73 @@ +largestArea($heights, 0, count($heights)); + } + + private function largestArea($a, $start, $limit) { + if ($a == null || empty($a)) { + return 0; + } + if ($start == $limit) { + return 0; + } + if ($limit - $start == 1) { + return $a[$start]; + } + if ($limit - $start == 2) { + $maxOfTwoBars = max($a[$start], $a[$start + 1]); + $areaFromTwo = min($a[$start], $a[$start + 1]) * 2; + return max($maxOfTwoBars, $areaFromTwo); + } + if ($this->checkIfSorted($a, $start, $limit)) { + $maxWhenSorted = 0; + for ($i = $start; $i < $limit; $i++) { + if ($a[$i] * ($limit - $i) > $maxWhenSorted) { + $maxWhenSorted = $a[$i] * ($limit - $i); + } + } + return $maxWhenSorted; + } else { + $minInd = $this->findMinInArray($a, $start, $limit); + return $this->maxOfThreeNums( + $this->largestArea($a, $start, $minInd), + $a[$minInd] * ($limit - $start), + $this->largestArea($a, $minInd + 1, $limit)); + } + } + + private function findMinInArray($a, $start, $limit) { + $min = PHP_INT_MAX; + $minIndex = -1; + for ($index = $start; $index < $limit; $index++) { + if ($a[$index] < $min) { + $min = $a[$index]; + $minIndex = $index; + } + } + return $minIndex; + } + + private function checkIfSorted($a, $start, $limit) { + for ($i = $start + 1; $i < $limit; $i++) { + if ($a[$i] < $a[$i - 1]) { + return false; + } + } + return true; + } + + private function maxOfThreeNums($a, $b, $c) { + return max(max($a, $b), $c); + } +} diff --git a/src/main/php/g0001_0100/s0084_largest_rectangle_in_histogram/readme.md b/src/main/php/g0001_0100/s0084_largest_rectangle_in_histogram/readme.md new file mode 100644 index 0000000..96ca2d0 --- /dev/null +++ b/src/main/php/g0001_0100/s0084_largest_rectangle_in_histogram/readme.md @@ -0,0 +1,28 @@ +84\. Largest Rectangle in Histogram + +Hard + +Given an array of integers `heights` representing the histogram's bar height where the width of each bar is `1`, return _the area of the largest rectangle in the histogram_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/01/04/histogram.jpg) + +**Input:** heights = [2,1,5,6,2,3] + +**Output:** 10 + +**Explanation:** The above is a histogram where width of each bar is 1. The largest rectangle is shown in the red area, which has an area = 10 units. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/01/04/histogram-1.jpg) + +**Input:** heights = [2,4] + +**Output:** 4 + +**Constraints:** + +* 1 <= heights.length <= 105 +* 0 <= heights[i] <= 104 \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.php b/src/main/php/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.php new file mode 100644 index 0000000..e7b8146 --- /dev/null +++ b/src/main/php/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.php @@ -0,0 +1,48 @@ +val = $val; + * $this->left = $left; + * $this->right = $right; + * } + * } + */ +class Solution { + /** + * @param TreeNode $root + * @return Integer[] + */ + public function inorderTraversal($root) { + if ($root == null) { + return array(); + } + $answer = array(); + $this->inorderTraversalLocal($root, $answer); + return $answer; + } + + function inorderTraversalLocal($root, &$answer) { + if ($root == null) { + return; + } + if ($root->left != null) { + $this->inorderTraversalLocal($root->left, $answer); + } + array_push($answer, $root->val); + if ($root->right != null) { + $this->inorderTraversalLocal($root->right, $answer); + } + } +} diff --git a/src/main/php/g0001_0100/s0094_binary_tree_inorder_traversal/readme.md b/src/main/php/g0001_0100/s0094_binary_tree_inorder_traversal/readme.md new file mode 100644 index 0000000..5068d01 --- /dev/null +++ b/src/main/php/g0001_0100/s0094_binary_tree_inorder_traversal/readme.md @@ -0,0 +1,48 @@ +94\. Binary Tree Inorder Traversal + +Easy + +Given the `root` of a binary tree, return _the inorder traversal of its nodes' values_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/09/15/inorder_1.jpg) + +**Input:** root = [1,null,2,3] + +**Output:** [1,3,2] + +**Example 2:** + +**Input:** root = [] + +**Output:** [] + +**Example 3:** + +**Input:** root = [1] + +**Output:** [1] + +**Example 4:** + +![](https://assets.leetcode.com/uploads/2020/09/15/inorder_5.jpg) + +**Input:** root = [1,2] + +**Output:** [2,1] + +**Example 5:** + +![](https://assets.leetcode.com/uploads/2020/09/15/inorder_4.jpg) + +**Input:** root = [1,null,2] + +**Output:** [1,2] + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 100]`. +* `-100 <= Node.val <= 100` + +**Follow up:** Recursive solution is trivial, could you do it iteratively? \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0096_unique_binary_search_trees/Solution.php b/src/main/php/g0001_0100/s0096_unique_binary_search_trees/Solution.php new file mode 100644 index 0000000..0e1d1e1 --- /dev/null +++ b/src/main/php/g0001_0100/s0096_unique_binary_search_trees/Solution.php @@ -0,0 +1,23 @@ +val = $val; + * $this->left = $left; + * $this->right = $right; + * } + * } + */ +class Solution { + /** + * @param TreeNode $root + * @return Boolean + */ + public function isValidBST($root) { + return $this->solve($root, PHP_INT_MIN, PHP_INT_MAX); + } + + private function solve($root, $left, $right) { + if ($root == null) { + return true; + } + if ($root->val <= $left || $root->val >= $right) { + return false; + } + return $this->solve($root->left, $left, $root->val) && $this->solve($root->right, $root->val, $right); + } +} diff --git a/src/main/php/g0001_0100/s0098_validate_binary_search_tree/readme.md b/src/main/php/g0001_0100/s0098_validate_binary_search_tree/readme.md new file mode 100644 index 0000000..a65734a --- /dev/null +++ b/src/main/php/g0001_0100/s0098_validate_binary_search_tree/readme.md @@ -0,0 +1,34 @@ +98\. Validate Binary Search Tree + +Medium + +Given the `root` of a binary tree, _determine if it is a valid binary search tree (BST)_. + +A **valid BST** is defined as follows: + +* The left subtree of a node contains only nodes with keys **less than** the node's key. +* The right subtree of a node contains only nodes with keys **greater than** the node's key. +* Both the left and right subtrees must also be binary search trees. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/12/01/tree1.jpg) + +**Input:** root = [2,1,3] + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/12/01/tree2.jpg) + +**Input:** root = [5,1,4,null,null,3,6] + +**Output:** false + +**Explanation:** The root node's value is 5 but its right child's value is 4. + +**Constraints:** + +* The number of nodes in the tree is in the range [1, 104]. +* -231 <= Node.val <= 231 - 1 \ No newline at end of file diff --git a/src/test/php/g0001_0100/s0073_set_matrix_zeroes/SolutionTest.php b/src/test/php/g0001_0100/s0073_set_matrix_zeroes/SolutionTest.php new file mode 100644 index 0000000..f0d6a4d --- /dev/null +++ b/src/test/php/g0001_0100/s0073_set_matrix_zeroes/SolutionTest.php @@ -0,0 +1,21 @@ +setZeroes($matrix); + $this->assertEquals([[1, 0, 1], [0, 0, 0], [1, 0, 1]], $matrix); + } + + public function testSetZeroes2() { + $matrix = [[0, 1, 2, 0], [3, 4, 5, 2], [1, 3, 1, 5]]; + $solution = new Solution(); + $solution->setZeroes($matrix); + $this->assertEquals([[0, 0, 0, 0], [0, 4, 5, 0], [0, 3, 1, 0]], $matrix); + } +} diff --git a/src/test/php/g0001_0100/s0074_search_a_2d_matrix/SolutionTest.php b/src/test/php/g0001_0100/s0074_search_a_2d_matrix/SolutionTest.php new file mode 100644 index 0000000..e343a5a --- /dev/null +++ b/src/test/php/g0001_0100/s0074_search_a_2d_matrix/SolutionTest.php @@ -0,0 +1,19 @@ +assertEquals(true, $solution->searchMatrix($input, 3)); + } + + public function testSearchMatrix2() { + $input = [[1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 60]]; + $solution = new Solution(); + $this->assertEquals(false, $solution->searchMatrix($input, 13)); + } +} diff --git a/src/test/php/g0001_0100/s0075_sort_colors/SolutionTest.php b/src/test/php/g0001_0100/s0075_sort_colors/SolutionTest.php new file mode 100644 index 0000000..862a3e2 --- /dev/null +++ b/src/test/php/g0001_0100/s0075_sort_colors/SolutionTest.php @@ -0,0 +1,21 @@ +sortColors($array); + $this->assertEquals([0, 0, 1, 1, 2, 2], $array); + } + + public function testSortColors2() { + $array = [2, 0, 1]; + $solution = new Solution(); + $solution->sortColors($array); + $this->assertEquals([0, 1, 2], $array); + } +} diff --git a/src/test/php/g0001_0100/s0076_minimum_window_substring/SolutionTest.php b/src/test/php/g0001_0100/s0076_minimum_window_substring/SolutionTest.php new file mode 100644 index 0000000..1eb610f --- /dev/null +++ b/src/test/php/g0001_0100/s0076_minimum_window_substring/SolutionTest.php @@ -0,0 +1,22 @@ +assertEquals("BANC", $solution->minWindow("ADOBECODEBANC", "ABC")); + } + + public function testMinWindow2() { + $solution = new Solution(); + $this->assertEquals("a", $solution->minWindow("a", "a")); + } + + public function testMinWindow3() { + $solution = new Solution(); + $this->assertEquals("", $solution->minWindow("a", "aa")); + } +} diff --git a/src/test/php/g0001_0100/s0078_subsets/SolutionTest.php b/src/test/php/g0001_0100/s0078_subsets/SolutionTest.php new file mode 100644 index 0000000..067a7f3 --- /dev/null +++ b/src/test/php/g0001_0100/s0078_subsets/SolutionTest.php @@ -0,0 +1,19 @@ +assertEquals($expected, $solution->subsets([1, 2, 3])); + } + + public function testSubsets2() { + $expected = [[], [0]]; + $solution = new Solution(); + $this->assertEquals($expected, $solution->subsets([0])); + } +} diff --git a/src/test/php/g0001_0100/s0079_word_search/SolutionTest.php b/src/test/php/g0001_0100/s0079_word_search/SolutionTest.php new file mode 100644 index 0000000..4cdc49e --- /dev/null +++ b/src/test/php/g0001_0100/s0079_word_search/SolutionTest.php @@ -0,0 +1,25 @@ +assertEquals(true, $solution->exist($input, "ABCCED")); + } + + public function testExist2() { + $input = [['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']]; + $solution = new Solution(); + $this->assertEquals(true, $solution->exist($input, "SEE")); + } + + public function testExist3() { + $input = [['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']]; + $solution = new Solution(); + $this->assertEquals(false, $solution->exist($input, "ABCB")); + } +} diff --git a/src/test/php/g0001_0100/s0084_largest_rectangle_in_histogram/SolutionTest.php b/src/test/php/g0001_0100/s0084_largest_rectangle_in_histogram/SolutionTest.php new file mode 100644 index 0000000..36fd60e --- /dev/null +++ b/src/test/php/g0001_0100/s0084_largest_rectangle_in_histogram/SolutionTest.php @@ -0,0 +1,17 @@ +assertEquals(10, $solution->largestRectangleArea([2, 1, 5, 6, 2, 3])); + } + + public function testLargestRectangleArea2() { + $solution = new Solution(); + $this->assertEquals(4, $solution->largestRectangleArea([2, 4])); + } +} diff --git a/src/test/php/g0001_0100/s0094_binary_tree_inorder_traversal/SolutionTest.php b/src/test/php/g0001_0100/s0094_binary_tree_inorder_traversal/SolutionTest.php new file mode 100644 index 0000000..b3c5414 --- /dev/null +++ b/src/test/php/g0001_0100/s0094_binary_tree_inorder_traversal/SolutionTest.php @@ -0,0 +1,27 @@ +right = $treeNode2; + $treeNode2->left = new TreeNode(3); + $solution = new Solution(); + $this->assertEquals("[1,3,2]", json_encode($solution->inorderTraversal($treeNode))); + } + + public function testInorderTraversal2() { + $solution = new Solution(); + $this->assertEquals("[]", json_encode($solution->inorderTraversal(null))); + } + + public function testInorderTraversal3() { + $solution = new Solution(); + $this->assertEquals("[1]", json_encode($solution->inorderTraversal(new TreeNode(1)))); + } +} diff --git a/src/test/php/g0001_0100/s0096_unique_binary_search_trees/SolutionTest.php b/src/test/php/g0001_0100/s0096_unique_binary_search_trees/SolutionTest.php new file mode 100644 index 0000000..6d625be --- /dev/null +++ b/src/test/php/g0001_0100/s0096_unique_binary_search_trees/SolutionTest.php @@ -0,0 +1,17 @@ +assertEquals(5, $solution->numTrees(3)); + } + + public function testNumTrees2() { + $solution = new Solution(); + $this->assertEquals(1, $solution->numTrees(1)); + } +} diff --git a/src/test/php/g0001_0100/s0098_validate_binary_search_tree/SolutionTest.php b/src/test/php/g0001_0100/s0098_validate_binary_search_tree/SolutionTest.php new file mode 100644 index 0000000..0052fd9 --- /dev/null +++ b/src/test/php/g0001_0100/s0098_validate_binary_search_tree/SolutionTest.php @@ -0,0 +1,26 @@ +left = new TreeNode(1); + $treeNode1->right = new TreeNode(3); + $solution = new Solution(); + $this->assertEquals(true, $solution->isValidBST($treeNode1)); + } + + public function testIsValidBST2() { + $treeNode = new TreeNode(5); + $treeNode->left = new TreeNode(1); + $treeNode->right = new TreeNode(4); + $treeNode->right->left = new TreeNode(3); + $treeNode->right->right = new TreeNode(6); + $solution = new Solution(); + $this->assertEquals(false, $solution->isValidBST($treeNode)); + } +}