Raymond Farria 6 년 전
부모
커밋
ea326328bc

+ 1
- 0
.idea/.name 파일 보기

@@ -0,0 +1 @@
1
+FundamentalDrills-Part1

+ 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>

+ 5
- 0
.idea/inspectionProfiles/profiles_settings.xml 파일 보기

@@ -0,0 +1,5 @@
1
+<component name="InspectionProjectProfileManager">
2
+  <settings>
3
+    <option name="PROJECT_PROFILE" />
4
+  </settings>
5
+</component>

+ 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>

+ 18
- 0
FundamentalDrills-Part1.iml 파일 보기

@@ -0,0 +1,18 @@
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
+    <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
16
+    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
17
+  </component>
18
+</module>

+ 5
- 0
pom.xml 파일 보기

@@ -15,5 +15,10 @@
15 15
             <version>4.12</version>
16 16
             <scope>test</scope>
17 17
         </dependency>
18
+        <dependency>
19
+            <groupId>junit</groupId>
20
+            <artifactId>junit</artifactId>
21
+            <version>RELEASE</version>
22
+        </dependency>
18 23
     </dependencies>
19 24
 </project>

+ 58
- 9
src/main/java/io/zipcoder/ArrayDrills.java 파일 보기

@@ -1,5 +1,7 @@
1 1
 package io.zipcoder;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 public class ArrayDrills {
4 6
 
5 7
 
@@ -10,7 +12,11 @@ public class ArrayDrills {
10 12
      *           firstLast(6, [1,2,3]); // Should return false
11 13
      */
12 14
     public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
15
+        if(value.equals(input[0]) | value.equals(input[input.length - 1])) {
16
+            return true;
17
+        }
18
+            return false;
19
+
14 20
     }
15 21
 
16 22
     /**
@@ -19,7 +25,10 @@ public class ArrayDrills {
19 25
      *           sameFirstLast([1,2,1]); // Should return true
20 26
      */
21 27
     public Boolean sameFirstLast(Integer[] input){
22
-        return null;
28
+        if(input.length > 1 && input[0].equals(input[input.length -1])) {
29
+            return true;
30
+        }
31
+        return false;
23 32
     }
24 33
 
25 34
 
@@ -30,7 +39,10 @@ public class ArrayDrills {
30 39
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 40
      */
32 41
     public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
42
+        if(input1[0].equals(input2[0]) || input1[input1.length -1].equals(input2[input2.length - 1])) {
43
+            return true;
44
+        }
45
+        return false;
34 46
     }
35 47
 
36 48
     /**
@@ -39,7 +51,11 @@ public class ArrayDrills {
39 51
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 52
      */
41 53
     public Integer[] rotateLeft(Integer[] input){
42
-        return null;
54
+        int start = input[0];
55
+        System.arraycopy(input, 1, input, 0, input.length - 1);
56
+        input[input.length - 1] = start;
57
+        return input;
58
+
43 59
     }
44 60
 
45 61
 
@@ -50,7 +66,12 @@ public class ArrayDrills {
50 66
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
51 67
      */
52 68
     public Integer[] maxValue(Integer[] input){
53
-        return null;
69
+        Arrays.sort(input);
70
+        int max = input[input.length-1];
71
+        for(int i = 0; i < input.length; i++){
72
+            input[i] = max;
73
+        }
74
+        return input;
54 75
     }
55 76
 
56 77
 
@@ -61,7 +82,23 @@ public class ArrayDrills {
61 82
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62 83
      */
63 84
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
85
+        Integer []newArr = new Integer[2];
86
+        if (input1.length %2 ==0 || input2.length %2 == 0) {
87
+            if (input1.length == input2.length){
88
+                newArr[0] = input1[input1.length / 2] + input1[input1.length / 2 - 1];
89
+                newArr[1] = input2[input2.length / 2] + input2[input2.length / 2 - 1];
90
+            }else if(input1.length>input2.length){
91
+                newArr[0] = input1[input1.length/2] + input1[input1.length/2 -1];
92
+                newArr[1] = input2[input2.length/2];
93
+            }else if(input1.length<input2.length){
94
+                newArr[0] = input1[input1.length/2];
95
+                newArr[1] = input2[input2.length/2] + input2[input2.length/2 - 1];
96
+            }
97
+        }else if(input1.length %2==1 && input2.length %2 ==1){
98
+            newArr[0] = input1[input1.length/2];
99
+            newArr[1] = input2[input2.length/2];
100
+        }
101
+        return newArr;
65 102
     }
66 103
 
67 104
 
@@ -70,8 +107,16 @@ public class ArrayDrills {
70 107
      * Consider the sum of the values in each array.
71 108
      * Return the array which has the largest sum. In event of a tie, return a.
72 109
      */
73
-    public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
110
+    public Integer[] biggerTwo(Integer[] a, Integer[] b) {
111
+        int c = a[0] + a[1];
112
+        int d = b[0] + b[1];
113
+        if (c > d) {
114
+            return a;
115
+        } else if (c < d) {
116
+            return b;
117
+        } else {
118
+            return a;
119
+        }
75 120
     }
76 121
 
77 122
     /**
@@ -81,6 +126,10 @@ public class ArrayDrills {
81 126
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82 127
      */
83 128
     public Integer[] midThree(Integer[] nums){
84
-        return null;
129
+        Integer[] midArr = new Integer[3];
130
+        midArr[0] = nums[nums.length/2 -1];
131
+        midArr[1] = nums[nums.length/2];
132
+        midArr[2] = nums[nums.length/2 +1];
133
+        return midArr;
85 134
     }
86 135
 }

+ 1
- 1
src/test/java/io/zipcoder/ArrayDrillsTest.java 파일 보기

@@ -179,7 +179,7 @@ public class ArrayDrillsTest {
179 179
     public void biggerTwo3(){
180 180
         Integer[] inputArray1 = {-1 ,20};
181 181
         Integer[] inputArray2 = {2, 15};
182
-        Integer[] expected = {1,20};
182
+        Integer[] expected = {-1,20};
183 183
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
184 184
         Assert.assertArrayEquals(expected, actual);
185 185
     }

BIN
target/classes/io/zipcoder/ArrayDrills.class 파일 보기


BIN
target/test-classes/io/zipcoder/ArrayDrillsTest.class 파일 보기