自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 P1719 最大加权矩形

为了更好的备战 NOIP2013,电脑组的几个女孩子 LYQ,ZSC,ZHQ 认为,我们不光需要机房,我们还需要运动,于是就决定找校长申请一块电脑组的课余运动场地,听说她们都是电脑组的高手,校长没有马上答应他们,而是先给她们出了一道数学题,并且告诉她们:你们能获得的运动场地的面积就是你们能找到的这个最大的数字。具体思路是:枚举top行和bottom行,求这几行的每一列的列和,得到一个一维数组,求这个数组的最大子段和。这个题可以看做是“最大字段和”在高维的情况。

2022-11-24 19:48:30 117 1

原创 45. 跳跃游戏 II

(1)当前位置i

2022-11-20 15:16:44 509

原创 851. 喧闹和富有 中等

richer 中所给出的数据 逻辑自洽(也就是说,在 person x 比 person y 更有钱的同时,不会出现 person y 比 person x 更有钱的情况 )。现在,返回一个整数数组 answer 作为答案,其中 answer[x] = y 的前提是,在所有拥有的钱肯定不少于 person x 的人中,person y 是最安静的人(也就是安静值 quiet[y] 最小的人)。题目需要找比当前节点富有的人。拓扑排序的图结构是富人指向穷人,知道根节点的值,拓扑序列的其他点的值就可以确定了。

2022-11-10 16:54:49 127

原创 695. 岛屿的最大面积 中等

岛屿 是由一些相邻的 1 (代表土地) 构成的组合,这里的「相邻」要求两个 1 必须在 水平或者竖直的四个方向上 相邻。你可以假设 grid 的四个边缘都被 0(代表水)包围着。使用并查集,为了避免重复,将当前网格和左边、右边的1合并。但是合并过程中要记录所有集合的面积。遍历每个网格,对于每一个非1的网格,分别向四个方向遍历。遍历过的网格设为0,防止重复计算。计算并返回 grid 中最大的岛屿面积。给你一个大小为 m x n 的二进制矩阵 grid。岛屿的面积是岛上值为 1 的单元格的数目。

2022-11-10 13:43:57 158

原创 959. 由斜杠划分区域 中等

在由 1 x 1 方格组成的 n x n 网格 grid 中,每个 1 x 1 方块由 ‘/’、‘’ 或空格构成。这些字符会将方块划分为一些共边的区域。给定网格 grid 表示为一个字符串数组,返回 区域的数量。请注意,反斜杠字符是转义的,因此 ‘’ 用 ‘\’ 表示。

2022-11-09 21:35:22 49

原创 128. 最长连续序列【中等】

给定一个未排序的整数数组 nums ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。请你设计并实现时间复杂度为 O(n) 的算法解决此问题。

2022-11-08 18:21:31 58

原创 797. 所有可能的路径(中等)

2022-11-07 23:19:32 35

原创 1557. 可以到达所有点的最少点数目(中等)

莫名其妙

2022-11-07 17:01:10 49

原创 816. 模糊坐标

莫名其妙

2022-11-07 16:14:44 38

原创 蓝桥杯-回文日期

莫名其妙

2022-11-06 22:53:02 626

原创 vs2022配置libtorch+opencv

添加系统变量D:\Torch\libtorch\libD:\Torch\libtorch\bin右键单击解决方案—配置管理器,设置为release添加工程的头文件目录:工程—属性—配置属性—c/c+±–常规—附加包含目录:加上头文件存放目录。D:\Torch\libtorch\includeD:\Torch\libtorch\include\torch\csrc\api\include添加文件引用的lib静态库路径:工程—属性—配置属性—链接器—常规—附加库目录:加上li.

2022-03-23 15:10:27 5270

原创 2038. 如果相邻两个颜色均相同则删除当前颜色(中等)

