From ecdaadcd389dcac3871b1e8ceae9ee835ac5cbb1 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 10 Jan 2025 04:30:49 -0600 Subject: [PATCH] adding palindrome number algo --- .../palindrome_number.py | 9 +++++++++ .../test_palindrome_number_round_12.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_12/palindrome_number.py create mode 100644 tests/test_150_questions_round_12/test_palindrome_number_round_12.py diff --git a/src/my_project/interviews/top_150_questions_round_12/palindrome_number.py b/src/my_project/interviews/top_150_questions_round_12/palindrome_number.py new file mode 100644 index 00000000..80952ebd --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_12/palindrome_number.py @@ -0,0 +1,9 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def isPalindrome(self, x: int) -> bool: + + str_x = str(x) + + return str_x == str_x[::-1] \ No newline at end of file diff --git a/tests/test_150_questions_round_12/test_palindrome_number_round_12.py b/tests/test_150_questions_round_12/test_palindrome_number_round_12.py new file mode 100644 index 00000000..a7ada3ad --- /dev/null +++ b/tests/test_150_questions_round_12/test_palindrome_number_round_12.py @@ -0,0 +1,16 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_12\ +.palindrome_number import Solution + + +class PalindromeNumberTestCase(unittest.TestCase): + + def test_is_palindrome_number(self): + solution = Solution() + output = solution.isPalindrome(x=121) + self.assertTrue(output) + + def test_is_no_palindrome_number(self): + solution = Solution() + output = solution.isPalindrome(x=123) + self.assertFalse(output) \ No newline at end of file