File tree Expand file tree Collapse file tree 2 files changed +54
-21
lines changed Expand file tree Collapse file tree 2 files changed +54
-21
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ (c) Sergio Morales 2013
3+ CodeEval Challenge: Unique Elements
4+ Dated Solved: 12/22/13
5+ **/
6+
7+ import java .io .*;
8+
9+
10+ public class Main {
11+ public static boolean found (String item , String [] list ) {
12+ for (int i = 0 ; i < list .length ; ++i ) {
13+ if (list [i ] != null && list [i ].equals (item )) {
14+ return true ;
15+ }
16+ }
17+
18+ return false ;
19+ }
20+
21+
22+ public static void main (String [] args ) throws IOException {
23+ File file = new File (args [0 ]);
24+ BufferedReader in = new BufferedReader (new FileReader (file ));
25+ String line ;
26+
27+ while ( (line = in .readLine ()) != null ) {
28+ String [] lineArray = line .split ("," );
29+ String [] uniqueArray = new String [lineArray .length ];
30+ Integer count = 0 ;
31+
32+ for (int i = 0 ; i < lineArray .length ; ++i ) {
33+ if (!found (lineArray [i ], uniqueArray )) {
34+ uniqueArray [count ] = lineArray [i ];
35+ ++count ;
36+ }
37+ }
38+ for (int i = 0 ; i < uniqueArray .length ; ++i ) {
39+ if (uniqueArray [i ] != null ) {
40+ System .out .print (uniqueArray [i ]);
41+ if ( (i +1 < uniqueArray .length -1 ) ) {
42+ if (uniqueArray [i +1 ] != null ) {
43+ System .out .print ("," );
44+ }
45+ }
46+ }
47+ }
48+
49+ System .out .println ();
50+ }
51+ }
52+
53+
54+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments