We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 28281f7 commit 736f66aCopy full SHA for 736f66a
409-longest-palindrome.js
@@ -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
24
/**
25
* @param {string} s
26
* @return {number}
0 commit comments