Movatterモバイル変換


[0]ホーム

URL:


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

Commit5695ae7

Browse files
authored
Create Minimum Number of Operations to Make Array Continuous.java
1 parentfd343f2 commit5695ae7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
classSolution {
2+
publicintminOperations(int[]nums) {
3+
Set<Integer>set =newHashSet<>();
4+
for (intnum :nums) {
5+
set.add(num);
6+
}
7+
int[]arr =newint[set.size()];
8+
intidx =0;
9+
for (Integernum :set) {
10+
arr[idx++] =num;
11+
}
12+
Arrays.sort(arr);
13+
intn =nums.length;
14+
intresult =n;
15+
intj =0;
16+
for (inti =0;i <arr.length;i++) {
17+
while (j <arr.length &&arr[j] <arr[i] +n) {
18+
j++;
19+
}
20+
intcount =j -i;
21+
result =Math.min(result,n -count);
22+
}
23+
returnresult;
24+
}
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp