Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to judge palindromes in LeetCode

Shulou Source: shulou.com Published: 2022-06-02 05:51:53 10月05日 Update

LeetCode how to judge the number of palindrome, I believe that many people without experience can do nothing about this, this article summarizes the causes and solutions of the problem, through this article I hope you can solve this problem.

Idea 1: Turn to character string to determine whether the original character string is consistent with the inverted character string

When a palindrome number is converted into a character string, it has the same characteristics as the original character string and the inverted character string, while a non-palindrome number does not have this characteristic, so it can be judged whether it is a palindrome number in this way. This idea is easier to understand, and you can find that negative numbers are not palindrome numbers (such as: -11 read from the right is 11-), so you can return negative numbers to false first, avoiding more calculations later.

class Solution: def isPalindrome(self, x: int) : if(x

Tags: Palindromes characters strings input output operations halves ideas more content numbers methods characteristics results negative numbers problems identical consistent helpless for this reason Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi OPPO Reno Shulou Technology MySQL Shulou Tech Info