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