自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(211)
  • 收藏
  • 关注

原创 传统图像--LBP特征

一些传统的图像处理方法,留着自己看

2022-06-18 23:49:45 257 1

原创 滑动窗口+前缀和-9--LC1248.统计[优美子数组]

class Solution(object): def numberOfSubarrays(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ def leK(nums, k): start = 0 odd_count = 0 count = .

2022-05-10 11:29:26 348

原创 滑动窗口+前缀和-8--LC930.和相同的二元子数组

class Solution(object): def numSubarraysWithSum(self, nums, goal): """ :type nums: List[int] :type goal: int :rtype: int """ # 1.前缀和 presum = 0 adict = {0:1} count = 0 for.

2022-05-10 10:53:35 264

原创 前缀和-LC560.和为K的子数组

class Solution(object): def subarraySum(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ # 前缀和+哈希表优化 # 使用哈希表,空间换时间 # 在遍历的过程中构建前缀和 # 使用哈希表或者字典记录每个前缀和出现的次数 .

2022-05-09 23:17:12 129

原创 滑动窗口+前缀和-7--LC992.K个不同整数的子数组

class Solution(object): def subarraysWithKDistinct(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ # 904题的进阶,904是寻找最长,这里限定了种类个数k # 这里涉及到状态回缩 # end在for循环里自动更新,end每次只.

2022-05-09 19:09:32 167

原创 滑动窗口-6--LC1004.最大连续1的个数III

class Solution(object): def longestOnes(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ max_len = float('-inf') star = 0 count = 0 for end in range(len(nums.

2022-04-28 13:16:52 87

原创 滑动窗口-5--LC904.水果成篮

class Solution(object): def minWindow(self, s, t): """ :type s: str :type t: str :rtype: str """ # 滑动窗口,不定长问题 from collections import Counter temp = Counter(t) # 定义一个与t一样的滑动窗口字典 .

2022-04-28 12:26:58 114

原创 滑动窗口-4--LC76.最小覆盖子串

class Solution(object): def minWindow(self, s, t): """ :type s: str :type t: str :rtype: str """ # 滑动窗口,不定长问题 from collections import Counter temp = Counter(t) # 定义一个与t一样的滑动窗口字典 .

2022-04-27 10:32:46 409

原创 滑动窗口-3--LC567.字符串的排列

class Solution(object): def checkInclusion(self, s1, s2): """ :type s1: str :type s2: str :rtype: bool """ # 滑动窗口 # 这个题与28是同类的,都是定长的滑动窗口问题 # 不同在于,此题考虑到排列,排列乍一看比较麻烦,需要考虑的情况很多 # 我们可.

2022-04-26 22:45:02 286

原创 滑动窗口-2--LC3.无重复字符的最长子串

class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ # 滑动窗口 if not len(s): return 0 # 最大就定义极小,最小就定义极大 res = float('-inf') i .

2022-04-26 22:22:23 286

原创 滑动窗口-1--LC28.实现strStr()

class Solution(object): def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """ # API # return haystack.find(needle) # 滑动窗口 star = 0 .

2022-04-26 22:18:27 354

原创 双指针-2--LC977.有序数组的平方

class Solution(object): def sortedSquares(self, nums): """ :type nums: List[int] :rtype: List[int] """ # 双指针法 # 非递减顺序的整数数组有三种情况“ # 1.非负数,平方后还是非递减 # 2.负数,平方后是非递增 # 3.有正有负,要具体考虑 .

2022-04-24 02:27:43 196

原创 双指针-2--LC844.比较含退格的字符串

class Solution(object): def backspaceCompare(self, s, t): """ :type s: str :type t: str :rtype: bool """ # 1.用栈清除元素后比较 def fun(str_): result = list() for i in str_: .

2022-04-24 01:44:18 157

原创 快慢指针-1--LC26.删除有序数组中的重复项

class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ # 快慢指针,27的进阶,先做27 # 如果len(nums)=0,没有元素,return 0 # 如果len(nums)=1,也没有重复元素,return 1 # 因此sl.

2022-04-24 00:59:26 106

原创 二分查找法-3--LC.有效的完全平方数

class Solution(object): def isPerfectSquare(self, num): """ :type num: int :rtype: bool """ # 69的进阶,二分查找法 l, r = 1, num while l<=r: mid = l + ((r-l)>>1) if mid * .

2022-04-24 00:41:43 85

原创 二分查找法-2--LC69.x的平方根

class Solution(object): def mySqrt(self, x): """ :type x: int :rtype: int """ # 二分查找法 # x平方根的整数部分是满足 k^2<=x的k的最大值,可以使用二分查找法查找k l, r, num = 0, x, -1 while l <= r: mid = l.

2022-04-24 00:36:05 110

原创 二分查找-1--LC34.在排序数组中查找元素的第一个和最后一个位置

class Solution(object): def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ # 二分查找法 n = len(nums) if not n: return [-1, -1].

2022-04-24 00:22:18 72

原创 动态规划--LC518.零钱兑换II

class Solution(object): def change(self, amount, coins): """ :type amount: int :type coins: List[int] :rtype: int """ # 完全背包 # 每一种面额的硬币有无限个 # dp[j]:金额为j的组合数,最终目标是dp[amount] # 此时的金.

2022-04-21 23:04:11 104

原创 动态规划--LC474.一和零

class Solution(object): def findMaxForm(self, strs, m, n): """ :type strs: List[str] :type m: int :type n: int :rtype: int """ # 这个题是一个01背包问题,不一样的是,背包的容量是2维的,有m和n # 确定dp # dp[i][j.

2022-04-20 17:54:11 643

原创 动态规划--LC494.目标和

此类问题与传统的01背包问题稍有不同,尤其是状态转移方程。01背包问题会有max(),求一个最大;而此问题求的是能有多少种方法,面对第i个元素,存在取与不取的问题,最后加起来就是所有的方法。class Solution(object): def findTargetSumWays(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int.

2022-04-19 23:51:14 125

原创 回溯算法--LC.37解数独

class Solution(object): def solveSudoku(self, board): """ :type board: List[List[str]] :rtype: None Do not return anything, modify board in-place instead. """ # 不仅需要在行上遍历,还需要在列上遍历,二重遍历问题 def backtracking.

2022-04-18 11:31:46 55

原创 回溯算法--LC51.N皇后

class Solution(object): def solveNQueens(self, n): """ :type n: int :rtype: List[List[str]] """ # 回溯问题 # 皇后们的约束条件: # 1.不能同行 # 2.不能同列 # 3.不能同斜线 # 先把棋盘创建出来,默认都是".

2022-04-18 01:09:01 135

原创 回溯算法--LC47.全排列II

class Solution(object): def permuteUnique(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ # 相较于46,此时数组里面又重复的数字,此时要考虑去重 # 去重一定要先排序 path = list() result = list() .

2022-04-17 21:54:26 88

原创 回溯算法--LC46.全排列

class Solution(object): def findSubsequences(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ # 本题求自增子序列,所以不能改变原数组顺序 res = [] path = [] def backsum(nums,start): .

2022-04-17 16:51:06 73

原创 回溯算法--LC491.递增子序列

class Solution(object): def findSubsequences(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ # 本题求自增子序列,所以不能改变原数组顺序 res = [] path = [] def backsum(nums,start): .

2022-04-17 11:52:38 67

原创 回溯算法--LC.90子集II

class Solution(object): def subsetsWithDup(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ # 包含重复元素,是子集问题加上去重 # LC78与LC40的结合 result = list() # 这种去重问题,必须对数组先排序,让重复的可以挨着.

2022-04-16 17:53:42 208

原创 回溯法--LC.93复原IP地址

class Solution(object): def restoreIpAddresses(self, s): """ :type s: str :rtype: List[str] """ result = list() path = list() if len(s) > 12: return [] self.backtracking(s.

2022-04-16 11:16:40 70

原创 回溯算法--LC.40组合总和II

class Solution(object): def combinationSum2(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ # 回溯法 # 此题与39题的区别:39的数组内无重复,但是组合内数字可以重复;40是数组内.

2022-04-15 01:27:21 223

原创 回溯法--LC.17电话号码的字母组合

class Solution(object): def letterCombinations(self, digits): """ :type digits: str :rtype: List[str] """ # 回溯法 # 首先,dics确定数字与字母之间的映射关系 dics = {'2':'abc', '3':'def', '4':'ghi','5':'jkl', .

2022-04-14 22:02:36 161

原创 回溯算法--LC216.组合总和III

数字选取[1-9]不重复这个题类似于LC77.组合,组合的问题是非重复的,这个题也是非重复的,这个题只是多了个求和。class Solution(object): def combinationSum3(self, k, n): """ :type k: int :type n: int :rtype: List[List[int]] """ # 回溯法 result = list.

2022-04-14 18:15:54 258

原创 动态规划--LC1049.最后一块石头的重量II

class Solution(object): def lastStoneWeightII(self, stones): """ :type stones: List[int] :rtype: int """ # 1.dp # 说实话,对于这个题一开始还真不知道怎么做,看了解析后做的,动态规划还得练啊 # 本题与LC416类似,目的就是想让石头分成两组,两组差距越小越好,最好是相等,相等.

2022-04-12 23:36:45 134

原创 动态规划--LC416分割等和子集

class Solution(object): def canPartition(self, nums): """ :type nums: List[int] :rtype: bool """ # 1.dp 用01背包的思想去解决这个问题 # 针对这个题,我们要把数组nums分割成两个子集,使得两个子集的元素和相等 # 那么我对数组nums求和,然后/2,如果可以整除说明可能会分割成两个.

2022-04-12 22:50:14 160

原创 动态规划--LC96.不同的二叉搜索树

class Solution(object): def numTrees(self, n): """ :type n: int :rtype: int """ # 1.dp dp = [0 for _ in range(n+1)] dp[0] = 1 dp[1] = 1 for i in range(2, n+1): for j i.

2022-04-12 01:51:30 89

原创 动态规划--LC343.整数拆分

class Solution(object): def integerBreak(self, n): """ :type n: int :rtype: int """ # 1.dp # n为正整数,那么0不是正整数,1是正整数但是不能拆分,所以从2开始 dp = [0 for _ in range(n+1)] for i in range(2, n+1): .

2022-04-12 01:11:02 94

原创 动态规划--LC63不同路径II

这个题是力扣62不同路径的改进,在路径上多了障碍物需要思考。class Solution(object): def uniquePathsWithObstacles(self, obstacleGrid): """ :type obstacleGrid: List[List[int]] :rtype: int """ # 有障碍物,那么有障碍物的位置路径=0 # 1.dp m = le.

2022-04-11 23:42:59 74

原创 动态规划--LC746. 使用最小花费爬楼梯

这个题目本身就比较难理解,弄懂题目之后还是比较简单的一个题目:这个题是力扣70题爬楼梯的进阶,考虑了爬楼的的花费。我们可以从两个角度来解决这个题:一是开始的台阶不花费,最后一个台阶需要花费。二是开始的台阶需要花费,最后一个台阶不需要花费。我是从第二个角度来解决这个问题的。首先,你可以站在下表为0或下表为1的台阶开始爬楼梯,我们可以看作是先从地面到第0个台阶或者第一个台阶,第一步是需要花费的。以cost=[10,15,20]为例,我一开始从0台阶爬楼梯那么花费就是10,这里要注意,开始的台阶也花费,或者.

2022-04-11 19:16:13 226

原创 卷积神经网络动态图

看这个图,就明白了卷积神经网络是在做什么

2022-04-10 01:27:37 2870 1

原创 70-动态规划--LC62不同路径

class Solution(object): def uniquePaths(self, m, n): """ :type m: int :type n: int :rtype: int """ # 1.动态规划 dp = [[0 for j in range(n)] for i in range(m)] for i in range(m): d.

2022-04-08 20:44:09 133

原创 70-动态规划--LC70爬楼梯

class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int """ # 1.递归,用递归超时 if n == 1: return 1 if n == 2: return 2 return self.climbStairs(n-1.

2022-04-08 18:36:05 169

原创 70-动态规划--LC509斐波那契数

class Solution(object): def fib(self, n): """ :type n: int :rtype: int """ # 1.递归 if n == 0: return 0 if n == 1: return 1 return self.fib(n-1) + self.fib(n-2)cla.

2022-04-08 16:19:13 415

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除