06 2023 档案
摘要:# 1 算法原理 **适用条件:有序数组** # 2 算法模板 ```python class Solution: def search(self, nums: List[int], target: int) -> int: left = 0 right = len(nums) - 1 # 规则 [
阅读全文
摘要:# 1 算法模板 ``` for 选择 in 选择列表: # 做选择 将该选择从选择列表移除 路径.add(选择) backtrack(路径, 选择列表) # 撤销选择 路径.remove(选择) 将该选择再加入选择列表 ``` # 2 代码示例 [46. 全排列](https://leetcode
阅读全文
摘要:# 1 算法原理 **适用场景:利用preSum 数组,可以在O(1)的时间内快速求出nums任意区间[i,j]内的所有元素之和** **sum(i,j) = preSum(j + 1) - preSum[i]**  { // 判断 base case // 如果坐标 (r, c) 超出了网格范围,直接返回 if (!inArea(grid, r, c)) { return; } // 访问上、下、左、右四个相邻结
阅读全文
摘要:# 1 原理 [字典树原理参考](https://blog.csdn.net/m0_46202073/article/details/107253959) # 2 构建字典树 ```python class Trie: def __init__(self): # 字典树结构 # children 数
阅读全文
摘要:# 题目 [496. 下一个更大元素 I](https://leetcode.cn/problems/next-greater-element-i/) nums1 中数字 x 的 下一个更大元素 是指 x 在 nums2 中对应位置 右侧 的 第一个 比 x 大的元素。 给你两个 没有重复元素 的数
阅读全文
摘要:# 1 题目 [5. 最长回文子串](https://leetcode.cn/problems/longest-palindromic-substring/) 给你一个字符串 s,找到 s 中最长的回文子串。 如果字符串的反序与原始字符串相同,则该字符串称为回文字符串。 示例 1: 输入:s = "
阅读全文
摘要:# 1 题目 [72. 编辑距离](https://leetcode.cn/problems/edit-distance/) 给你两个单词 word1 和 word2, 请返回将 word1 转换成 word2 所使用的最少操作数 。 你可以对一个单词进行如下三种操作: 插入一个字符 删除一个字符
阅读全文

浙公网安备 33010602011771号