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