0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LeetCodeの9. Palindrome Numberについて

Posted at

LeetCodeの9. Palindrome Numberについて

自分が思いついたやり方はこれ。

qiita.py
class Solution(object):
    def isPalindrome(self, x):
        if x < 0:
            return False
        else:
            y = str(x)
            z = (y[::-1])
            if y == z:
                return True
            else:
                return False

yでxをintからstrに
zはy(strになったx)の逆から
yとzが等しければTrueを返す

使った知識としては
if/selse制御構文
intとstrの使い分け
[::-1]で文字列を逆さに

こんなところでしょうか。
もうちょっと短くできるんじゃないだろうか...

LeetCodeは楽しいですね!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?