Untitled
unknown
plain_text
3 months ago
560 B
4
Indexable
public class Solution { public String makeSmallestPalindrome(String s) { char[] arr = s.toCharArray(); int i = 0, j = s.length() - 1; while (i < j) { if (arr[i] != arr[j]) { // Replace the larger character with the smaller one if (arr[i] < arr[j]) { arr[j] = arr[i]; } else { arr[i] = arr[j]; } } i++; j--; } return new String(arr); } }
Editor is loading...
Leave a Comment