wuyijia

导航

2023年9月10日 #

代码随想录算法训练营-回溯算法|491.递增子序列、46. 全排列、47. 全排列 II、332. 重新安排行程、37. 解数独

摘要: 491. 递增子序列 不对原数组进行排序,利用set对同层的子集进行去重。 1 class Solution: 2 def findSubsequences(self, nums): 3 result = [] 4 path = [] 5 self.backtracking(nums, 0, pat 阅读全文

posted @ 2023-09-10 13:19 小吴要努力 阅读(4) 评论(0) 推荐(0) 编辑

2023年9月5日 #

二叉树-257二叉树的所有路径带回溯思想、404. 左叶子之和

摘要: 257. 二叉树的所有路径 1 # Definition for a binary tree node. 2 # class TreeNode: 3 # def __init__(self, val=0, left=None, right=None): 4 # self.val = val 5 # 阅读全文

posted @ 2023-09-05 15:07 小吴要努力 阅读(1) 评论(0) 推荐(0) 编辑

2023年8月29日 #

链表-代码随想录234. 回文链表、143. 重排链表

摘要: 链表问题:双指针、迭代法、递归法(天然可用)、虚拟头节点 双链表 既可以向前查询也可以向后查询。 循环链表,顾名思义,就是链表首尾相连。循环链表可以用来解决约瑟夫环问题。 234. 回文链表 1 # Definition for singly-linked list. 2 # class ListN 阅读全文

posted @ 2023-08-29 08:24 小吴要努力 阅读(4) 评论(0) 推荐(0) 编辑

2023年8月28日 #

数组二分查找:35. 搜索插入位置、34. 在排序数组中查找元素的第一个和最后一个位置、69. x 的平方根、367.有效的完全平方数

摘要: 35. 搜索插入位置 1 class Solution: 2 def searchInsert(self, nums: List[int], target: int) -> int: 3 left, right = 0, len(nums)-1 4 5 while left <= right: #左 阅读全文

posted @ 2023-08-28 19:26 小吴要努力 阅读(2) 评论(0) 推荐(0) 编辑

哈希表基础题217. 存在重复元素、389. 找不同、496. 下一个更大元素 I

摘要: 217. 存在重复元素 1 class Solution: 2 def containsDuplicate(self, nums: List[int]) -> bool: 3 #方法1:set去重,直接比较去重之后数组长度 4 if len(set(nums)) != len(nums): 5 re 阅读全文

posted @ 2023-08-28 13:22 小吴要努力 阅读(3) 评论(0) 推荐(0) 编辑

2023年8月27日 #

数组章节的进阶54. 螺旋矩阵、904. 水果成篮、76. 最小覆盖子串、26. 删除有序数组中的重复项

摘要: 54. 螺旋矩阵 1 class Solution: 2 def spiralOrder(self, matrix: List[List[int]]) -> List[int]: 3 m, n = len(matrix), len(matrix[0]) 4 res = [] #存放遍历后的结果 5 阅读全文

posted @ 2023-08-27 21:19 小吴要努力 阅读(4) 评论(0) 推荐(0) 编辑

2023年8月26日 #

栈基础题20、496、232

摘要: 20. 有效的括号 1 class Solution: 2 #遍历完字符串后,栈是空的,说明全部匹配了 3 def isValid(self, s: str) -> bool: 4 stack = [] 5 #剪枝 6 if len(s) % 2 != 0: 7 return False 8 9 f 阅读全文

posted @ 2023-08-26 20:03 小吴要努力 阅读(5) 评论(0) 推荐(0) 编辑

2023年8月25日 #

基础题队列933、225、622、641

摘要: 933. 最近的请求次数 1 class RecentCounter: 2 3 def __init__(self): 4 self.q = collections.deque() 5 6 def ping(self, t: int) -> int: 7 self.q.append(t) 8 9 w 阅读全文

posted @ 2023-08-25 16:51 小吴要努力 阅读(12) 评论(0) 推荐(0) 编辑

基础题链表203、206

摘要: 203. 移除链表元素 也可以用栈解决:(程序员小熊) 1 # Definition for singly-linked list. 2 # class ListNode: 3 # def __init__(self, val=0, next=None): 4 # self.val = val 5 阅读全文

posted @ 2023-08-25 16:22 小吴要努力 阅读(3) 评论(0) 推荐(0) 编辑

2023年8月24日 #

基础题数组-485、283、27

摘要: 485. 最大连续 1 的个数 1 class Solution: 2 def findMaxConsecutiveOnes(self, nums: List[int]) -> int: 3 maxCount = count = 0 4 5 for i, num in enumerate(nums) 阅读全文

posted @ 2023-08-24 10:50 小吴要努力 阅读(4) 评论(0) 推荐(0) 编辑