deno.land / x / masx200_leetcode_test@10.6.5 / break-a-palindrome / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
export default function breakPalindrome(palindrome: string): string { if (palindrome.length <= 1) return "";
const str = [...palindrome]; const index = str.findIndex((c, i) => c !== "a" && i < Math.floor(palindrome.length / 2) ); if (index < 0) return str.slice(0, str.length - 1).join("") + "b"; return str.map((v, i) => i === index ? "a" : v).join("");}
masx200_leetcode_test

Version Info

Tagged at
a year ago