如果相邻两个颜色均相同则删除当前颜色总共有 n 个颜色片段排成一列,每个颜色片段要么是 ‘A’ 要么是 ‘B’ 。给你一个长度为 n 的字符串 colors ,其中 colors[i] 表示第 i 个颜色片段的颜色。Alice 和 Bob 在玩一个游戏,他们 轮流 从这个字符串中删除颜色。Alice 先手 。如果一个颜色片段为 ‘A’ 且 相邻两个颜色 都是颜色 ‘A’ ,那么 Alice 可以删除该颜色片段。Alice 不可以 删除任何颜色 ‘B’ 片段。如果一个颜色片段为 ‘B’ 且 相邻两个.

2022-03-22 12:55:07 3523

原创 2044. 统计按位或能得到最大值的子集数目(medium)

统计按位或能得到最大值的子集数目给你一个整数数组 nums ,请你找出 nums 子集 按位或 可能得到的 最大值 ,并返回按位或能得到最大值的 不同非空子集的数目 。如果数组 a 可以由数组 b 删除一些元素(或不删除)得到,则认为数组 a 是数组 b 的一个 子集 。如果选中的元素下标位置不一样,则认为两个子集 不同 。对数组 a 执行 按位或 ,结果等于 a[0] OR a[1] OR … OR a[a.length - 1](下标从 0 开始)。1.回溯每次回溯时,如果pos==n,判.

2022-03-15 11:25:14 177

原创 1002. 查找共用字符(easy)

查找共用字符给你一个字符串数组 words ,请你找出所有在 words 的每个字符串中都出现的共用字符( 包括重复字符),并以数组形式返回。你可以按 任意顺序 返回答案。1.使用数组v统计统计每个字母在各个字符串中出现的最少次数,将其加入到结果数组中。注意:(1)emplace_back可以直接传入构造函数的参数,减少一次构造的调用。(2)使用字符构造string实例:string(1,c)。v.push_back(string(1,c))=v.emplace_back(1,c).cl.

2022-03-14 19:52:24 279

原创 49. 字母异位词分组(medium)

