File tree Expand file tree Collapse file tree 2 files changed +39
-18
lines changed
arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11 Expand file tree Collapse file tree 2 files changed +39
-18
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
- * Provide the solution to LeetCode 1929 here:
9
- * https://leetcode.com/problems/concatenation-of-array
10
- */
11
8
public int [] getConcatenation (int [] nums ) {
12
- return null ;
9
+ int answer [] = new int [nums .length * 2 ];
10
+ for (int i = 0 ; i < nums .length ; i ++) {
11
+ answer [i ] = nums [i ];
12
+ answer [i + nums .length ] = nums [i ];
13
+ }
14
+ return answer ;
13
15
}
14
16
15
- /**
16
- * Provide the solution to LeetCode 2942 here:
17
- * https://leetcode.com/problems/find-words-containing-character/
18
- */
19
17
public List <Integer > findWordsContaining (String [] words , char x ) {
20
- return null ;
18
+ var result = new ArrayList <Integer >();
19
+ for (int i = 0 ; i < words .length ; i ++) {
20
+ if (words [i ].contains (String .valueOf (x ))) {
21
+ result .add (i );
22
+ }
23
+ }
24
+ return result ;
21
25
}
22
26
}
Original file line number Diff line number Diff line change 1
- /**
2
- * Provide the solution to LeetCode 1929 here:
3
- * https://leetcode.com/problems/concatenation-of-array
4
- */
1
+
5
2
export function getConcatenation ( nums : number [ ] ) : number [ ] {
6
- return [ ] ;
7
- }
3
+ if ( nums . length === 0 ) {
4
+ return [ ] ;
5
+ }
6
+ const result = [ ...nums ] ;
7
+ for ( const num of nums ) {
8
+ result . push ( num ) ;
9
+ }
10
+ return result ;
11
+ }
12
+
13
+
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 [ ] ;
15
- }
21
+ if ( words . length === 0 ) {
22
+ return [ ] ;
23
+ }
24
+ const result = [ ] ;
25
+ for ( let i = 0 ; i < words . length ; i ++ ) {
26
+ if ( words [ i ] . includes ( x ) ) {
27
+ result . push ( i ) ;
28
+ }
29
+ }
30
+ return result ;
31
+ }
32
+ //Received help from copiliot and Meiko and Bryana.
You can’t perform that action at this time.
0 commit comments