File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 311
311
1374|[ Generate a String With Characters That Have Odd Counts] ( ./1374-generate-a-string-with-characters-that-have-odd-counts.js ) |Easy|
312
312
1380|[ Lucky Numbers in a Matrix] ( ./1380-lucky-numbers-in-a-matrix.js ) |Easy|
313
313
1389|[ Create Target Array in the Given Order] ( ./1389-create-target-array-in-the-given-order.js ) |Easy|
314
+ 1400|[ Construct K Palindrome Strings] ( ./1400-construct-k-palindrome-strings.js ) |Medium|
314
315
1402|[ Reducing Dishes] ( ./1402-reducing-dishes.js ) |Hard|
315
316
1408|[ String Matching in an Array] ( ./1408-string-matching-in-an-array.js ) |Easy|
316
317
1410|[ HTML Entity Parser] ( ./1410-html-entity-parser.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1400. Construct K Palindrome Strings
3
+ * https://leetcode.com/problems/construct-k-palindrome-strings/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given a string s and an integer k, return true if you can use all the characters in s to
7
+ * construct k palindrome strings or false otherwise.
8
+ */
9
+
10
+ /**
11
+ * @param {string } s
12
+ * @param {number } k
13
+ * @return {boolean }
14
+ */
15
+ var canConstruct = function ( s , k ) {
16
+ const occurrences = new Array ( 26 ) . fill ( 0 ) ;
17
+ s . split ( '' ) . forEach ( c => occurrences [ c . charCodeAt ( 0 ) - 'a' . charCodeAt ( 0 ) ] ++ ) ;
18
+
19
+ const oddCount = occurrences . filter ( n => n % 2 !== 0 ) . length ;
20
+ return k <= s . length && oddCount <= k ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments