Skip to content

Commit

Permalink
update 659 java
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Sep 10, 2024
1 parent 453dfad commit 66dbec9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@
621 | [Task Scheduler](https://leetcode.com/problems/task-scheduler/) | [Python](./leetcode_python/Greedy/task-scheduler.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Greedy/TaskScheduler.java) | _O(n)_ | _O(1)_ | Medium |`trick`,`array`,`greedy`, `fb`, `amazon` | AGAIN****** (7)
646 | [Maximum Length of Pair Chain](https://leetcode.com/problems/maximum-length-of-pair-chain/) | [Python](./leetcode_python/Greedy/maximum-length-of-pair-chain.py) | _O(nlogn)_ | _O(1)_ | Medium | good trick, greedy, similar as `#435 Non-overlapping Intervals`, Line Sweep, `amazon` | OK********** (5) (but again)
649 | [Dota2 Senate](https://leetcode.com/problems/dota2-senate/) | [Python](./leetcode_python/Greedy/dota2-senate.py) | _O(n)_ | _O(n)_ | Medium | complex question | AGAIN (not start*)
659 | [Split Array into Consecutive Subsequences](https://leetcode.com/problems/split-array-into-consecutive-subsequences/) | [Python](./leetcode_python/Greedy/split-array-into-consecutive-subsequences.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Greedy/SplitArrayIntoConsecutiveSubsequences.java) | _O(n)_ | _O(1)_ | Medium | `google`| AGAIN (not start*)
659 | [Split Array into Consecutive Subsequences](https://leetcode.com/problems/split-array-into-consecutive-subsequences/) | [Python](./leetcode_python/Greedy/split-array-into-consecutive-subsequences.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Greedy/SplitArrayIntoConsecutiveSubsequences.java) | _O(n)_ | _O(1)_ | Medium | map, pq, greedy, dp, `google`| AGAIN***** (1)
738 | [Monotone Increasing Digits](https://leetcode.com/problems/monotone-increasing-digits/) | [Python](./leetcode_python/Greedy/monotone-increasing-digits.py) | _O(1)_ | _O(1)_ | Medium | good trick, greedy, string, trick, `Amazon`| AGAIN********* (4)
763 | [Partition Labels](https://leetcode.com/problems/partition-labels/) | [Python](./leetcode_python/Greedy/partition-labels.py) | _O(n)_ | _O(n)_ | Medium |greedy,trick,dict,index,`amazon`| AGAIN******* (5) (AGAIN)
767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./leetcode_python/Greedy/reorganize-string.py) | _O(n)_ | _O(1)_ | Medium |`greedy`,`counter`,`good trick`,`amazon`,`fb`| AGAIN**************** (7) (MUST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
public class SplitArrayIntoConsecutiveSubsequences {

// V0
// TODO : implement
// public boolean isPossible(int[] nums) {
//
// }
Expand All @@ -68,6 +69,8 @@ public boolean isPossible_1(int[] nums) {
for (int num : nums) increaseCount(notPlacedCount, num);

for (int num : nums) {

// NOTE !!! below conditions
boolean alreadyContains = notPlacedCount.get(num) == 0;
boolean canAddToExisting = sequenceEndCount.getOrDefault(num - 1, 0) > 0;
boolean canAddNewSequence = notPlacedCount.getOrDefault(num + 1, 0) > 0 && notPlacedCount.getOrDefault(num + 2, 0) > 0;
Expand Down

0 comments on commit 66dbec9

Please sign in to comment.