Beginner here. I did "Leetcode 9. Palindrone Number" and think I figured out the solution, but as a beginner I am not familiar with some basic Python formats.
Leetcode Problem =
- Given an integer x, return true if x is a palindrome, and false otherwise.
My Code Solution =
`input_string_for_test = "1155215511"
bucket_1 = []
bucket_2 = []
boolean_bucket = 0
bucket_1.append(input_string_for_test)
bucket_2.append(input_string_for_test[::-1])
'''
print(bucket_1)
print(bucket_2)
'''
if bucket_1 == bucket_2:
boolean_bucket =+ 1
'''
print("PALINDROME")
'''
print(bool(boolean_bucket))
else:
'''
print("NO")
'''
print(bool(boolean_bucket))`
**The Leetcode required format = **
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
How can I convert my code into what Leetcode requires, so that I can submit my attempt?
Many thanks!
Im not familiar/fluent with Syntax because I am just a hobbyist who enjoys coding in my free time.
I tried to change "bucket_1.append(input_string_for_test" to "bucket_1.append(x)", but the error message was this:
TypeError: 'int' object has no attribute '__getitem__'
bucket_2.append(x[::-1])
Line 12 in isPalindrome (Solution.py)
ret = Solution().isPalindrome(param_1)
Line 43 in _driver (Solution.py)
_driver()
Line 53 in <module> (Solution.py)