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 11package com .codedifferently .lesson11 ;
22
3+ import java .util .ArrayList ;
34import java .util .List ;
45
56public class Lesson11 {
67
78 /**
8- * Provide the solution to LeetCode 1929 here:
9+ * Solution to LeetCode problem: Concatenation of Array
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 /**
16- * Provide the solution to LeetCode 2942 here:
25+ * Solution to LeetCode problem: Find Words Containing Character
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+ 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 ;
2140 }
2241}
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+ return [ ... nums , ... nums ] ;
77}
88
99/**
1010 * Provide the solution to LeetCode 2942 here:
1111 * https://leetcode.com/problems/find-words-containing-character/
1212 */
1313export 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 ) ;
1517}
You can’t perform that action at this time.
0 commit comments