摘要: class Solution: def searchInsert(self, nums: List[int], target: int) -> int: # 如果目标数大于列表中最大的数,就返回最后的位置 if target > nums[len(nums) - 1]: return len(nums) ... 阅读全文
posted @ 2019-08-21 22:23 我叫郑小白 阅读(110) 评论(0) 推荐(0) 编辑
摘要: class Solution: def isPalindrome(self, x: int) -> bool: # 参考 7.整数反转 num = 0 a = abs(x) while(a != 0): temp = a % 10 num = num*10 + temp a = a//10 if x >= 0 and x == num: return True else: return False 阅读全文
posted @ 2019-08-21 22:13 我叫郑小白 阅读(85) 评论(0) 推荐(0) 编辑
摘要: class Solution: def reverse(self, x: int) -> int: num = 0 # 取绝对值 a = abs(x) while(a != 0): # 首先,假设 a = 123 # num = 0 # a = 12 # num = 3 # a = 1 # num = 32 # a = 0 # num = 321 # a=0时,结束循环 temp = a % 10 阅读全文
posted @ 2019-08-21 22:04 我叫郑小白 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 方法一: 方法二: 阅读全文
posted @ 2019-08-21 15:35 我叫郑小白 阅读(137) 评论(0) 推荐(0) 编辑
摘要: class Solution: def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: # 创建一个初始链表 curr = dummy = ListNode(0) # 遍历两个链表 while l1 and l2: ... 阅读全文
posted @ 2019-08-21 11:13 我叫郑小白 阅读(137) 评论(0) 推荐(0) 编辑
摘要: class Solution: def removeElement(self, nums: List[int], val: int) -> int: # 定义两个指针,一个头,一个尾 i, last = 0, len(nums) - 1 while i <= last: # 判断头指针当前对应的列表中的值是否与val相等 # 若是,则头指针和尾指针对应的数进行调换 if nums[i] == va 阅读全文
posted @ 2019-08-21 10:00 我叫郑小白 阅读(103) 评论(0) 推荐(0) 编辑