Skip to content

Commit 736f66a

Browse files
authored
Update 409-longest-palindrome.js
1 parent 28281f7 commit 736f66a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

409-longest-palindrome.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const longestPalindrome = function (s) {
6+
const set = new Set()
7+
let counter = 0
8+
for (let i = 0; i < s.length; i++) {
9+
const currentChar = s[i]
10+
if (set.has(currentChar)) {
11+
counter++
12+
set.delete(currentChar)
13+
} else {
14+
set.add(currentChar)
15+
}
16+
}
17+
counter *= 2
18+
if (set.size > 0) counter++
19+
return counter
20+
}
21+
22+
// another
23+
124
/**
225
* @param {string} s
326
* @return {number}

0 commit comments

Comments
 (0)