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

Commit70d9082

Browse files
Merge pull requestneetcode-gh#308 from SharmaTushar1/patch-5
Create 448-Find-All-Numbers-Disappeared-in-an-Array.java
2 parents29f1c24 +b96c1bd commit70d9082

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Since the array has values form 0 to n we can use in-place sorting that's O(N) time and constant space.
2+
classSolution {
3+
publicList<Integer>findDisappearedNumbers(int[]nums) {
4+
List<Integer>list =newArrayList<>();
5+
for (inti =0;i<nums.length;i++) {
6+
intcorrect =nums[i]-1;
7+
if (nums[i]!=nums[correct] &&nums[correct]!=nums[i]) {
8+
inttemp =nums[i];
9+
nums[i] =nums[correct];
10+
nums[correct] =temp;
11+
i--;
12+
}
13+
}
14+
for (inti =0;i<nums.length;i++) {
15+
if (nums[i]-1!=i)
16+
list.add(i+1);
17+
}
18+
returnlist;
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp