Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 69de7e1

Browse files
committed
Add solution #1745
1 parent 2755ed4 commit 69de7e1

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,517 LeetCode solutions in JavaScript
1+
# 1,518 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1344,6 +1344,7 @@
13441344
1742|[Maximum Number of Balls in a Box](./solutions/1742-maximum-number-of-balls-in-a-box.js)|Easy|
13451345
1743|[Restore the Array From Adjacent Pairs](./solutions/1743-restore-the-array-from-adjacent-pairs.js)|Medium|
13461346
1744|[Can You Eat Your Favorite Candy on Your Favorite Day?](./solutions/1744-can-you-eat-your-favorite-candy-on-your-favorite-day.js)|Medium|
1347+
1745|[Palindrome Partitioning IV](./solutions/1745-palindrome-partitioning-iv.js)|Hard|
13471348
1748|[Sum of Unique Elements](./solutions/1748-sum-of-unique-elements.js)|Easy|
13481349
1749|[Maximum Absolute Sum of Any Subarray](./solutions/1749-maximum-absolute-sum-of-any-subarray.js)|Medium|
13491350
1752|[Check if Array Is Sorted and Rotated](./solutions/1752-check-if-array-is-sorted-and-rotated.js)|Easy|
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* 1745. Palindrome Partitioning IV
3+
* https://leetcode.com/problems/palindrome-partitioning-iv/
4+
* Difficulty: Hard
5+
*
6+
* Given a string s, return true if it is possible to split the string s into three non-empty
7+
* palindromic substrings. Otherwise, return false.
8+
*
9+
* A string is said to be palindrome if it the same string when reversed.
10+
*/
11+
12+
/**
13+
* @param {string} s
14+
* @return {boolean}
15+
*/
16+
var checkPartitioning = function(s) {
17+
const n = s.length;
18+
const isPalindrome = Array.from({ length: n }, () => Array(n).fill(false));
19+
20+
for (let i = n - 1; i >= 0; i--) {
21+
for (let j = i; j < n; j++) {
22+
if (s[i] === s[j] && (j - i <= 2 || isPalindrome[i + 1][j - 1])) {
23+
isPalindrome[i][j] = true;
24+
}
25+
}
26+
}
27+
28+
for (let i = 1; i < n - 1; i++) {
29+
for (let j = i; j < n - 1; j++) {
30+
if (isPalindrome[0][i - 1] && isPalindrome[i][j] && isPalindrome[j + 1][n - 1]) {
31+
return true;
32+
}
33+
}
34+
}
35+
36+
return false;
37+
};

0 commit comments

Comments
 (0)