File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed
arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11 Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson11 ;
2
2
3
+ import java .util .ArrayList ;
3
4
import java .util .List ;
4
5
5
6
public class Lesson11 {
@@ -9,14 +10,28 @@ public class Lesson11 {
9
10
* https://leetcode.com/problems/concatenation-of-array
10
11
*/
11
12
public int [] getConcatenation (int [] nums ) {
12
- return null ;
13
+ int n = nums .length ;
14
+ int [] ans = new int [2 * n ];
15
+
16
+ for (int i = 0 ; i < nums .length ; i ++){
17
+ ans [i ] = nums [i ];
18
+ ans [i + n ] = nums [i ];
19
+ }
20
+ return ans ;
13
21
}
14
22
15
23
/**
16
24
* Provide the solution to LeetCode 2942 here:
17
25
* https://leetcode.com/problems/find-words-containing-character/
18
26
*/
19
27
public List <Integer > findWordsContaining (String [] words , char x ) {
20
- return null ;
28
+ List <Integer > indices = new ArrayList <>();
29
+
30
+ for (int i = 0 ; i < words .length ; i ++) {
31
+ if (words [i ].indexOf (x ) != -1 ) {
32
+ indices .add (i );
33
+ }
34
+ }
35
+ return indices ;
21
36
}
22
37
}
Original file line number Diff line number Diff line change 3
3
* https://leetcode.com/problems/concatenation-of-array
4
4
*/
5
5
export function getConcatenation ( nums : number [ ] ) : number [ ] {
6
- return [ ] ;
6
+ const n = nums . length ;
7
+ const ans : number [ ] = new Array ( 2 * n ) ;
8
+
9
+ for ( let i = 0 ; i < n ; i ++ ) {
10
+ ans [ i ] = nums [ i ] ;
11
+ ans [ i + n ] = nums [ i ] ;
12
+ }
13
+ return ans ;
7
14
}
8
15
9
16
/**
10
17
* Provide the solution to LeetCode 2942 here:
11
18
* https://leetcode.com/problems/find-words-containing-character/
12
19
*/
13
20
export function findWordsContaining ( words : string [ ] , x : string ) : number [ ] {
14
- return [ ] ;
21
+ const indices : number [ ] = [ ] ;
22
+
23
+ for ( let i = 0 ; i < words . length ; i ++ ) {
24
+ if ( words [ i ] . includes ( x ) ) {
25
+ indices . push ( i ) ;
26
+ }
27
+ }
28
+ return indices ;
15
29
}
You can’t perform that action at this time.
0 commit comments