orhancanceylan
BAN USERThe idea is great but, putting all positives to the front and then traversing at the beginning of the array and also the swapping won't cost a lot ?
- orhancanceylan June 13, 2012isn't finding the max of an array require to travel once ? and then we also need to traverse through array to add elements to the bitmap ?
- orhancanceylan June 13, 2012isn't finding the max of an array require to travel once ? and then we also need to traverse through array to add elements to the bitmap ?
- orhancanceylan June 13, 2012From the pisagor thm; A:{3,4,10} and B:{6,8,5}
- orhancanceylan June 13, 2012that would be N^2 right ? which is the trivial solution
- orhancanceylan June 12, 2012you're right man, great !
- orhancanceylan June 12, 2012{{package mic01;
public class LongestPalindrome {
public static void main(String[] args) {
String dummy = "AAABBGFF ili ollo benmio ooloo eo sadkjansd evbnbve eikdo ooooooooookoooooooooo";
System.out.println(letsDoThis(dummy));
}
private static String letsDoThis(String dummy) {
String result = null;
int max = 0;
String[] a = dummy.split(" ");
for(int i=0; i<a.length; i++){
if(isPalindrome(a[i])){
if(a[i].length() > max)
result = a[i];
}
}
return result;
}
private static boolean isPalindrome(String string) {
int length = string.length();
if(length % 2 == 0)
return false;
else{
for(int i=0; i<length/2; i++){
if(string.charAt(i) != string.charAt(length-i-1)){
return false;
}
}
}
return true;
}
}
}}
congrats man, that's the best solution
- orhancanceylan June 13, 2012