Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added python solution for 9. palindrome number
  • Loading branch information
blankaex committed Oct 19, 2021
commit b32e3255d3d1ec28308cc2832aad8c0061756116
19 changes: 19 additions & 0 deletions Python/9.PalindromeNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# compare reverse method
# simply reverse the input and check equality
class Solution:
def isPalindrome(self, x: int) -> bool:
return str(x) == str(x)[::-1]

# double pointer method
# start at either end of the number and go inwards
# return false if a number doesn't match, otherwise it's a palindrome
class Solution:
def isPalindrome(self, x: int) -> bool:
arr = str(x)
l, r = 0, len(arr) - 1
while r > l:
if arr[l] != arr[r]:
return False
l +=1
r -= 2
return True
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
| :--: | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------------- |
| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [Python](./Python/Longest_Substring_Without_Repeating_Characters.py) | _O(n)_ | _O(n)_ | Medium | `Hash Table`<br/>`Sliding Window` | Open for improvisation, mentioned time and space complexities unconfirmed |
| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/) | [Java](./Java/string-to-integer-atoi.java) | _O(n)_ | _O(1)_ | Medium | | |
| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | |
| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) <br> [Python](./Python/9.PalindromeNumber.py) | _O(n)_ | _O(1)_ | Easy | | |
| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/) | [Java](./Java/reverse-words-in-a-string.java) | _O(1)_ | _O(n)_ | Medium | | |
| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note/) | [Java](./Java/ransom-note.java) | _O(1)_ | _O(n)_ | Easy | | Character Count |
| 387 | [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/) | [Java](./Java/first-unique-character-in-a-string.java) | _O(n)_ | _O(1)_ | Easy | | Character Count |
Expand Down