《leetCode》:palindrome Number

xiaoxiao2021-02-28  127

题目描述

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

题目大意:即检测一个数是否为回文数,不开辟额外的空间

public boolean isPalindrome(int x) { if (x<0 || (x!=0 && x==0)) return false; int rev = 0; while (x>rev){ rev = rev*10 + x; x = x/10; } return (x==rev || x==rev/10); }

转载请注明原文地址: https://www.6miu.com/read-37405.html

最新回复(0)