File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11 Expand file tree Collapse file tree 2 files changed +29
-4
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 {
@@ -9,14 +10,29 @@ public class Lesson11 {
910 * https://leetcode.com/problems/concatenation-of-array
1011 */
1112 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 ;
1322 }
1423
1524 /**
1625 * Provide the solution to LeetCode 2942 here:
1726 * https://leetcode.com/problems/find-words-containing-character/
1827 */
1928 public List <Integer > findWordsContaining (String [] words , char x ) {
20- return null ;
29+ List <Integer > result = new ArrayList ();
30+
31+ for (int i = 0 ; i < words .length ; i ++) {
32+ if (words [i ].contains (x +"" )) {
33+ result .add (i );
34+ }
35+ }
36+ return result ;
2137 }
2238}
Original file line number Diff line number Diff line change 33 * https://leetcode.com/problems/concatenation-of-array
44 */
55export function getConcatenation ( nums : number [ ] ) : number [ ] {
6- return [ ] ;
6+ let combinedArr = nums . concat ( nums ) ;
7+ return combinedArr ;
78}
89
910/**
1011 * Provide the solution to LeetCode 2942 here:
1112 * https://leetcode.com/problems/find-words-containing-character/
1213 */
1314export function findWordsContaining ( words : string [ ] , x : string ) : number [ ] {
14- return [ ] ;
15+ let result : number [ ] = [ ] ;
16+
17+ for ( let i = 0 ; i < words . length ; i ++ ) {
18+ if ( words [ i ] . includes ( x ) ) {
19+ result . push ( i ) ;
20+ }
21+ }
22+
23+ return result ;
1524}
You can’t perform that action at this time.
0 commit comments