Determine whether an integer is a palindrome. Do this without extra space., palindrome

Source: Internet
Author: User

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 ;}}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.