瀏覽代碼

linkedhashset

Seth 6 年之前
父節點
當前提交
648e017ddd
共有 3 個文件被更改,包括 93 次插入64 次删除
  1. 74
    55
      .idea/workspace.xml
  2. 3
    8
      arraz/src/main/java/Arraz.java
  3. 16
    1
      arraz/src/test/java/ArrazTest.java

+ 74
- 55
.idea/workspace.xml 查看文件

@@ -2,6 +2,7 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="3455511b-a100-4bbd-b07c-68f009bc8dbc" name="Default" comment="">
5
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
5 6
       <change beforePath="$PROJECT_DIR$/arraz/src/main/java/Arraz.java" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/src/main/java/Arraz.java" afterDir="false" />
6 7
       <change beforePath="$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java" afterDir="false" />
7 8
     </list>
@@ -22,13 +23,14 @@
22 23
       </usages-collector>
23 24
       <usages-collector id="statistics.file.types.edit">
24 25
         <counts>
25
-          <entry key="JAVA" value="7260" />
26
+          <entry key="JAVA" value="7562" />
26 27
           <entry key="XML" value="3" />
27 28
         </counts>
28 29
       </usages-collector>
29 30
       <usages-collector id="statistics.file.types.open">
30 31
         <counts>
31
-          <entry key="JAVA" value="3" />
32
+          <entry key="CLASS" value="1" />
33
+          <entry key="JAVA" value="4" />
32 34
           <entry key="XML" value="3" />
33 35
         </counts>
34 36
       </usages-collector>
@@ -36,11 +38,11 @@
36 38
   </component>
37 39
   <component name="FileEditorManager">
38 40
     <leaf SIDE_TABS_SIZE_LIMIT_KEY="375">
39
-      <file pinned="false" current-in-tab="false">
41
+      <file pinned="false" current-in-tab="true">
40 42
         <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
41 43
           <provider selected="true" editor-type-id="text-editor">
42
-            <state relative-caret-position="334">
43
-              <caret line="231" column="49" lean-forward="true" selection-start-line="231" selection-start-column="49" selection-end-line="231" selection-end-column="49" />
44
+            <state relative-caret-position="167">
45
+              <caret line="224" column="52" selection-start-line="224" selection-start-column="52" selection-end-line="224" selection-end-column="52" />
44 46
               <folding>
45 47
                 <element signature="imports" expanded="true" />
46 48
                 <element signature="e#4388#4389#0" expanded="true" />
@@ -50,14 +52,20 @@
50 52
           </provider>
51 53
         </entry>
52 54
       </file>
53
-      <file pinned="false" current-in-tab="true">
55
+      <file pinned="false" current-in-tab="false">
54 56
         <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
55 57
           <provider selected="true" editor-type-id="text-editor">
56
-            <state relative-caret-position="359">
57
-              <caret line="130" column="26" selection-start-line="130" selection-start-column="26" selection-end-line="130" selection-end-column="26" />
58
-              <folding>
59
-                <element signature="imports" expanded="true" />
60
-              </folding>
58
+            <state relative-caret-position="313">
59
+              <caret line="127" lean-forward="true" selection-start-line="127" selection-end-line="127" />
60
+            </state>
61
+          </provider>
62
+        </entry>
63
+      </file>
64
+      <file pinned="false" current-in-tab="false">
65
+        <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/src.zip!/java/util/Set.java">
66
+          <provider selected="true" editor-type-id="text-editor">
67
+            <state relative-caret-position="386">
68
+              <caret line="189" column="17" selection-start-line="189" selection-start-column="17" selection-end-line="189" selection-end-column="17" />
61 69
             </state>
62 70
           </provider>
63 71
         </entry>
@@ -207,7 +215,7 @@
207 215
     <property name="GO_FMT" value="false" />
208 216
     <property name="WebServerToolWindowFactoryState" value="false" />
209 217
     <property name="aspect.path.notification.shown" value="true" />
210
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544139093969" />
218
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544188738035" />
211 219
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="JUnit4" />
212 220
     <property name="jdk.selected.JAVA_MODULE" value="1.8" />
213 221
     <property name="last_opened_file_path" value="$PROJECT_DIR$" />
