Skip to content

Commit f50c499

Browse files
refactor 699
1 parent 8af3b5a commit f50c499

File tree

1 file changed

+3
-66
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-66
lines changed

src/main/java/com/fishercoder/solutions/_699.java

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,11 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
/**
7-
* 699. Falling Squares
8-
*
9-
* On an infinite number line (x-axis), we drop given squares in the order they are given.
10-
* The i-th square dropped (positions[i] = (left, side_length)) is a
11-
* square with the left-most point being positions[i][0] and sidelength positions[i][1].
12-
* The square is dropped with the bottom edge parallel to the number line, and
13-
* from a higher height than all currently landed squares. We wait for each square to stick before dropping the next.
14-
* The squares are infinitely sticky on their bottom edge, and will
15-
* remain fixed to any positive length surface they touch (either the number line or another square).
16-
* Squares dropped adjacent to each other will not stick together prematurely.
17-
* Return a list ans of heights.
18-
* Each height ans[i] represents the current highest height of any square we have dropped,
19-
* after dropping squares represented by positions[0], positions[1], ..., positions[i].
20-
21-
Example 1:
22-
23-
Input: [[1, 2], [2, 3], [6, 1]]
24-
Output: [2, 5, 5]
25-
Explanation:
26-
27-
28-
After the first drop of positions[0] = [1, 2]:
29-
_aa
30-
_aa
31-
-------
32-
The maximum height of any square is 2.
33-
34-
35-
After the second drop of positions[1] = [2, 3]:
36-
__aaa
37-
__aaa
38-
__aaa
39-
_aa__
40-
_aa__
41-
--------------
42-
The maximum height of any square is 5.
43-
The larger square stays on top of the smaller square despite where its center
44-
of gravity is, because squares are infinitely sticky on their bottom edge.
45-
46-
47-
After the third drop of positions[1] = [6, 1]:
48-
__aaa
49-
__aaa
50-
__aaa
51-
_aa
52-
_aa___a
53-
--------------
54-
The maximum height of any square is still 5.
55-
56-
Thus, we return an answer of [2, 5, 5].
57-
58-
59-
Example 2:
60-
61-
Input: [[100, 100], [200, 100]]
62-
Output: [100, 100]
63-
Explanation: Adjacent squares don't get stuck prematurely - only their bottom edge can stick to surfaces.
64-
65-
Note:
66-
1 <= positions.length <= 1000.
67-
1 <= positions[0] <= 10^8.
68-
1 <= positions[1] <= 10^6.
69-
*/
70-
716
public class _699 {
727
public static class Solution1 {
73-
/**credit: https://discuss.leetcode.com/topic/107107/easy-understood-o-n-2-solution-with-explanation*/
8+
/**
9+
* credit: https://discuss.leetcode.com/topic/107107/easy-understood-o-n-2-solution-with-explanation
10+
*/
7411
public List<Integer> fallingSquares(int[][] positions) {
7512
List<Interval> intervals = new ArrayList<>();
7613
List<Integer> result = new ArrayList<>();

0 commit comments

Comments
 (0)