Skip to content

Commit ef52c87

Browse files
committed
Update and rename uniqelem.js to uniqelem.java
1 parent e8328f1 commit ef52c87

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

uniqelem.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

uniqelem.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)