@@ -358,7 +366,7 @@
358 366
       <workItem from="1543955862749" duration="2347000" />
359 367
       <workItem from="1543958998826" duration="113000" />
360 368
       <workItem from="1544020724645" duration="762000" />
361
-      <workItem from="1544046933389" duration="20210000" />
369
+      <workItem from="1544046933389" duration="22466000" />
362 370
     </task>
363 371
     <task id="LOCAL-00001" summary="readme and docs">
364 372
       <created>1544021313039</created>
@@ -371,39 +379,39 @@
371 379
     <servers />
372 380
   </component>
373 381
   <component name="TestHistory">
374
-    <history-entry file="ArrazTest_testInsertArrayAt2 - 2018.12.06 at 16h 08m 11s.xml">
375
-      <configuration name="ArrazTest.testInsertArrayAt2" configurationId="JUnit" />
382
+    <history-entry file="ArrazTest_testRemoveDupesFromArray2 - 2018.12.06 at 18h 33m 05s.xml">
383
+      <configuration name="ArrazTest.testRemoveDupesFromArray2" configurationId="JUnit" />
376 384
     </history-entry>
377
-    <history-entry file="ArrazTest_testInsertArrayAt1 - 2018.12.06 at 16h 08m 38s.xml">
378
-      <configuration name="ArrazTest.testInsertArrayAt1" configurationId="JUnit" />
385
+    <history-entry file="ArrazTest_testRemoveDupesFromArray2 - 2018.12.06 at 18h 33m 50s.xml">
386
+      <configuration name="ArrazTest.testRemoveDupesFromArray2" configurationId="JUnit" />
379 387
     </history-entry>
380
-    <history-entry file="ArrazTest_testInsertArrayAt2 - 2018.12.06 at 16h 08m 41s.xml">
381
-      <configuration name="ArrazTest.testInsertArrayAt2" configurationId="JUnit" />
388
+    <history-entry file="ArrazTest_testRemoveDupesFromArray2 - 2018.12.06 at 18h 33m 59s.xml">
389
+      <configuration name="ArrazTest.testRemoveDupesFromArray2" configurationId="JUnit" />
382 390
     </history-entry>
383
-    <history-entry file="ArrazTest_testInsertArrayAt1 - 2018.12.06 at 16h 11m 02s.xml">
384
-      <configuration name="ArrazTest.testInsertArrayAt1" configurationId="JUnit" />
391
+    <history-entry file="ArrazTest_testRemoveDupesFromArray2 - 2018.12.06 at 18h 34m 13s.xml">
392
+      <configuration name="ArrazTest.testRemoveDupesFromArray2" configurationId="JUnit" />
385 393
     </history-entry>
386
-    <history-entry file="ArrazTest_testInsertArrayAt1 - 2018.12.06 at 16h 11m 14s.xml">
387
-      <configuration name="ArrazTest.testInsertArrayAt1" configurationId="JUnit" />
394
+    <history-entry file="ArrazTest_testRemoveDupesFromArray2 - 2018.12.06 at 18h 35m 05s.xml">
395
+      <configuration name="ArrazTest.testRemoveDupesFromArray2" configurationId="JUnit" />
388 396
     </history-entry>
389
-    <history-entry file="ArrazTest_testInsertArrayAt2 - 2018.12.06 at 16h 11m 17s.xml">
390
-      <configuration name="ArrazTest.testInsertArrayAt2" configurationId="JUnit" />
397
+    <history-entry file="ArrazTest_testRemoveDupesFromArray2 - 2018.12.07 at 07h 58m 33s.xml">
398
+      <configuration name="ArrazTest.testRemoveDupesFromArray2" configurationId="JUnit" />
391 399
     </history-entry>
392
-    <history-entry file="ArrazTest_testCopyArrayByIterator1 - 2018.12.06 at 16h 59m 54s.xml">
393
-      <configuration name="ArrazTest.testCopyArrayByIterator1" configurationId="JUnit" />
400
+    <history-entry file="ArrazTest_testRemoveDupesFromArray2 - 2018.12.07 at 08h 12m 08s.xml">
401
+      <configuration name="ArrazTest.testRemoveDupesFromArray2" configurationId="JUnit" />
394 402
     </history-entry>
