1
0

4 Revīzijas ed63d390a0 ... 52ae422802

Autors SHA1 Ziņojums Datums
  xxt 52ae422802 回文数 10 mēneši atpakaļ
  xxt 8a0d10c3ff 回文数 10 mēneši atpakaļ
  xxt 43956395a0 回文数 10 mēneši atpakaļ
  xxt c44f6208c5 回文数 10 mēneši atpakaļ
2 mainītis faili ar 93 papildinājumiem un 0 dzēšanām
  1. 42 0
      array/isPalindrome.py
  2. 51 0
      array/isPalindrome2.py

+ 42 - 0
array/isPalindrome.py

@@ -0,0 +1,42 @@
+import unittest
+
+
+class Solution:
+    def isPalindrome(self, x: int) -> bool:
+        if str(x) == str(x)[::-1]:
+            return True
+        else:
+            return False
+
+
+
+
+
+
+
+
+class TestisPalindrome(unittest.TestCase):
+    def test_isPalindrome(self):
+        x = 121
+        s = Solution()
+        res = s.isPalindrome(x)
+        self.assertEqual(res, True)
+
+    def test_isPalindrome2(self):
+        x = -121
+        s = Solution()
+        res = s.isPalindrome(x)
+        self.assertEqual(res, False)
+
+
+    def test_isPalindrome3(self):
+        x = 1221
+        s = Solution()
+        res = s.isPalindrome(x)
+        self.assertEqual(res, True)
+
+    def test_isPalindrome4(self):
+        x = 1231
+        s = Solution()
+        res = s.isPalindrome(x)
+        self.assertEqual(res, False)

+ 51 - 0
array/isPalindrome2.py

@@ -0,0 +1,51 @@
+import unittest
+
+
+class Solution:
+    def isPalindrome(self, x: int) -> bool:
+        if x < 0:
+            return False
+        a = 0
+        t = x
+        while x:
+            a = a * 10 + x % 10
+            print("a",a)
+            x = x // 10
+            print("x", x)
+        return t == a
+
+
+
+
+
+
+
+
+
+
+
+class TestisPalindrome(unittest.TestCase):
+    def test_isPalindrome(self):
+        x = 121
+        s = Solution()
+        res = s.isPalindrome(x)
+        self.assertEqual(res, True)
+
+    def test_isPalindrome2(self):
+        x = -121
+        s = Solution()
+        res = s.isPalindrome(x)
+        self.assertEqual(res, False)
+
+
+    def test_isPalindrome3(self):
+        x = 12321
+        s = Solution()
+        res = s.isPalindrome(x)
+        self.assertEqual(res, True)
+
+    def test_isPalindrome4(self):
+        x = 1231
+        s = Solution()
+        res = s.isPalindrome(x)
+        self.assertEqual(res, False)