Leetcode
吴优无恧
这个作者很懒,什么都没留下…
展开
-
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 · 228 阅读 · 0 评论 -
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 · 120 阅读 · 0 评论 -
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 · 492 阅读 · 0 评论 -
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 · 225 阅读 · 0 评论