395
-    <history-entry file="ArrazTest_testCopyArrayByIterator2 - 2018.12.06 at 16h 59m 57s.xml">
396
-      <configuration name="ArrazTest.testCopyArrayByIterator2" configurationId="JUnit" />
403
+    <history-entry file="ArrazTest_testRemoveDupesFromArray1 - 2018.12.07 at 08h 12m 26s.xml">
404
+      <configuration name="ArrazTest.testRemoveDupesFromArray1" configurationId="JUnit" />
397 405
     </history-entry>
398
-    <history-entry file="ArrazTest_testFindMaxMinOfArray1 - 2018.12.06 at 18h 11m 28s.xml">
399
-      <configuration name="ArrazTest.testFindMaxMinOfArray1" configurationId="JUnit" />
406
+    <history-entry file="ArrazTest_testRemoveDupesFromArray2 - 2018.12.07 at 08h 15m 25s.xml">
407
+      <configuration name="ArrazTest.testRemoveDupesFromArray2" configurationId="JUnit" />
400 408
     </history-entry>
401
-    <history-entry file="ArrazTest_testFindMaxMinOfArray2 - 2018.12.06 at 18h 11m 30s.xml">
402
-      <configuration name="ArrazTest.testFindMaxMinOfArray2" configurationId="JUnit" />
409
+    <history-entry file="ArrazTest_testRemoveDupesFromArray1 - 2018.12.07 at 08h 15m 32s.xml">
410
+      <configuration name="ArrazTest.testRemoveDupesFromArray1" configurationId="JUnit" />
403 411
     </history-entry>
404 412
   </component>
405 413
   <component name="TimeTrackingManager">
406
-    <option name="totallyTimeSpent" value="23432000" />
414
+    <option name="totallyTimeSpent" value="25688000" />
407 415
   </component>
408 416
   <component name="ToolWindowManager">
409 417
     <frame x="1" y="23" width="1440" height="807" extended-state="0" />
@@ -457,19 +465,6 @@
457 465
         </state>
458 466
       </provider>
459 467
     </entry>
460
-    <entry file="file://$PROJECT_DIR$/arraz/src/main/java/OddEven.java">
461
-      <provider selected="true" editor-type-id="text-editor">
462
-        <state>
463
-          <caret column="22" selection-start-column="22" selection-end-column="22" />
464
-          <folding>
465
-            <element signature="e#189#190#0" expanded="true" />
466
-            <element signature="e#215#216#0" expanded="true" />
467
-            <element signature="e#308#309#0" expanded="true" />
468
-            <element signature="e#335#336#0" expanded="true" />
469
-          </folding>
470
-        </state>
471
-      </provider>
472
-    </entry>
473 468
     <entry file="file://$PROJECT_DIR$/arraz/src/main/java/MaxMin.java">
474 469
       <provider selected="true" editor-type-id="text-editor">
475 470
         <state>
@@ -487,18 +482,33 @@
487 482
         </state>
488 483
       </provider>
489 484
     </entry>
490
-    <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
485
+    <entry file="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/org/junit/internal/runners/model/ReflectiveCallable.class">
491 486
       <provider selected="true" editor-type-id="text-editor">
492
-        <state relative-caret-position="334">
493
-          <caret line="231" column="49" lean-forward="true" selection-start-line="231" selection-start-column="49" selection-end-line="231" selection-end-column="49" />
487
+        <state relative-caret-position="210">
488
+          <caret line="17" selection-start-line="17" selection-end-line="17" />
489
+        </state>
490
+      </provider>
491
+    </entry>
492
+    <entry file="file://$PROJECT_DIR$/arraz/src/main/java/OddEven.java">
493
+      <provider selected="true" editor-type-id="text-editor">
494
+        <state>
495
+          <caret column="22" selection-start-column="22" selection-end-column="22" />
494 496
           <folding>
495
-            <element signature="imports" expanded="true" />
496
-            <element signature="e#4388#4389#0" expanded="true" />
497
-            <element signature="e#4411#4412#0" expanded="true" />
497
+            <element signature="e#189#190#0" expanded="true" />
498
+            <element signature="e#215#216#0" expanded="true" />
499
+            <element signature="e#308#309#0" expanded="true" />
500
+            <element signature="e#335#336#0" expanded="true" />
498 501
           </folding>
