-
[LeetCode] 1616. Split Two Strings to Make PalindromeLeetCode 2021. 10. 7. 00:45728x90
https://leetcode.com/problems/split-two-strings-to-make-palindrome/
Split Two Strings to Make Palindrome - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Split Two Strings to Make Palindrome


풀이코드
class Solution { public: bool checkPalindromeFormation(string a, string b) { int l[2] = {palindrome_chk(a), palindrome_chk(b)}; string strs[2] = {a,b}; if (l[0]<0 || l[1]<0) return true; for (int i=0; i<2; i++) { for (int j=0; j<2; j++) { int ll = l[i], rr = a.size()-1-ll; for(;ll>=0 && strs[j][ll]==strs[1-j][rr];) {ll--;rr++;} if (ll<0) return true; } } return false; } int palindrome_chk(string a) { int l=a.size()/2-1, r=a.size()-1-l; for (;l>=0 && a[l]==a[r];) {l--;r++;} return l; } };'LeetCode' 카테고리의 다른 글
[LeetCode] 208. Implement Trie (Prefix Tree) (0) 2021.10.08 [LeetCode] 79. Word Search (0) 2021.10.07 [LeetCode] 1337. The K Weakest Rows in a Matrix (0) 2021.10.06 [LeetCode] 70. Climbing Stairs (0) 2021.10.06 [LeetCode] 1657. Determine if Two Strings Are Close (0) 2021.10.04