Skip to content

Commit f1ac5ce

Browse files
committed
Create 409.最长回文串.js
1 parent 5593313 commit f1ac5ce

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

409.最长回文串.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var longestPalindrome = function(s) {
6+
const arr = new Array(128).fill(0);
7+
let result = 0;
8+
for (let i = 0; i < s.length; i++) {
9+
const n = s.charCodeAt(i);
10+
arr[n]++;
11+
if (arr[n] >= 2) {
12+
result += 2;
13+
arr[n] -= 2;
14+
}
15+
}
16+
return result + (arr.indexOf(1) === -1 ? 0 : 1);
17+
};

0 commit comments

Comments
 (0)