File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed
arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11 Expand file tree Collapse file tree 2 files changed +27
-6
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 {
6
7
7
8
/**
8
- * Provide the solution to LeetCode 1929 here:
9
+ * Solution to LeetCode problem: Concatenation of Array
9
10
* https://leetcode.com/problems/concatenation-of-array
10
11
*/
11
12
public int [] getConcatenation (int [] nums ) {
12
- return null ;
13
+ int size = nums .length ;
14
+
15
+ int [] result = new int [size * 2 ];
16
+
17
+ for (int i = 0 ; i < size * 2 ; i ++) {
18
+ result [i ] = nums [i % size ];
19
+ }
20
+
21
+ return result ;
13
22
}
14
23
15
24
/**
16
- * Provide the solution to LeetCode 2942 here:
25
+ * Solution to LeetCode problem: Find Words Containing Character
17
26
* https://leetcode.com/problems/find-words-containing-character/
18
27
*/
19
28
public List <Integer > findWordsContaining (String [] words , char x ) {
20
- return null ;
29
+ List <Integer > result = new ArrayList <>();
30
+
31
+ String searchChar = String .valueOf (x );
32
+
33
+ for (int i = 0 ; i < words .length ; i ++) {
34
+ if (words [i ].contains (searchChar )) {
35
+ result .add (i );
36
+ }
37
+ }
38
+
39
+ return result ;
21
40
}
22
41
}
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
+ return [ ... nums , ... nums ] ;
7
7
}
8
8
9
9
/**
10
10
* Provide the solution to LeetCode 2942 here:
11
11
* https://leetcode.com/problems/find-words-containing-character/
12
12
*/
13
13
export function findWordsContaining ( words : string [ ] , x : string ) : number [ ] {
14
- return [ ] ;
14
+ return words
15
+ . map ( ( word , index ) => ( word . includes ( x ) ? index : - 1 ) )
16
+ . filter ( index => index !== - 1 ) ;
15
17
}
You can’t perform that action at this time.
0 commit comments