ソースを参照

Merge 19a8f0f3b7ff2468b440f3d33cb1621414c61391 into b2e20fd406b12d4908e4fb952d821a476dd96c45

SupaGrammer 6 年 前
コミット
8f38f11c20
コミット者のEメールアドレスに関連付けられたアカウントが存在しません
共有8 個のファイルを変更した129 個の追加12 個の削除を含む
  1. 16
    0
      .idea/compiler.xml
  2. 13
    0
      .idea/misc.xml
  3. 8
    0
      .idea/modules.xml
  4. 6
    0
      .idea/vcs.xml
  5. 16
    0
      FundamentalDrills-Part1.iml
  6. 70
    12
      src/main/java/io/zipcoder/ArrayDrills.java
  7. バイナリ
      target/classes/io/zipcoder/ArrayDrills.class
  8. バイナリ
      target/test-classes/io/zipcoder/ArrayDrillsTest.class

+ 16
- 0
.idea/compiler.xml ファイルの表示

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="CompilerConfiguration">
4
+    <annotationProcessing>
5
+      <profile name="Maven default annotation processors profile" enabled="true">
6
+        <sourceOutputDir name="target/generated-sources/annotations" />
7
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
8
+        <outputRelativeToContentRoot value="true" />
9
+        <module name="FundamentalDrills-Part1" />
10
+      </profile>
11
+    </annotationProcessing>
12
+    <bytecodeTargetLevel>
13
+      <module name="FundamentalDrills-Part1" target="1.5" />
14
+    </bytecodeTargetLevel>
15
+  </component>
16
+</project>

+ 13
- 0
.idea/misc.xml ファイルの表示

@@ -0,0 +1,13 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="MavenProjectsManager">
4
+    <option name="originalFiles">
5
+      <list>
6
+        <option value="$PROJECT_DIR$/pom.xml" />
7
+      </list>
8
+    </option>
9
+  </component>
10
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
11
+    <output url="file://$PROJECT_DIR$/classes" />
12
+  </component>
13
+</project>

+ 8
- 0
.idea/modules.xml ファイルの表示

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/FundamentalDrills-Part1.iml" filepath="$PROJECT_DIR$/FundamentalDrills-Part1.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
.idea/vcs.xml ファイルの表示

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

+ 16
- 0
FundamentalDrills-Part1.iml ファイルの表示

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
4
+    <output url="file://$MODULE_DIR$/target/classes" />
5
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
+    <content url="file://$MODULE_DIR$">
7
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>

+ 70
- 12
src/main/java/io/zipcoder/ArrayDrills.java ファイルの表示

@@ -1,5 +1,8 @@
1 1
 package io.zipcoder;
2 2
 
3
+import java.util.Collections;
4
+import java.util.Arrays;
5
+
3 6
 public class ArrayDrills {
4 7
 
5 8
 
@@ -9,8 +12,16 @@ 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) {
16
+        int firstElement = input[0];
17
+        int lastLastElement = input[input.length - 1];
18
+        if (firstElement == value || lastLastElement == value) {
19
+            return true;
20
+        }
21
+        // get first element
22
+        // get last element
23
+        // check if first Element or last element = value
24
+        return false;
14 25
     }
15 26
 
16 27
     /**
@@ -18,10 +29,15 @@ public class ArrayDrills {
18 29
      * example : sameFirstLast([1,2,3]); // Should return false
19 30
      *           sameFirstLast([1,2,1]); // Should return true
20 31
      */
21
-    public Boolean sameFirstLast(Integer[] input){
22
-        return null;
23
-    }
32
+    public Boolean sameFirstLast(Integer[] input) {
33
+        int firstElement = input[0];
34
+        int lastElement = input[input.length - 1];
35
+        if (lastElement == firstElement) {
36
+            return true;
37
+        }
24 38
 
39
+        return false;
40
+    }
25 41
 
26 42
     /**
27 43
      * Given 2 arrays of ints, a and b, return true if they have the same first element or they have the same last element.
@@ -29,8 +45,16 @@ public class ArrayDrills {
29 45
      * example : commonEnd([1, 2, 3], [7, 3]); // Should return true
30 46
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 47
      */
32
-    public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
48
+    public Boolean commonEnd(Integer[] input1, Integer[] input2) {
49
+        Integer firstArrayElement = input1[0];
50
+        Integer firstArrayLastElement = input1[input1.length - 1];
51
+        Integer secondArrayElement = input2[0];
52
+        Integer secondArrayLastElement = input2[input2.length - 1];
53
+        if (firstArrayElement.equals(secondArrayElement) || firstArrayLastElement.equals(secondArrayLastElement)) {
54
+            return true;
55
+        }
56
+
57
+        return false;
34 58
     }
35 59
 
36 60
     /**
@@ -39,7 +63,9 @@ public class ArrayDrills {
39 63
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 64
      */
41 65
     public Integer[] rotateLeft(Integer[] input){
42
-        return null;
66
+        Collections.rotate(Arrays.asList(input), 2);
67
+        System.out.println(Arrays.toString(input));
68
+        return input;
43 69
     }
44 70
 
45 71
 
@@ -50,7 +76,12 @@ public class ArrayDrills {
50 76
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
51 77
      */
52 78
     public Integer[] maxValue(Integer[] input){
53
-        return null;
79
+        int max = Collections.max(Arrays.asList(input));
80
+        for(int i = 0; i < input.length; i++) {
81
+            input[i] = max;
82
+        }
83
+
84
+        return input;
54 85
     }
55 86
 
56 87
 
@@ -61,17 +92,40 @@ public class ArrayDrills {
61 92
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62 93
      */
63 94
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
95
+        //assign new arrays
96
+        Integer[] midWay = new Integer[2];
97
+        midWay[0] = findMid(input1);
98
+        midWay[1] = findMid(input2);
99
+        return midWay;
65 100
     }
66 101
 
102
+    //made an assisting method that will find the middle index for...too much looping involved and I got lazy
103
+
104
+    public int findMid(Integer[] newInput) {
105
+        if (newInput.length % 2 == 0) {
106
+            return newInput[newInput.length/2] + newInput[newInput.length/2 - 1];
107
+        }
67 108
 
109
+        return newInput[newInput.length/2];
110
+    }
68 111
     /**
69 112
      * Start with 2 int arrays, a and b, each length 2.
70 113
      * Consider the sum of the values in each array.
71 114
      * Return the array which has the largest sum. In event of a tie, return a.
72 115
      */
73 116
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
117
+        Integer sumA = 0;
118
+        Integer sumB = 0;
119
+        for(int i = 0; i < a.length; i++){
120
+            sumA += a[i];
121
+            sumB += b[i];
122
+        }
123
+
124
+        if (sumA == sumB){
125
+            return a;
126
+        }
127
+//this does not pass the 3rd test case for this...should make another an assisting method to call upon and do the work for me...
128
+        return b;
75 129
     }
76 130
 
77 131
     /**
@@ -81,6 +135,10 @@ public class ArrayDrills {
81 135
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82 136
      */
83 137
     public Integer[] midThree(Integer[] nums){
84
-        return null;
138
+        Integer [] resultArr = new Integer[3];
139
+        resultArr[0] = nums[(nums.length/2) - 1];
140
+        resultArr[1] = nums[(nums.length/2)];
141
+        resultArr[2] = nums[(nums.length/2) + 1];
142
+        return resultArr;
85 143
     }
86 144
 }

バイナリ
target/classes/io/zipcoder/ArrayDrills.class ファイルの表示


バイナリ
target/test-classes/io/zipcoder/ArrayDrillsTest.class ファイルの表示