字母异位词分组给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。1.本题要求相同字母的字符串放在一起,考虑用哈希表,键是字符串,值是字符串数组。对字符串排序,如果两个串由相同的字母的组成,排序后的字符串是相同的,可以以此作为map的键class Solution {public: vector<vector<string>> groupAnag.

2022-03-14 14:37:15 134

原创 2049. 统计最高分的节点数目(中等)

统计最高分的节点数目给你一棵根节点为 0 的 二叉树 ,它总共有 n 个节点,节点编号为 0 到 n - 1 。同时给你一个下标从 0 开始的整数数组 parents 表示这棵树,其中 parents[i] 是节点 i 的父节点。由于节点 0 是根,所以 parents[0] == -1 。一个子树的 大小 为这个子树内节点的数目。每个节点都有一个与之关联的 分数 。求出某个节点分数的方法是,将这个节点和与它相连的边全部 删除 ,剩余部分是若干个 非空 子树,这个节点的 分数 为所有这些子树 大小的乘.

2022-03-11 13:14:09 967

原创 904. 水果成篮

水果成篮你正在探访一家农场,农场从左到右种植了一排果树。这些树用一个整数数组 fruits 表示,其中 fruits[i] 是第 i 棵树上的水果 种类 。你想要尽可能多地收集水果。然而,农场的主人设定了一些严格的规矩,你必须按照要求采摘水果:你只有 两个 篮子,并且每个篮子只能装 单一类型 的水果。每个篮子能够装的水果总量没有限制。你可以选择任意一棵树开始采摘,你必须从 每棵 树(包括开始采摘的树)上 恰好摘一个水果 。采摘的水果应当符合篮子中的水果类型。每采摘一次,你将会向右移动到下一棵树,并.

2022-03-10 21:50:46 118

原创 35. 搜索插入位置

搜索插入位置给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。请必须使用时间复杂度为 O(log n) 的算法。二分法用于搜索插入位置:如果nums[mid]<target时,left=mid+1,保证left左边都是比target小的元素。如果nums[mid]>=target,right=mid-1,即right右边的数大于等于target,插入时选择的位置就是left。class Solution {..

2022-03-09 22:40:39 42

原创 1109. 航班预订统计

航班预订统计这里有 n 个航班,它们分别从 1 到 n 进行编号。有一份航班预订表 bookings ,表中第 i 条预订记录 bookings[i] = [firsti, lasti, seatsi] 意味着在从 firsti 到 lasti (包含 firsti 和 lasti )的 每个航班 上预订了 seatsi 个座位。请你返回一个长度为 n 的数组 answer,里面的元素是每个航班预定的座位总数。本题用到的解题思想是差分数组。差分数组是前缀和的逆运算。presum[i]=pres.

2022-03-09 19:34:59 99

原创 1685. 有序数组中差绝对值之和

有序数组中差绝对值之和给你一个 非递减 有序整数数组 nums 。请你建立并返回一个整数数组 result,它跟 nums 长度相同,且result[i] 等于 nums[i] 与数组中所有其他元素差的绝对值之和。换句话说, result[i] 等于 sum(|nums[i]-nums[j]|) ,其中 0 <= j < nums.length 且 j != i (下标从 0 开始)。class Solution {public: vector<int> get.

2022-03-08 20:08:02 45

原创 1871. 跳跃游戏 VII

跳跃游戏 VII给你一个下标从 0 开始的二进制字符串 s 和两个整数 minJump 和 maxJump 。一开始,你在下标 0 处,且该位置的值一定为 ‘0’ 。当同时满足如下条件时,你可以从下标 i 移动到下标 j 处:i + minJump <= j <= min(i + maxJump, s.length - 1) 且s[j] == '0'.如果你可以到达 s 的下标 s.length - 1 处,请你返回 true ,否则返回 false 。前缀和+动态规划某一处是.

2022-03-08 18:34:10 4183

原创 2055. 蜡烛之间的盘子

蜡烛之间的盘子给你一个长桌子,桌子上盘子和蜡烛排成一列。给你一个下标从 0 开始的字符串 s ,它只包含字符 ‘*’ 和 ‘|’ ,其中 '’ 表示一个 盘子 ,’|’ 表示一支 蜡烛 。同时给你一个下标从 0 开始的二维整数数组 queries ,其中 queries[i] = [lefti, righti] 表示 子字符串 s[lefti…righti] (包含左右端点的字符)。对于每个查询,你需要找到 子字符串中 在 两支蜡烛之间 的盘子的 数目 。如果一个盘子在 子字符串中 左边和右边 都 至.

2022-03-08 14:21:27 54

原创 209. 长度最小的子数组

长度最小的子数组给定一个含有 n 个正整数的数组和一个正整数 target 。找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl+1, …, numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回 0 。1.滑动窗口使用滑动窗口解法时,如果当前窗口的总和>target,left向前移动,窗口的总和一定在变小,已知right在前一个位置时,滑动窗口总和不满足要求,left移动之后必然不满足要求,所以right指针不需要移动。.

2022-03-06 14:43:38 35

原创 53.最大子数组和(简单)

最大子数组和给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。子数组 是数组中的一个连续部分。1.动态规划f[i]表示以nums[0,i]上最大子数组的和。f[i]=max(f[i-1]+nums[i],nums[i]),同时维护最大子数组和。class Solution {public: int maxSubArray(vector<int>& nums) { int maxsum=nums.

2022-03-04 23:02:21 343

原创 2104. Sum of Subarray Ranges

Sum of Subarray RangesYou are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray.Return the sum of all subarray ranges of nums.A subarray is a contiguous non-empty seq.

2022-03-04 19:42:33 167

原创 2016. Maximum Difference Between Increasing Elements(Easy)

Maximum Difference Between Increasing ElementsGiven a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and nums[i] < nums[j].Return the maximu.

2022-02-26 17:36:05 56

原创 692. Top K Frequent Words(medium)

Top K Frequent WordsGiven a non-empty list of words, return the k most frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first..

2021-05-20 20:45:02 112

原创 95. Unique Binary Search Trees II(medium)

Unique Binary Search Trees IIGiven an integer n, return all the structurally unique BST’s (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order.递归 vector<TreeNode*> dfs(int start,int end.

2021-05-17 19:12:35 62

原创 二叉树的中序遍历

Binary Tree Inorder Traversal(easy)Given the root of a binary tree, return the inorder traversal of its nodes’ values./** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * T.

2021-05-17 18:28:03 81

原创 96. Unique Binary Search Trees(medium)

Unique Binary Search TreesGiven an integer n, return the number of structurally unique BST’s (binary search trees) which has exactly n nodes of unique values from 1 to n.1.官方题解思路:动态规划二分搜索树的中序遍历序列是递增的序列,以每个子节点为根的二叉树又是一棵二分搜索树对于长度为n的序列,其二叉搜索树根的选择有n种,分别是.

2021-05-17 12:15:23 64

原创 笔记

tie(x_depth,x_parent,x_found)=tuple{depth,parent,true}可实现批量赋值,tie绑定的是变量,tuple是值。如果queue的元素是pair类型,赋值的时候可以 (pair(first,second)),或者(first,second)。取值时可以 auto&&[first,second]=q.pop()vector<vector< int >>res, res.push_back(vector< int.

2021-05-17 09:15:07 63

原创 993. Cousins in Binary Tree(medium)

Cousins in Binary TreeIn a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.Two nodes of a binary tree are cousins if they have the same depth, but have different parents.We are given the root of a binary tre.

2021-05-17 09:14:37 43

原创 102. Binary Tree Level Order Traversal(medium)

Binary Tree Level Order TraversalGiven the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level).Example 1:Input: root = [3,9,20,null,null,15,7]Output: [[3],[9,20],[15,7]]1.层序遍历不使用.

2021-05-17 00:03:32 32

原创 421. Maximum XOR of Two Numbers in an Array(medium)

Maximum XOR of Two Numbers in an ArrayGiven an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 ≤ i ≤ j < n.Follow up: Could you do this in O(n) runtime?Example 1:Input: nums = [3,10,5,25,2,8]Output: 28Explanation: Th.

2021-05-16 22:36:40 69

原创 1269. Number of Ways to Stay in the Same Place After Some Steps(medium)

Number of Ways to Stay in the Same Place After Some StepsYou have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array or stay in the same place (The pointer should not .

2021-05-13 18:57:16 109 1

原创 39. Combination Sum(medium)

Combination SumGiven an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.The same number may be.

2021-05-13 18:54:27 69

原创 1310. XOR Queries of a Subarray(medium)

XOR Queries of a SubarrayGiven the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor … xor arr[Ri] ). Return an array containin.

2021-05-13 09:41:35 57

原创 50. Pow(x, n)(medium)

Pow(x, n)Implement pow(x, n), which calculates x raised to the power n (i.e., xn).1.思路来自于之前一道题,求xn,如果一个一个累加,会超时,题解思路是,对于x,第一次加x,第二次加x+x,然后加(x+x)+(x+x),计数器count<2n时,会继续累加,否则递归(x,n-count)double mypow(double x,long long int n){ if(n==0){ .

2021-05-12 12:06:31 51

原创 1734. Decode XORed Permutation(medium)

Decode XORed PermutationThere is an integer array perm that is a permutation of the first n positive integers, where n is always odd.It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For e.

2021-05-11 20:57:40 58

原创 51. N-Queens(hard)

N-QueensThe n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each solution contains a distinct board configurati.

2021-05-10 18:36:04 44

空空如也

空空如也

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

TA关注的人

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