499 502
         </state>
500 503
       </provider>
501 504
     </entry>
505
+    <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/src.zip!/java/util/Set.java">
506
+      <provider selected="true" editor-type-id="text-editor">
507
+        <state relative-caret-position="386">
508
+          <caret line="189" column="17" selection-start-line="189" selection-start-column="17" selection-end-line="189" selection-end-column="17" />
509
+        </state>
510
+      </provider>
511
+    </entry>
502 512
     <entry file="file://$PROJECT_DIR$/README.md">
503 513
       <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
504 514
         <state split_layout="SPLIT">
@@ -511,10 +521,19 @@
511 521
     </entry>
512 522
     <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
513 523
       <provider selected="true" editor-type-id="text-editor">
514
-        <state relative-caret-position="359">
515
-          <caret line="130" column="26" selection-start-line="130" selection-start-column="26" selection-end-line="130" selection-end-column="26" />
524
+        <state relative-caret-position="313">
525
+          <caret line="127" lean-forward="true" selection-start-line="127" selection-end-line="127" />
526
+        </state>
527
+      </provider>
528
+    </entry>
529
+    <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
530
+      <provider selected="true" editor-type-id="text-editor">
531
+        <state relative-caret-position="167">
532
+          <caret line="224" column="52" selection-start-line="224" selection-start-column="52" selection-end-line="224" selection-end-column="52" />
516 533
           <folding>
517 534
             <element signature="imports" expanded="true" />
535
+            <element signature="e#4388#4389#0" expanded="true" />
536
+            <element signature="e#4411#4412#0" expanded="true" />
518 537
           </folding>
519 538
         </state>
520 539
       </provider>

+ 3
- 8
arraz/src/main/java/Arraz.java 查看文件

@@ -1,7 +1,4 @@
1
-import java.util.Arrays;
2
-import java.util.HashSet;
3
-import java.util.Iterator;
4
-import java.util.Set;
1
+import java.util.*;
5 2
 
6 3
 public class Arraz {
7 4
 
@@ -125,10 +122,8 @@ public class Arraz {
125 122
     }
126 123
 
127 124
     public Integer[] removeDupesFromArray(Integer[] array){
128
-        Set<Integer> integerSet = new HashSet<>();
129
-        integerSet.addAll(Arrays.asList(array));
130
-        Integer[] integers = new Integer[integerSet.size()];
131
-        return integerSet.toArray(integers);
125
+        Set<Integer> integerSet = new LinkedHashSet<>(Arrays.asList(array));
126
+        return integerSet.toArray(new Integer[0]);
132 127
     }
133 128
 
134 129
 }

+ 16
- 1
arraz/src/test/java/ArrazTest.java 查看文件

@@ -222,16 +222,31 @@ public class ArrazTest {
222 222
         Integer[] array1 = new Integer[]{1,3 ,4, 3, 7, 7, 10};
223 223
         Integer[] expected = new Integer[]{1, 3, 4, 7, 10};
224 224
         Integer[] actual = testArraz.removeDupesFromArray(array1);
225
+        System.out.println(Arrays.toString(actual));
225 226
 
226 227
         Assert.assertArrayEquals(expected, actual);
227 228
     }
228 229
 
229 230
     @Test
230 231
     public void testRemoveDupesFromArray2(){
231
-        Integer[] array1 = new Integer[]{5, 1, 1, 1, 1 ,1};
232
+        Integer[] array1 = new Integer[]{5, 1, 5, 5, 5 ,5};
232 233
         Integer[] expected = new Integer[]{5, 1};
233 234
         Integer[] actual = testArraz.removeDupesFromArray(array1);
235
+        System.out.println(Arrays.toString(actual));
234 236
 
235 237
         Assert.assertArrayEquals(expected, actual);
236 238
     }
239
+
240
+//    @Test
241
+//    public void testFind2ndLargestFromArray1(){
242
+//        double expected = 38.4;
243
+//        double actual = testArraz.find2ndLargestFromArray();
244
+//
245
+//        Assert.assertEquals(expected, actual, .01);
246
+//    }
247
+//
248
+//    @Test
249
+//    public void testFind2ndLargestFromArray2(){
250
+//
251
+//    }
237 252
 }