Skip to content

Commit 9b05996

Browse files
committed
update java cheatsheet
1 parent 1693f0e commit 9b05996

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

doc/cheatsheet/java_trick.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,23 @@ Arrays.sort(map.keySet().toArray());
679679
Arrays.sort(tmp, (x, y) -> Integer.compare(-x[1], -y[1]));
680680
```
681681

682+
- `floorEntry` method in `TreeMap`
683+
- https://blog.csdn.net/a1510841693/article/details/124323418
684+
- floorEntry() : It returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.
685+
686+
```java
687+
// floorEntry
688+
// LC 1146
689+
690+
// ...
691+
TreeMap<Integer, Integer>[] historyRecords;
692+
// ...
693+
public int get(int index, int snapId) {
694+
return historyRecords[index].floorEntry(snapId).getValue();
695+
}
696+
// ...
697+
```
698+
682699
### 1-10) Get max val from an Array
683700
```java
684701
// java

0 commit comments

Comments
 (0)