Leetcode
Given an integer x
, return true if x
is palindrome integer.
An integer is a palindrome when it reads the same backward as forward. For example, 121
is palindrome while 123
is not.
Example 1:
Input: x = 121
Output: true
Example 2:
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Example 4:
Input: x = -101
Output: false
Constraints:
-231 <= x <= 231 - 1
class Solution:
def isPalindrome(self, x: int) -> bool:
tmp = str(x)
Palindrome = tmp[::-1]
return tmp == Palindrome
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
Palindrome = 0
ori = x
while(x != 0):
tmp = x%10
x = (x-tmp)/10
Palindrome = Palindrome*10+tmp
return ori == Palindrome
CH8 在線廣告實現 流程 每人先對本次進行自己的總結 問題討論 2022.02.16 問題討論
Mar 16, 2022題目 Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2:
Oct 25, 2021Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1 Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100]. Example 2 Input: nums = [-7,-3,2,3,11]
Jun 7, 2021You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n. Example 1 Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Explanation: The arrays we are merging are [1,2,3] and [2,5,6].
Jun 7, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up