Created
November 16, 2015 22:49
-
-
Save SocraticPhoenix/a764bc3221862b90f8f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Compressed, 342 characters | |
public static String p(String s){String[]w=s.toLowerCase().split(" ");String e="";for(int j=0,i=0;j<w.length;j++){for(;i<w.length;i++){String x=w[i],y=w[j];String r="";for(int k=0;k<Math.min(y.length(),x.length());k++){char a=y.charAt(k);char b=x.charAt(k);r=a==b?r.concat(String.valueOf(a)):r;}e=r.length()>e.length()&&j!=i?r:e;}}return e;} | |
//Uncompressed | |
public static String p(String s) { | |
String[] w = s.toLowerCase().split(" "); | |
String e = ""; | |
for (int j = 0, i = 0, m = w.length; j < m; j++) { | |
for (; i < m; i++) { | |
String x = w[i], y = w[j], r = ""; | |
for (int k = 0; k < Math.min(y.length(), x.length()); k++) { | |
char a = y.charAt(k), b = x.charAt(k); | |
r = a == b ? r.concat(String.valueOf(a)) : r; | |
} | |
e = r.length() > e.length() && j != i ? r : e; | |
} | |
} | |
return e; | |
} | |
//How I wrote it before minimizing character count: | |
public static String prefix(String sentence) { | |
String[] words = sentence.toLowerCase().split(" "); | |
return isolate(words); | |
} | |
public static String isolate(String... strings) { | |
String result = ""; | |
for (int j = 0; j < strings.length; j++) { | |
for (int i = 0; i < strings.length; i++) { | |
String string = strings[i], string1 = strings[j]; | |
String result2 = ""; | |
for (int k = 0; k < Math.min(string1.length(), string.length()); k++) { | |
char a = string1.charAt(k); | |
char b = string.charAt(k); | |
result2 = a == b ? result2.concat(String.valueOf(a)) : result2; | |
} | |
result = result2.length() > result.length() && j != i ? result2 : result; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment