Day6-9. Palindrome Number

9. Palindrome Number(easy)

Given an integer x, return true if x is palindrome integer.

An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not.

Example 1:
Input: x = 121
Output: true

Example 2:
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.

Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

Example 4:
Input: x = -101
Output: false

Constraints:
-231 <= x <= 231 - 1

My solution

class Solution:
    def isPalindrome(self, x: int) -> bool:

        num = str(x)
        reverse = num[::-1]

        if num==reverse:
            return True
        else:
            return False

以下是在讨论区看到别人的做法

def isPalindrome(self, x: int) -> bool:
	if x<0:
		return False

	inputNum = x
	newNum = 0
	while x>0:
		newNum = newNum * 10 + x%10
		x = x//10
	return newNum == inputNum

Result

https://ithelp.ithome.com.tw/upload/images/20210921/20140843EKWryueZNp.png

今天偷懒只写了一题easy的
而且还使用了小作弊的方法

明天要进去实验室了
今天在进行收心操的部分
祝我顺利

也希望大家连假後的明天都顺利!!


<<:  【第二十一天 - Graph 题目分析】

>>:  [Day6] 开发环境建置

day26: 开始体验 ramda.js

今天我们要开始体验 Ramda,请大家到 Ramda.js 官网安装 Ramda 後, 就可以开始以...

Day-27 特集:测试驱动开发 TDD

所谓测试驱动开发(Test-driven development, TDD),即「先写测试再开发」,...

庄家 show hand 了? - 竭尽点 ?

今年是台股放量的一年,也是新一代韭菜毕业的一年 很多人提到无本当冲多好赚之类的 但当冲没看懂方向真的...

[Day 14] 表格图页面建立

 这篇主要是根据网路上的 Code 建立的(其实是看书学的),主要是用来了解 UITableView...

Day03. 进入No code/Low code 的世界- 安装 Blue Prism

可曾想过一家企业有着IT与非IT背景的团队(例如:行销部门)共事, 企业如何运用这些人才解决这每日堆...