9 check Palindrome Number by using python
By splitting string python can deal with this problem easily.
string[a:b:c]
意思是從c為間隔從a開始一直取到b(注意不含b) s[0:8] returns everything up to, but not including, the character at position 8
so reverse a string a can be a[::-1]
class Solution:
# @return a boolean
def isPalindrome(self, x):
a=str(x)
b=a[::-1]
if a==b:
return True
else:
return False
Before I tried to use the common method like I did in C, using for loop to give x and reversion of x to different string a,b and check if a and b are same. But I found it has a mistake. Because the string in python is immutable. I CAN'T DO a[i]=x[i].
相關文章
- Leetcode 9 Palindrome NumberLeetCode
- [LeetCode] 9. Palindrome NumberLeetCode
- LeetCode - 9. Palindrome NumberLeetCode
- LeetCode 第 9 題(Palindrome Number)LeetCode
- 【LeetCode從零單排】No.9 Palindrome NumberLeetCode
- leetcode Palindrome NumberLeetCode
- Using the WITH CHECK OPTION
- Palindrome Number leetcode javaLeetCodeJava
- LeetCode Palindrome Number(009)解法總結LeetCode
- LeetCode - 解題筆記 - 8 - Palindrome NumberLeetCode筆記
- leetcode學習筆記09 palindrome-numberLeetCode筆記
- [LeetCode] Palindrome Number 驗證迴文數字LeetCode
- How to check whether the current database in using Oracle optionsDatabaseOracle
- leetcode第九題Palindrome Number 驗證迴文數字LeetCode
- Python Number(數字)Python
- [MetalKit]15-Using-MetalKit-part-9使用MetalKit9
- Paging Records Using SQL Server 2005 Database - ROW_NUMBER FunctionSQLServerDatabaseFunction
- pdf crop using pythonPython
- Palindrome PairsAI
- 9 Rules for Using Color in Business Intelligence DashboardsIntel
- Using Python to Shorten a URL Using Google's Shortening ServicePythonGo
- Python學習筆記——Python Number(數字)Python筆記
- vue報錯:[Vue warn]: Invalid prop: type check failed for prop "value". Expected Number, got String....VueAIGo
- [MetalKit]9-Using-MetalKit-part-8使用MetalKit8
- Using lxml.objectify to Parse XML With PythonXMLObjectPython
- 關於Python Number 相關的知識!Python
- onclick="return check()" 和 onclick="check()" 區別
- Using sub-generators for lexical scanning in PythonPython
- 搞定字串類面試題-Palindrome字串面試題
- LeetCode-Palindrome PairsLeetCodeAI
- Leetcode Valid PalindromeLeetCode
- Python_9_Codecademy_9_Lists and FunctionsPythonFunction
- Python技術之Number資料型別介紹Python資料型別
- LeetCode-Palindrome Permutation IILeetCode
- 【LeetCode】Palindrome Pairs(336)LeetCodeAI
- LeetCode-Valid PalindromeLeetCode
- Leetcode: Palindrome Partitioning IILeetCode
- [LintCode] Palindrome Linked List