LeetCode 9 的题目是 “Palindrome Number”(回文数)。题目要求如下: 题目描述: 给定一个整数 x,判断它是否是一个回文数。回文数是指正着读和倒着读都一样的整数。 示例: 输入: 121 输出: true 输入: -121 输出: false 解释: 倒着读是 121-,所以不是回文数。可见,所有负数都不是回文数字。 输入: 10...
classSolution{public:boolisPalindrome(intx){if(x <0)returnfalse;intori = x;longlongrev =0;while(x >0){ rev = rev *10+ x %10; x = x /10; }returnrev == ori?true:false; } }; 参考官方题解_翻转一半 classSolution{public:boolisPalindrome(intx){if(x <0|| (x %10==0&& x !
Can you solve this real interview question? Palindrome Number - Given an integer x, return true if x is a palindrome, and false otherwise. Example 1: Input: x = 121 Output: true Explanation: 121 reads as 121 from left to right and from right to lef
LeetCode 9. Palindrome Number(c语言版) 题目: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input:121Output:true Example 2: Input:-121Output:falseExplanation:From left to right, it reads -121. From right to...
1. public boolean isPalindrome(int x) { 2. String s = String.valueOf(x); 3. for(int i=0;i<s.length()/2;i++){ 4. if(s.charAt(i)!=s.charAt(s.length()-1-i)) 5. return false; 6. } 7. return true; 8. } 1. ...
public boolean isPalindrome(int x) { if(x < 0 || (x % 10 == 0 && x != 0)) return false; int revertedNumber = 0; while(x > revertedNumber) { revertedNumber = revertedNumber * 10 + x % 10; x /= 10; } return x == revertedNumber || x == revertedNumber/10; } 时间复...
public class Solution { public boolean isPalindrome(int x) { if (x < 0 || (x != 0 && x % 10 == 0)) return false; int r = 0; while (x > r) { r = r * 10 + x % 10; x = x /10; } return x == r || x == r / 10; } }版权...
class Solution { public: bool isPalindrome(int x) { if(x<0){ return false; } vector<int> v1; while(x){ v1.push_back(x%10); x=x/10; } int i=0; int j=v1.size()-1; while(i<j){ if(v1[i]!=v1[j]){ return false; ...
1745-palindrome-partitioning-iv Time: 105 ms (42.35%), Space: 90.7 MB (7.06%) - LeetHub Mar 7, 2024 1798-max-number-of-k-sum-pairs Time: 47 ms (15.22%), Space: 55.4 MB (47.65%) - LeetHub Jun 1, 2023 1806-minimum-number-of-operations-to-reinitialize-a-permutation Time: 22 ms...
1241 Number of Comments per Post * $ 68.00% Easy 1240 Tiling a Rectangle with the Fewest Squares 52.40% Hard 1239 Maximum Length of a Concatenated String with Unique Characters 50.70% Medium 1238 Circular Permutation in Binary Representation 67.90% Medium 1237 Find Positive Integer Solution for a...