[LeetCode] Check ASCII Palindromic

4030. Check ASCII Palindromic

You are given a string s consisting of lowercase English letters.

Construct a binary string by replacing each character in s with the 8-bit binary representation of its ASCII value, including leading zeros, while preserving the original order of the characters.

Return true if the resulting binary string is a palindrome. Otherwise, return false.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public:
bool isPalindromic(string s) {
string ss;
for(auto& ch : s) {
ss += format("{:08b}", ch);
}
cout<<ss<<endl;
for(int l = 0, r = ss.size() - 1; l < r; l++,r--) {
if(ss[l] != ss[r]) return false;
}
return true;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/03/PS/LeetCode/check-ascii-palindromic/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.