LeetCode in Kotlin

4030. Check ASCII Palindromic

Easy

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.

Example 1:

Input: s = “ff”

Output: true

Explanation:

Example 2:

Input: s = “leet”

Output: false

Explanation:

Constraints:

Solution

class Solution {
    fun isPalindromic(s: String): Boolean {
        val n = s.length
        for (i in 0..n / 2) {
            val lptr = s[i].code
            val rptr = s[n - i - 1].code
            for (j in 0..7) {
                val left = (lptr shr j) and 1
                val right = (rptr shr (7 - j)) and 1
                if (left != right) {
                    return false
                }
            }
        }
        return true
    }
}