Given an array of strings with only lowercase letters, create a function that returns an array of those same strings, but each string has its letters rearranged such that it becomes a palindrome (if possible, if not, return -1).
Anonymous
public class Main { public static void main(String[] args) { String ana = "Rats live on no evil star"; System.out.println(new Main().isPalindrome(ana)); } private boolean isPalindrome(String s) { s = s.replaceAll("\\s+","").toLowerCase(); int length = s.length(); if (length < 2) return true; else { if (s.charAt(0) != s.charAt(length - 1)) { return false; } else { return isPalindrome(s.substring(1, length - 1)); } } } }
Check out your Company Bowl for anonymous work chats.