File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11 Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 6
6
public class Lesson11 {
7
7
8
8
public int [] getConcatenation (int [] nums ) {
9
+ if (nums .length == 0 ){
10
+ return new int []{};
11
+ }
9
12
int lenOriginalArray = nums .length ;
10
13
int [] concatenatedArrays = new int [lenOriginalArray * 2 ];
11
14
@@ -21,6 +24,10 @@ public int[] getConcatenation(int[] nums) {
21
24
22
25
public List <Integer > findWordsContaining (String [] words , char x ) {
23
26
var indexList = new ArrayList <Integer >();
27
+ if (words .length == 0 ){
28
+ return indexList ;
29
+ }
30
+
24
31
int index = -1 ;
25
32
for (String word : words ){
26
33
index = index + 1 ;
Original file line number Diff line number Diff line change 3
3
* https://leetcode.com/problems/concatenation-of-array
4
4
*/
5
5
export function getConcatenation ( nums : number [ ] ) : number [ ] {
6
- return [ ] ;
6
+ if ( nums . length === 0 ) {
7
+ return [ ] ;
8
+ }
9
+ const lenOriginalArray : number = nums . length ;
10
+ const concatenatedArrays : number [ ] = [ lenOriginalArray * 2 ] ;
11
+ for ( let i = 0 ; i < lenOriginalArray ; i ++ ) {
12
+ concatenatedArrays [ i ] = nums [ i ] ;
13
+ }
14
+ const nextIndex = lenOriginalArray ;
15
+ for ( let i = 0 ; i < lenOriginalArray ; i ++ ) {
16
+ concatenatedArrays [ nextIndex + i ] = nums [ i ] ;
17
+ }
18
+ return concatenatedArrays ;
7
19
}
8
20
9
21
/**
10
22
* Provide the solution to LeetCode 2942 here:
11
23
* https://leetcode.com/problems/find-words-containing-character/
12
24
*/
13
25
export function findWordsContaining ( words : string [ ] , x : string ) : number [ ] {
14
- return [ ] ;
26
+ const indexList : number [ ] = [ ] ;
27
+ if ( words . length === 0 ) {
28
+ return [ ] ;
29
+ }
30
+ let index = - 1 ;
31
+ for ( const word of words ) {
32
+ index = index + 1 ;
33
+ const charactersOfWord = [ ] ;
34
+ const charactersOfCurrentWord : string [ ] = word . split ( '' ) ;
35
+ for ( const xter of charactersOfCurrentWord ) {
36
+ charactersOfWord . push ( xter ) ;
37
+ }
38
+ if ( charactersOfWord . includes ( x ) ) {
39
+ indexList . push ( index ) ;
40
+ }
41
+ }
42
+ return indexList ;
15
43
}
You can’t perform that action at this time.
0 commit comments