Skip to content

Commit

Permalink
Updated tasks 221-338
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanhNIT authored Nov 16, 2024
1 parent 3fe7a5c commit 71e89b7
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 55 deletions.
48 changes: 24 additions & 24 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package g0201_0300.s0221_maximal_square;

// #Medium #Array #Dynamic_Programming #Matrix #Dynamic_Programming_I_Day_16
// #Big_O_Time_O(m*n)_Space_O(m*n) #2022_07_04_Time_7_ms_(72.35%)_Space_59.5_MB_(10.55%)
// #Big_O_Time_O(m*n)_Space_O(m*n) #2024_11_16_Time_6_ms_(97.07%)_Space_60.3_MB_(39.55%)

public class Solution {
public int maximalSquare(char[][] matrix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #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) #2022_07_04_Time_0_ms_(100.00%)_Space_42_MB_(20.73%)
// #Big_O_Time_O(n)_Space_O(n) #2024_11_16_Time_0_ms_(100.00%)_Space_40.6_MB_(95.51%)

import com_github_leetcode.TreeNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Binary_Search_Tree
// #Data_Structure_II_Day_17_Tree #Level_2_Day_9_Binary_Search_Tree #Big_O_Time_O(n)_Space_O(n)
// #2022_07_04_Time_1_ms_(78.91%)_Space_45.3_MB_(58.87%)
// #2024_11_16_Time_0_ms_(100.00%)_Space_44.3_MB_(63.70%)

import com_github_leetcode.TreeNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Easy #Top_100_Liked_Questions #Two_Pointers #Stack #Linked_List #Recursion
// #Level_2_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1)
// #2022_07_04_Time_6_ms_(76.07%)_Space_97.6_MB_(56.14%)
// #2024_11_16_Time_4_ms_(84.46%)_Space_69_MB_(17.17%)

import com_github_leetcode.ListNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree
// #Data_Structure_II_Day_18_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n)
// #2022_07_04_Time_10_ms_(56.51%)_Space_47.4_MB_(45.84%)
// #2024_11_16_Time_6_ms_(100.00%)_Space_44_MB_(98.99%)

import com_github_leetcode.TreeNode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package g0201_0300.s0238_product_of_array_except_self;

// #Medium #Top_100_Liked_Questions #Array #Prefix_Sum #Data_Structure_II_Day_5_Array #Udemy_Arrays
// #Big_O_Time_O(n^2)_Space_O(n) #2022_07_04_Time_1_ms_(100.00%)_Space_50.8_MB_(85.60%)
// #Big_O_Time_O(n^2)_Space_O(n) #2024_11_16_Time_1_ms_(99.66%)_Space_55.1_MB_(79.02%)

public class Solution {
public int[] productExceptSelf(int[] nums) {
int product = 1;
int[] ans = new int[nums.length];
for (int num : nums) {
product = product * num;
}
int[] res = new int[nums.length];
int prefixProduct = 1;
for (int i = 0; i < nums.length; i++) {
if (nums[i] != 0) {
ans[i] = product / nums[i];
} else {
int p = 1;
for (int j = 0; j < nums.length; j++) {
if (j != i) {
p = p * nums[j];
}
}
ans[i] = p;
}
res[i] = prefixProduct;
prefixProduct *= nums[i];
}
int suffixProduct = 1;
for (int i = nums.length - 1; i >= 0; i--) {
res[i] *= suffixProduct;
suffixProduct *= nums[i];
}
return ans;
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Hard #Top_100_Liked_Questions #Array #Heap_Priority_Queue #Sliding_Window #Queue
// #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k)
// #2022_07_04_Time_58_ms_(52.28%)_Space_145_MB_(50.60%)
// #2024_11_16_Time_26_ms_(95.89%)_Space_59.6_MB_(38.70%)

import java.util.LinkedList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Matrix #Divide_and_Conquer
// #Data_Structure_II_Day_4_Array #Binary_Search_II_Day_8 #Big_O_Time_O(n+m)_Space_O(1)
// #2022_07_04_Time_7_ms_(86.73%)_Space_58.4_MB_(9.95%)
// #2024_11_16_Time_5_ms_(99.92%)_Space_45.8_MB_(60.21%)

public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/g0201_0300/s0283_move_zeroes/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Easy #Top_100_Liked_Questions #Array #Two_Pointers #Algorithm_I_Day_3_Two_Pointers
// #Programming_Skills_I_Day_6_Array #Udemy_Arrays #Big_O_Time_O(n)_Space_O(1)
// #2022_07_06_Time_2_ms_(79.54%)_Space_55.7_MB_(5.98%)
// #2024_11_16_Time_2_ms_(83.99%)_Space_45.9_MB_(50.99%)

public class Solution {
public void moveZeroes(int[] nums) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Two_Pointers #Bit_Manipulation
// #Binary_Search_II_Day_5 #Big_O_Time_O(n)_Space_O(n)
// #2022_07_06_Time_2_ms_(99.82%)_Space_61.1_MB_(83.92%)
// #2024_11_16_Time_2_ms_(97.52%)_Space_59.9_MB_(5.22%)

public class Solution {
public int findDuplicate(int[] nums) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package g0201_0300.s0295_find_median_from_data_stream;

// #Hard #Top_100_Liked_Questions #Sorting #Two_Pointers #Design #Heap_Priority_Queue #Data_Stream
// #Big_O_Time_O(n*log_n)_Space_O(n) #2022_07_06_Time_151_ms_(80.24%)_Space_125.2_MB_(44.11%)
// #Big_O_Time_O(n*log_n)_Space_O(n) #2024_11_16_Time_83_ms_(99.56%)_Space_63.4_MB_(77.85%)

import java.util.PriorityQueue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Binary_Search
// #Algorithm_II_Day_16_Dynamic_Programming #Binary_Search_II_Day_3 #Dynamic_Programming_I_Day_18
// #Udemy_Dynamic_Programming #Big_O_Time_O(n*log_n)_Space_O(n)
// #2022_07_06_Time_3_ms_(98.63%)_Space_44.3_MB_(60.27%)
// #2024_11_16_Time_3_ms_(95.75%)_Space_43.7_MB_(93.58%)

public class Solution {
public int lengthOfLIS(int[] nums) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/g0301_0400/s0322_coin_change/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Breadth_First_Search
// #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_20
// #Level_2_Day_12_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(amount)
// #2022_07_09_Time_17_ms_(91.77%)_Space_41.8_MB_(95.50%)
// #2024_11_16_Time_12_ms_(92.59%)_Space_44.3_MB_(64.02%)

public class Solution {
public int coinChange(int[] coins, int amount) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/g0301_0400/s0338_counting_bits/Solution.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package g0301_0400.s0338_counting_bits;

// #Easy #Dynamic_Programming #Bit_Manipulation #Udemy_Bit_Manipulation
// #Big_O_Time_O(num)_Space_O(num) #2022_07_10_Time_2_ms_(86.73%)_Space_48.3_MB_(31.59%)
// #Big_O_Time_O(num)_Space_O(num) #2024_11_16_Time_2_ms_(96.37%)_Space_46.4_MB_(70.53%)

public class Solution {
public int[] countBits(int num) {
Expand Down

0 comments on commit 71e89b7

Please sign in to comment.