diff --git a/python/009_Palindrome_Number.py b/python/009_Palindrome_Number.py index b18b89d..cf3f871 100644 --- a/python/009_Palindrome_Number.py +++ b/python/009_Palindrome_Number.py @@ -9,17 +9,12 @@ class Solution(object): def isPalindrome(self, x): if x < 0: return False - ls = 0 + ls = len(str(x)) tmp = x - while tmp != 0: - ls += 1 - tmp = tmp // 10 - tmp = x - for i in range(ls/2): - right = tmp % 10 + for i in range(int(ls/2)): + right = int(tmp % 10) left = tmp / (10 ** (ls - 2 * i - 1)) - left = left % 10 - # print left, right + left = int(left % 10) if left != right: return False tmp = tmp // 10 @@ -62,4 +57,4 @@ def isPalindrome(self, x): if __name__ == '__main__': # begin s = Solution() - print s.isPalindrome(1001) \ No newline at end of file + print s.isPalindrome(1001) diff --git a/python/035_Search_Insert_Position.py b/python/035_Search_Insert_Position.py index d1a8681..9e6abd0 100644 --- a/python/035_Search_Insert_Position.py +++ b/python/035_Search_Insert_Position.py @@ -23,13 +23,21 @@ class Solution: # return pos def searchInsert(self, nums, target): - l, r = 0, len(nums) - 1 + l, r = int(0), len(nums) - 1 while l < r: - mid = (l + r) / 2 + mid = int((l + r) / 2) if nums[mid] < target: l = mid + 1 else: r = mid if nums[l] < target: return l + 1 - return l + return l + + + +if __name__ == '__main__': + # begin + s = Solution() + print (s.searchInsert([1,3,5,6],5)) +