04 2020 档案
摘要:判断ab是否相等 assertEqual(a, b) 判断ab不相等 assertNotEqual(a, b) 判断a是b assertIs(a, b) 判断a不是b assertIsNot(a, b) 判断a是不是None assertIsNone(a) 判断a不是None assertIsNot
阅读全文
摘要:1.题目 2.代码实现: # 快慢双指针追赶碰撞解法,时间复杂度为O(n),空间复杂度为O(1) if not head: return head slow = head quick = head while quick and slow: # 这里因为quick是跳两次,所以要判断quick和qu
阅读全文
摘要:1.题目 把归并结果存到第一个数组上: Input: nums1 = [1,2,3,0,0,0], m = 3 nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] 2.代码实现: class Solution: def merge(self, nums1: Li
阅读全文
摘要:1.题目 可以删除一个字符,判断是否能构成回文字符串。: Input: "abca" Output: True Explanation: You could delete the character 'c'. 2.代码实现: class Solution(object): def validPali
阅读全文
摘要:1.题目 找到字符串中的元音,翻转如下: Given s = "leetcode", return "leotcede". 2.代码实现: class Solution: def reverseVowels(self, s: str) -> str: dict = {'a','e','i','o',
阅读全文
摘要:1.题目描述: 判断一个非负整数是否为两个整数的平方和。 2.同Leetcode167,使用双指针来解题 import math class Solution: def judgeSquareSum(self, c: int) -> bool: if c < 0: return False #如果c
阅读全文
摘要:1.题目描述:在有序数组中找出两个数,使它们的和为 target。 Input: numbers={2, 7, 11, 15}, target=9 Output: index1=1, index2=2 2.解题思路:1.升序排列的数组2.使用双指针,一个指针指向值较小的元素,另一个指针指向值较大的索
阅读全文

浙公网安备 33010602011771号