File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1- # 1,517 LeetCode solutions in JavaScript
1+ # 1,518 LeetCode solutions in JavaScript
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
134413441742|[ Maximum Number of Balls in a Box] ( ./solutions/1742-maximum-number-of-balls-in-a-box.js ) |Easy|
134513451743|[ Restore the Array From Adjacent Pairs] ( ./solutions/1743-restore-the-array-from-adjacent-pairs.js ) |Medium|
134613461744|[ 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|
134713481748|[ Sum of Unique Elements] ( ./solutions/1748-sum-of-unique-elements.js ) |Easy|
134813491749|[ Maximum Absolute Sum of Any Subarray] ( ./solutions/1749-maximum-absolute-sum-of-any-subarray.js ) |Medium|
134913501752|[ Check if Array Is Sorted and Rotated] ( ./solutions/1752-check-if-array-is-sorted-and-rotated.js ) |Easy|
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments