You are viewing a single comment's thread. Return to all comments →
You can just iterate over half of the string as we check the absolute values so the rest will be repetition.
Java solution :
private static boolean isFunny(String given) { int last = given.length() - 1; for (int first = 1; first <= given.length()/2; first++, last--) { if (Math.abs(given.charAt(first) - given.charAt(first - 1)) != Math.abs(given.charAt(last) - given.charAt(last - 1))) { return false; } } return true; }
Seems like cookies are disabled on this browser, please enable them to open this website
Funny String
You are viewing a single comment's thread. Return to all comments →
You can just iterate over half of the string as we check the absolute values so the rest will be repetition.
Java solution :