로딩
요청 처리 중입니다...

JAVA_LeetCode 131_Palindrome Partitioning

 JAVA_LeetCode 131_Palindrome Partitioning

JAVA_LeetCode 131_Palindrome Partitioning 풀이 class Solution { public List partition(String s) { int len = s.length(), end = 0; boolean[][] isPalindrome = new boolean[len][len]; // 회문 여부를 DP로 사전 계산 for(int i = 1; i <= len; i++){ for(int j = 0; j <= len - i; j++) { end = j + i - 1; if(s.charAt(j) == s.charAt(end)){ if(i <= 2) isPalindrome[j][end] = true; // 길이가 1 또는 2면 안쪽 검사 필요 없음 else isPalindrome[j][end] = isPalindrome[j + 1][end - 1]; // 안쪽 문자열이 회문이면 긴 문자열도 회문 } } } List