File tree 5 files changed +72
-0
lines changed
algorithms/FindAllNumbersDisappearedInAnArray
5 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ All solutions will be accepted!
107
107
| 733| [ Flood Fill] ( https://leetcode-cn.com/problems/flood-fill/description/ ) | [ java/py/js] ( ./algorithms/FloodFill ) | Easy|
108
108
| 110| [ Balanced Binary Tree] ( https://leetcode-cn.com/problems/balanced-binary-tree/description/ ) | [ java/py/js] ( ./algorithms/BalancedBinaryTree ) | Easy|
109
109
| 70| [ Climbing Stairs] ( https://leetcode-cn.com/problems/climbing-stairs/description/ ) | [ java/py/js] ( ./algorithms/ClimbingStairs ) | Easy|
110
+ | 448| [ Find All Numbers Disappeared In An Array] ( https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/description/ ) | [ java/py/js] ( ./algorithms/FindAllNumbersDisappearedInAnArray ) | Easy|
110
111
111
112
# Database
112
113
| #| Title| Solution| Difficulty|
Original file line number Diff line number Diff line change
1
+ # Find All Numbers Disappeared In An Array
2
+ This problem is easy to solve
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public List <Integer > findDisappearedNumbers (int [] nums ) {
3
+ List <Integer > res = new ArrayList <Integer >();
4
+ for (int i = 0 ; i <= nums .length ; i ++) {
5
+ res .add (i );
6
+ }
7
+
8
+ for (int num : nums ) {
9
+ res .set (num , 0 );
10
+ }
11
+
12
+ Iterator iterator = res .iterator ();
13
+ while (iterator .hasNext ()) {
14
+ if ((int ) iterator .next () == 0 ) {
15
+ iterator .remove ();
16
+ }
17
+ }
18
+
19
+ return res ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @return {number[] }
4
+ */
5
+ var findDisappearedNumbers = function ( nums ) {
6
+ let res = [ ]
7
+ for ( let i = 0 ; i <= nums . length ; i ++ ) {
8
+ res . push ( i )
9
+ }
10
+
11
+ nums . forEach ( num => res [ num ] = 0 )
12
+
13
+ let effectiveLength = 0 ,
14
+ pos = 0
15
+
16
+ for ( let i = 0 ; i < res . length ; i ++ ) {
17
+ if ( res [ i ] !== 0 ) {
18
+ res [ pos ] = res [ i ]
19
+ pos ++
20
+ effectiveLength ++
21
+ }
22
+ }
23
+ res . length = effectiveLength
24
+ return res
25
+ } ;
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def findDisappearedNumbers (self , nums ):
3
+ """
4
+ :type nums: List[int]
5
+ :rtype: List[int]
6
+ """
7
+ res = []
8
+ for i in range (len (nums ) + 1 ):
9
+ res .append (i )
10
+
11
+ for num in nums :
12
+ res [num ] = 0
13
+
14
+ # remove 0 to the end
15
+ effective_length = 0
16
+ pos = 0
17
+ for i in range (len (res )):
18
+ if res [i ] != 0 :
19
+ res [pos ] = res [i ]
20
+ pos += 1
21
+ effective_length += 1
22
+
23
+ return res [:effective_length ]
You can’t perform that action at this time.
0 commit comments