Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- /**
- * @param n: non-negative integer n.
- * @return: return whether a binary representation of a non-negative integer n is a palindrome.
- */
- public boolean isPalindrome(int n) {
- // write code here.
- int[] bin = new int[32];
- int len = 0;
- do {
- bin[len++] = n & 1;
- n >>= 1;
- } while (n > 0);
- for (int i = 0; i < len / 2; i++) {
- if (bin[i] != bin[len - i - 1]) {
- return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment