Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 873165c

Browse files
add 3254
1 parent 29f7c04 commit 873165c

File tree

2 files changed

+31
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

2 files changed

+31
-0
lines changed

‎paginated_contents/algorithms/4th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
3+
| 3254 | [Find the Power of K-Size Subarrays I](https://leetcode.com/problems/find-the-power-of-k-size-subarrays-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3254.java) | | Easy |
34
| 3249 | [Count the Number of Good Nodes](https://leetcode.com/problems/count-the-number-of-good-nodes/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3249.java) | | Medium |
45
| 3248 | [Snake in Matrix](https://leetcode.com/problems/snake-in-matrix/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3248.java) | | Easy |
56
| 3243 | [Shortest Distance After Road Addition Queries I](https://leetcode.com/problems/shortest-distance-after-road-addition-queries-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3243.java) | | Medium |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import java.util.Arrays;
4+
5+
public class _3254 {
6+
public static class Solution1 {
7+
public int[] resultsArray(int[] nums, int k) {
8+
int n = nums.length;
9+
int[] ans = new int[n - k + 1];
10+
boolean sorted;
11+
if (k == 1) {
12+
return nums;
13+
}
14+
Arrays.fill(ans, -1);
15+
for (int i = 0; i <= n - k; i++) {
16+
sorted = true;
17+
for (int j = i + 1; j < i + k; j++) {
18+
if (nums[j] != nums[j - 1] + 1) {
19+
sorted = false;
20+
break;
21+
}
22+
}
23+
if (sorted) {
24+
ans[i] = nums[i + k - 1];
25+
}
26+
}
27+
return ans;
28+
}
29+
}
30+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /