classSolution: defcheckPalindromeFormation(self, a: str, b: str) -> bool: return self.checkConcatenation(a, b) or self.checkConcatenation(b, a) defcheckConcatenation(self, a: str, b: str) -> bool: n = len(a) left, right = 0, n-1 while left < right and a[left] == b[right]: left += 1 right -= 1 if left >= right: returnTrue return self.checkSelfPalindrome(a, left, right) or self.checkSelfPalindrome(b, left, right)
defcheckSelfPalindrome(self, a: str, left: int, right: int) -> bool: while left < right and a[left] == a[right]: left += 1 right -= 1 return left >= right
classSolution { publicbooleancheckPalindromeFormation(String a, String b) { return checkConcatenation(a, b) || checkConcatenation(b, a); }
publicbooleancheckConcatenation(String a, String b) { intn= a.length(); intleft=0, right = n - 1; while (left < right && a.charAt(left) == b.charAt(right)) { left++; right--; } if (left >= right) { returntrue; } return checkSelfPalindrome(a, left, right) || checkSelfPalindrome(b, left, right); }
publicbooleancheckSelfPalindrome(String a, int left, int right) { while (left < right && a.charAt(left) == a.charAt(right)) { left++; right--; } return left >= right; } }
publicclassSolution { publicboolCheckPalindromeFormation(string a, string b) { return checkConcatenation(a, b) || checkConcatenation(b, a); }
publicboolcheckConcatenation(string a, string b) { int n = a.Length; int left = 0, right = n - 1; while (left < right && a[left] == b[right]) { left++; right--; } if (left >= right) { returntrue; } return CheckSelfPalindrome(a, left, right) || CheckSelfPalindrome(b, left, right); }
publicboolCheckSelfPalindrome(string a, int left, int right) { while (left < right && a[left] == a[right]) { left++; right--; } return left >= right; } }
funccheckPalindromeFormation(a, b string)bool { return checkConcatenation(a, b) || checkConcatenation(b, a) }
funccheckConcatenation(a, b string)bool { left, right := 0, len(a)-1 for left < right && a[left] == b[right] { left++ right-- } if left >= right { returntrue } return checkSelfPalindrome(a[left:right+1]) || checkSelfPalindrome(b[left:right+1]) }
funccheckSelfPalindrome(s string)bool { left, right := 0, len(s)-1 for left < right && s[left] == s[right] { left++ right-- } return left >= right }