shakila 6 lat temu
rodzic
commit
5ad4736609
1 zmienionych plików z 30 dodań i 6 usunięć
  1. 30
    6
      src/main/java/io/zipcoder/ArrayDrills.java

+ 30
- 6
src/main/java/io/zipcoder/ArrayDrills.java Wyświetl plik

@@ -1,4 +1,7 @@
1 1
 package io.zipcoder;
2
+import java.util.Arrays;
3
+import java.util.ArrayUtils;
4
+
2 5
 
3 6
 public class ArrayDrills {
4 7
 
@@ -9,8 +12,14 @@ public class ArrayDrills {
9 12
      * example : firstLast(6, [1,2,6); // Should return true
10 13
      *           firstLast(6, [1,2,3]); // Should return false
11 14
      */
12
-    public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
15
+    public boolean firstLast(Integer value, Integer[] input){   //change b to B
16
+        boolean firstLast = false;
17
+        //for (int i = 0; i<input.length; i++){
18
+            if(value = intput[0] || value = input[input.length-1]){
19
+                firstLast = true;
20
+        }
21
+
22
+        return firstLast;
14 23
     }
15 24
 
16 25
     /**
@@ -18,8 +27,12 @@ public class ArrayDrills {
18 27
      * example : sameFirstLast([1,2,3]); // Should return false
19 28
      *           sameFirstLast([1,2,1]); // Should return true
20 29
      */
21
-    public Boolean sameFirstLast(Integer[] input){
22
-        return null;
30
+    public boolean sameFirstLast(Integer[] input){  //change b to B
31
+        boolean same = false;
32
+        if (input.length >= 2 && input[0] == input[input.length-1]){
33
+            same = true;
34
+        }
35
+        return same;
23 36
     }
24 37
 
25 38
 
@@ -29,8 +42,12 @@ public class ArrayDrills {
29 42
      * example : commonEnd([1, 2, 3], [7, 3]); // Should return true
30 43
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 44
      */
32
-    public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
45
+    public boolean commonEnd(Integer[] input1, Integer[] input2){       //change b to B
46
+        boolean common = false;
47
+        if (input1[0] == input2[0] || input1[input1.length-1] == input2[input2.length-1]){
48
+                common = true;
49
+        }
50
+        return common;
34 51
     }
35 52
 
36 53
     /**
@@ -39,6 +56,13 @@ public class ArrayDrills {
39 56
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 57
      */
41 58
     public Integer[] rotateLeft(Integer[] input){
59
+        Integer last = 0;
60
+        Integer[] temp = input.length;
61
+        for (int i = 0; i < input.length;i++){
62
+            last = input[0];
63
+            array = ArrayUtils.removeElement(input,input[0]);
64
+
65
+        }
42 66
         return null;
43 67
     }
44 68