Determine whether an integer is a palindrome. Do this without extra space., palindrome
When I saw this question, I first did not know the word "Determine". I couldn't help it in English. I checked the meaning of the question and found out the meaning of "palindrome.
The problem is what the text is. the official explanation is: A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.
Although the English language is not good, I still understand the English explanation. This means that reading is the same as reading from the back.
Do this without extra space in the following sentence. It probably means that other spaces cannot be used during implementation.
I do not know that the call of the Math. pow () method in the second method does not use other space.
Public class palindrome {// using with extra spacepublic static boolean check (int x) {String temp = Integer. toString (x); boolean flag = true; for (int I = 0; I <temp. length ()/2; I ++) {char a = temp. charAt (I); char B = temp. charAt (temp. length ()-i-1); if (! = B) {flag = false ;}} return flag ;}// using without extra spacepublic static boolean check2 (int x) {if (x <0) return false; int n = 1; int temp = x; while (temp/10! = 0) {temp = temp/10; n ++;} for (int I = 0; I <n/2; I ++) {int a = I; int B = n-1-i; if (getInt (x, )! = GetInt (x, B) {return false ;}} return true ;}// for example, to obtain a hundred bits, divide it by 896698, get 8966 and get 6 from the remaining 10, that is, the-bit value private static int getInt (int x, int I) {int a = (int) Math. pow (10, I); return (x/a) % 10 ;}}