Skip to content

Commit 8308043

Browse files
authored
Create 3517-smallest-palindromic-rearrangement-i.js
1 parent e56f504 commit 8308043

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {string} s
3+
* @return {string}
4+
*/
5+
var smallestPalindrome = function(s) {
6+
const n = s.length
7+
const pre = s.substring(0, Math.floor(n / 2))
8+
const left = Array.from(pre).sort().join('')
9+
if (n % 2 === 0) {
10+
return `${left}${left.split('').reverse().join('')}`
11+
} else {
12+
return `${left}${s[Math.floor(n / 2)]}${left.split('').reverse().join('')}`
13+
}
14+
};

0 commit comments

Comments
 (0)