Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

81 lines
1.6 KiB
Markdown

---
id: 69b58ce40693f140c84c8559
title: "Challenge 240: Palindrome Characters"
challengeType: 29
dashedName: challenge-240
---
# --description--
Given a string, determine if it's a palindrome and return the middle character (if it's odd length) or middle two characters (if it's even).
- A palindrome is a string that is the same forward and backward.
- If it's not a palindrome, return `"none"`.
# --hints--
`palindrome_locator("racecar")` should return `"e"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("racecar"), "e")`)
}})
```
`palindrome_locator("level")` should return `"v"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("level"), "v")`)
}})
```
`palindrome_locator("freecodecamp")` should return `"none"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("freecodecamp"), "none")`)
}})
```
`palindrome_locator("noon")` should return `"oo"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("noon"), "oo")`)
}})
```
`palindrome_locator("11100111")` should return `"00"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("11100111"), "00")`)
}})
```
# --seed--
## --seed-contents--
```py
def palindrome_locator(s):
return s
```
# --solutions--
```py
def palindrome_locator(s):
if s != s[::-1]:
return "none"
mid = len(s) // 2
return s[mid] if len(s) % 2 == 1 else s[mid - 1] + s[mid]
```