Skip to content

Commit

Permalink
add 300 java, update progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Mar 12, 2024
1 parent d492a73 commit a727ea4
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@
222| [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes/) | [Python](./leetcode_python/Binary_Search/count-complete-tree-nodes.py) | _O((logn)^2)_ | _O(1)_ | Medium || AGAIN (not start)
275| [H-Index II](https://leetcode.com/problems/h-index-ii/) | [Python](./leetcode_python/Binary_Search/h-index-ii.py) | _O(logn)_ | _O(1)_ | Medium |similar as `# 274 H-Index`, Binary Search, `fb` | AGAIN**** (3)
278| [First Bad Version](https://leetcode.com/problems/first-bad-version/) | [Python](./leetcode_python/Binary_Search/first-bad-version.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/BinarySearch/FirstBadVersion.java)| _O(logn)_ | _O(1)_ | Easy | `good basic`,LintCode, binary search, `fb` | OK*** (5) (MUST)
300| [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/) | [Python](./leetcode_python/Binary_Search/longest-increasing-subsequence.py) | _O(nlogn)_ | _O(n)_ | Medium |Curated Top 75, array, binary search,`DP good basic`, `binary search`, LintCode, DP,`amazon`,`fb`| AGAIN********** (8)
300| [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/) | [Python](./leetcode_python/Binary_Search/longest-increasing-subsequence.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/BinarySearch/LongestIncreasingSubsequence.java)| _O(nlogn)_ | _O(n)_ | Medium |Curated Top 75, array, binary search,`DP good basic`, `binary search`, LintCode, DP,`amazon`,`fb`| AGAIN********** (9)
367| [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square/)| [Python](./leetcode_python/Binary_Search/valid-perfect-square.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/BinarySearch/ValidPerfectSquare.java) | _O(logn)_ | _O(1)_| Easy | good basic, similar as `# 69 Sqrt(x)` | OK* (3)
374| [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower/)| [Python](./leetcode_python/Binary_Search/guess-number-higher-or-lower.py) | _O(logn)_ | _O(1)_ | Easy | | OK*
410| [Split Array Largest Sum](https://leetcode.com/problems/split-array-largest-sum/)| [Python](./leetcode_python/Binary_Search/split-array-largest-sum.py) | _O(logn)_ | _O(1)_ | Hard | | AGAIN (not start)
Expand Down
2 changes: 1 addition & 1 deletion data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
20240312: 297(again)
20240312: 297(again),300
20240311: 261(again!!!),268,269(again),271,295(again)
20240310: 213,217,226,230,235,238,242,252,253
20240309: 207(again!!!),208,211(again),212
Expand Down
18 changes: 9 additions & 9 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2024-05-06 -> ['297(again)']
2024-05-06 -> ['297(again),300']
2024-05-05 -> ['261(again!!!),268,269(again),271,295(again)']
2024-05-04 -> ['213,217,226,230,235,238,242,252,253']
2024-05-03 -> ['207(again!!!),208,211(again),212']
Expand All @@ -11,7 +11,7 @@
2024-04-24 -> ['39,48(again),49,53,54']
2024-04-23 -> ['20,21,23,33(again)']
2024-04-22 -> ['1,3,5,4,19']
2024-04-15 -> ['297(again)']
2024-04-15 -> ['297(again),300']
2024-04-14 -> ['261(again!!!),268,269(again),271,295(again)']
2024-04-13 -> ['213,217,226,230,235,238,242,252,253']
2024-04-12 -> ['207(again!!!),208,211(again),212']
Expand All @@ -22,27 +22,27 @@
2024-04-07 -> ['73,76,79(again),91,25']
2024-04-06 -> ['55(again),56,62,70']
2024-04-03 -> ['39,48(again),49,53,54']
2024-04-02 -> ['297(again)', '20,21,23,33(again)']
2024-04-02 -> ['297(again),300', '20,21,23,33(again)']
2024-04-01 -> ['261(again!!!),268,269(again),271,295(again)', '1,3,5,4,19']
2024-03-31 -> ['213,217,226,230,235,238,242,252,253']
2024-03-30 -> ['207(again!!!),208,211(again),212']
2024-03-29 -> ['152,153(again),190,191,198,200,206(again)']
2024-03-28 -> ['139(again),141,143(again)']
2024-03-27 -> ['121,124(again),125,128,133(again)']
2024-03-26 -> ['100,102,104,105(again)']
2024-03-25 -> ['297(again)', '73,76,79(again),91,25']
2024-03-25 -> ['297(again),300', '73,76,79(again),91,25']
2024-03-24 -> ['261(again!!!),268,269(again),271,295(again)', '55(again),56,62,70']
2024-03-23 -> ['213,217,226,230,235,238,242,252,253']
2024-03-22 -> ['207(again!!!),208,211(again),212']
2024-03-21 -> ['152,153(again),190,191,198,200,206(again)', '39,48(again),49,53,54']
2024-03-20 -> ['297(again)', '139(again),141,143(again)', '20,21,23,33(again)']
2024-03-20 -> ['297(again),300', '139(again),141,143(again)', '20,21,23,33(again)']
2024-03-19 -> ['261(again!!!),268,269(again),271,295(again)', '121,124(again),125,128,133(again)', '1,3,5,4,19']
2024-03-18 -> ['213,217,226,230,235,238,242,252,253', '100,102,104,105(again)']
2024-03-17 -> ['297(again)', '207(again!!!),208,211(again),212', '73,76,79(again),91,25']
2024-03-17 -> ['297(again),300', '207(again!!!),208,211(again),212', '73,76,79(again),91,25']
2024-03-16 -> ['261(again!!!),268,269(again),271,295(again)', '152,153(again),190,191,198,200,206(again)', '55(again),56,62,70']
2024-03-15 -> ['297(again)', '213,217,226,230,235,238,242,252,253', '139(again),141,143(again)']
2024-03-14 -> ['297(again)', '261(again!!!),268,269(again),271,295(again)', '207(again!!!),208,211(again),212', '121,124(again),125,128,133(again)']
2024-03-13 -> ['297(again)', '261(again!!!),268,269(again),271,295(again)', '213,217,226,230,235,238,242,252,253', '152,153(again),190,191,198,200,206(again)', '100,102,104,105(again)', '39,48(again),49,53,54']
2024-03-15 -> ['297(again),300', '213,217,226,230,235,238,242,252,253', '139(again),141,143(again)']
2024-03-14 -> ['297(again),300', '261(again!!!),268,269(again),271,295(again)', '207(again!!!),208,211(again),212', '121,124(again),125,128,133(again)']
2024-03-13 -> ['297(again),300', '261(again!!!),268,269(again),271,295(again)', '213,217,226,230,235,238,242,252,253', '152,153(again),190,191,198,200,206(again)', '100,102,104,105(again)', '39,48(again),49,53,54']
2024-03-12 -> ['261(again!!!),268,269(again),271,295(again)', '213,217,226,230,235,238,242,252,253', '207(again!!!),208,211(again),212', '139(again),141,143(again)', '73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-11 -> ['213,217,226,230,235,238,242,252,253', '207(again!!!),208,211(again),212', '152,153(again),190,191,198,200,206(again)', '121,124(again),125,128,133(again)', '55(again),56,62,70', '1,3,5,4,19']
2024-03-10 -> ['207(again!!!),208,211(again),212', '152,153(again),190,191,198,200,206(again)', '139(again),141,143(again)', '100,102,104,105(again)']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package LeetCodeJava.BinarySearch;

// https://leetcode.com/problems/longest-increasing-subsequence/description/

import java.util.Arrays;

public class LongestIncreasingSubsequence {

// V0
// TODO : implement it
// public int lengthOfLIS(int[] nums) {
// return 0;
// }

// V1
// IDEA : DP
// https://leetcode.com/problems/longest-increasing-subsequence/solutions/4509493/300/
public int lengthOfLIS_1(int[] nums) {
if(nums == null || nums.length == 0)return 0;
int n=nums.length;
int[] dp=new int[n];
Arrays.fill(dp,1);
for(int i=1;i<n;i++){
for(int j=0;j<i;j++){
if(nums[i]>nums[j]){
dp[i]=Math.max(dp[i],dp[j]+1);
}
}
}
int maxi=1;
for(int len : dp){
maxi=Math.max(maxi,len);
}
return maxi;
}

// V2
// IDEA : BINARY SEARCH
// https://leetcode.com/problems/longest-increasing-subsequence/solutions/4509303/beats-100-binary-search-explained-with-video-c-java-python-js/
public int lengthOfLIS_2(int[] nums) {
int[] tails = new int[nums.length];
int size = 0;
for (int x : nums) {
int i = 0, j = size;
while (i != j) {
int m = (i + j) / 2;
if (tails[m] < x)
i = m + 1;
else
j = m;
}
tails[i] = x;
if (i == size) ++size;
}
return size;
}

// V3
// IDEA : DP
// https://leetcode.com/problems/longest-increasing-subsequence/solutions/4510776/java-solution-explained-in-hindi/
public int lengthOfLIS_3(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}

int n = nums.length;
int[] dp = new int[n];
Arrays.fill(dp, 1);

for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
if (nums[i] > nums[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
}

int maxLength = 0;
for (int len : dp) {
maxLength = Math.max(maxLength, len);
}
return maxLength;
}

}

0 comments on commit a727ea4

Please sign in to comment.