Skip to content

Commit a6ff14a

Browse files
committed
feat: update solutions to lcof problem: No.40
1 parent b1c2795 commit a6ff14a

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

.github/workflows/prettier.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
ref: ${{ github.head_ref }}
1616

1717
- name: Prettify code
18-
uses: creyD/prettier_action@v3.0
18+
uses: creyD/prettier_action@v3.3
1919
with:
2020
prettier_options: --write **/*.{js,c,cpp,go,rb,java,cs,py,scala,md}
2121
commit_message: 'style: prettify code'

lcof/面试题40. 最小的k个数/README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ class Solution {
5454
for (int e : arr) {
5555
if (bigRoot.size() < k) {
5656
bigRoot.offer(e);
57-
} else {
58-
if (e < bigRoot.peek()) {
59-
bigRoot.poll();
60-
bigRoot.offer(e);
61-
}
57+
} else if (e < bigRoot.peek()) {
58+
bigRoot.poll();
59+
bigRoot.offer(e);
6260
}
6361
}
6462
int[] res = new int[k];

lcof/面试题40. 最小的k个数/Solution.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ public int[] getLeastNumbers(int[] arr, int k) {
77
for (int e : arr) {
88
if (bigRoot.size() < k) {
99
bigRoot.offer(e);
10-
} else {
11-
if (e < bigRoot.peek()) {
12-
bigRoot.poll();
13-
bigRoot.offer(e);
14-
}
10+
} else if (e < bigRoot.peek()) {
11+
bigRoot.poll();
12+
bigRoot.offer(e);
1513
}
1614
}
1715
int[] res = new int[k];

0 commit comments

Comments
 (0)