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 11package com .codedifferently .lesson11 ;
22
3+ import java .util .ArrayList ;
34import java .util .List ;
45
56public class Lesson11 {
67
7- /**
8- * Provide the solution to LeetCode 1929 here:
9- * https://leetcode.com/problems/concatenation-of-array
10- */
118 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 ;
1315 }
1416
15- /**
16- * Provide the solution to LeetCode 2942 here:
17- * https://leetcode.com/problems/find-words-containing-character/
18- */
1917 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 ;
2125 }
2226}
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+
52export 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+
815
916/**
1017 * Provide the solution to LeetCode 2942 here:
1118 * https://leetcode.com/problems/find-words-containing-character/
1219 */
1320export 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