摘要: # 实例代码 ```python import matplotlib.pyplot as plt import matplotlib.cm as cm import numpy as np import pandas as pd from sklearn.cluster import KMeans 阅读全文
posted @ 2023-07-05 15:56 柳叶昶 阅读(77) 评论(0) 推荐(0) 编辑
摘要: # 1 算法原理 **适用条件:有序数组** # 2 算法模板 ```python class Solution: def search(self, nums: List[int], target: int) -> int: left = 0 right = len(nums) - 1 # 规则 [ 阅读全文
posted @ 2023-06-11 10:54 柳叶昶 阅读(0) 评论(0) 推荐(0) 编辑
摘要: # 1 算法模板 ``` for 选择 in 选择列表: # 做选择 将该选择从选择列表移除 路径.add(选择) backtrack(路径, 选择列表) # 撤销选择 路径.remove(选择) 将该选择再加入选择列表 ``` # 2 代码示例 [46. 全排列](https://leetcode 阅读全文
posted @ 2023-06-08 20:33 柳叶昶 阅读(3) 评论(0) 推荐(0) 编辑
摘要: # 1 算法原理 **适用场景:利用preSum 数组,可以在O(1)的时间内快速求出nums任意区间[i,j]内的所有元素之和** **sum(i,j) = preSum(j + 1) - preSum[i]** ![](https://img2023.cnblogs.com/blog/21670 阅读全文
posted @ 2023-06-08 20:33 柳叶昶 阅读(13) 评论(0) 推荐(0) 编辑
摘要: # 1 算法模板 ``` void dfs(int[][] grid, int r, int c) { // 判断 base case // 如果坐标 (r, c) 超出了网格范围,直接返回 if (!inArea(grid, r, c)) { return; } // 访问上、下、左、右四个相邻结 阅读全文
posted @ 2023-06-08 17:13 柳叶昶 阅读(3) 评论(0) 推荐(0) 编辑
摘要: # 1 原理 [字典树原理参考](https://blog.csdn.net/m0_46202073/article/details/107253959) # 2 构建字典树 ```python class Trie: def __init__(self): # 字典树结构 # children 数 阅读全文
posted @ 2023-06-06 16:17 柳叶昶 阅读(7) 评论(0) 推荐(0) 编辑
摘要: # 题目 [496. 下一个更大元素 I](https://leetcode.cn/problems/next-greater-element-i/) nums1 中数字 x 的 下一个更大元素 是指 x 在 nums2 中对应位置 右侧 的 第一个 比 x 大的元素。 给你两个 没有重复元素 的数 阅读全文
posted @ 2023-06-05 10:41 柳叶昶 阅读(0) 评论(0) 推荐(0) 编辑
摘要: # 1 题目 [5. 最长回文子串](https://leetcode.cn/problems/longest-palindromic-substring/) 给你一个字符串 s,找到 s 中最长的回文子串。 如果字符串的反序与原始字符串相同,则该字符串称为回文字符串。 示例 1: 输入:s = " 阅读全文
posted @ 2023-06-02 00:40 柳叶昶 阅读(10) 评论(0) 推荐(0) 编辑
摘要: # 1 题目 [72. 编辑距离](https://leetcode.cn/problems/edit-distance/) 给你两个单词 word1 和 word2, 请返回将 word1 转换成 word2 所使用的最少操作数 。 你可以对一个单词进行如下三种操作: 插入一个字符 删除一个字符 阅读全文
posted @ 2023-06-01 16:27 柳叶昶 阅读(5) 评论(0) 推荐(0) 编辑
摘要: # 题目 力扣 1143 [力扣1143](https://leetcode.cn/problems/longest-common-subsequence/) 给定两个字符串 text1 和 text2,返回这两个字符串的最长 公共子序列 的长度。如果不存在 公共子序列 ,返回 0 。 一个字符串的 阅读全文
posted @ 2023-05-31 19:26 柳叶昶 阅读(13) 评论(0) 推荐(0) 编辑