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 326
326
405|[ Convert a Number to Hexadecimal] ( ./0405-convert-a-number-to-hexadecimal.js ) |Easy|
327
327
406|[ Queue Reconstruction by Height] ( ./0406-queue-reconstruction-by-height.js ) |Medium|
328
328
407|[ Trapping Rain Water II] ( ./0407-trapping-rain-water-ii.js ) |Hard|
329
+ 409|[ Longest Palindrome] ( ./0409-longest-palindrome.js ) |Easy|
329
330
412|[ Fizz Buzz] ( ./0412-fizz-buzz.js ) |Easy|
330
331
414|[ Third Maximum Number] ( ./0414-third-maximum-number.js ) |Easy|
331
332
415|[ Add Strings] ( ./0415-add-strings.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 409. Longest Palindrome
3
+ * https://leetcode.com/problems/longest-palindrome/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given a string s which consists of lowercase or uppercase letters, return the length
7
+ * of the longest palindrome that can be built with those letters.
8
+ *
9
+ * Letters are case sensitive, for example, "Aa" is not considered a palindrome.
10
+ */
11
+
12
+ /**
13
+ * @param {string } s
14
+ * @return {number }
15
+ */
16
+ var longestPalindrome = function ( s ) {
17
+ const set = new Set ( ) ;
18
+ return [ ...s ] . reduce ( ( count , c ) => {
19
+ return set . delete ( c ) ? count + 2 : ( set . add ( c ) , count ) ;
20
+ } , 0 ) + ( set . size > 0 ? 1 : 0 ) ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments