摘要: 数组和字符串 三数之和 leetcode-python-三数之和 - 泊鸽 - 博客园 (cnblogs.com) 矩阵置0 leetcode-python-矩阵置0 - 泊鸽 - 博客园 (cnblogs.com) 字母异位词分组 leetcode-python-字母异位词分组 - 泊鸽 - 博客 阅读全文
posted @ 2021-06-13 22:56 泊鸽 阅读(27) 评论(0) 推荐(0)
摘要: 1)先对所有字符串重排序,然后取set获得总共的分组个数。再逐个判断加入。时间复杂度太高了 class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: def so(x): x= sorted(x) ret 阅读全文
posted @ 2021-06-13 22:54 泊鸽 阅读(117) 评论(0) 推荐(0)
摘要: 笨比方法,空间复杂度较高 1)逐行遍历,发现0记录列的位置,然后当前行全为0。最后再遍历一次,每行的对应列也置0 class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: """ Do not return anyth 阅读全文
posted @ 2021-06-13 22:06 泊鸽 阅读(147) 评论(0) 推荐(0)
摘要: 想了很久,双指针的方法一直超时。可能是python的特性。 主要有两个问题:1)重复列表判断;2)遍历 方法: 1)暴力三重for循环,O(n^3),会超时 2)先排序,然后双指针 class Solution: def threeSum(self, nums: List[int]) -> List 阅读全文
posted @ 2021-06-13 20:17 泊鸽 阅读(92) 评论(0) 推荐(0)