- 博客(8)
- 收藏
- 关注
原创 LeetcodeHot100_004.寻找两个正序数组的中位数
感觉是排序+查找的结合体。但是由于是在路上写的,没看见题目中要求的时间复杂度,直接使用了python的列表sort了一下。还是得掌握一下两个数组合并排序的算法。暴力版本:时间复杂度o(m+n),空间复杂度o(m+n)class Solution(object): def findMedianSortedArrays(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[
2021-11-28 15:41:44
204
原创 LeetcodeHot100_003.无重复字符的最长子串
又是查找,看了标签,显示:哈希表、滑动窗口打算使用python切片+列表实现class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ # 每一轮循环固定最大窗口,不断更新,最后输出 windows = [0] for i in range(len(s))
2021-11-26 17:38:22
113
原创 LeetcodeHot100_002.两数相加
有bug版本:class Solution(object): def addTwoNumbers(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ l3 = ListNode() # 相加 if (not l1 and not l2): ret
2021-11-26 16:08:00
487
原创 LeetcodeHot100_001.两数之和
残暴解法:o(n²)class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] tips: 1.从第一个整数开始,逐个配对 2.成功便输出,失败便下一个 """ for i in r
2021-11-25 20:22:39
198
原创 力扣上手拦路虎之列表输出
class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """需要关注输出的数据格式为list对于def而言,需要有return作为输出,而非print否则例题输出为null而想要将列表作为输出,直接return[i,j]即可..
2021-11-25 19:42:13
164
原创 力扣上手拦路虎之python的类
1. 两数之和class Solution(object): def twoSum(self, nums, target): ''' :type nums: List[int] :type target: int :rtype: List[int] '''使用类的时候需要进行初始化,否则会报错:TypeError: twoSum () missing 1 required positional argument: 't
2021-11-25 17:47:02
217
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人