![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
摸摸头_
这个作者很懒,什么都没留下…
展开
-
单调数列:判断数列单调
题目题解class Solution {public: bool isMonotonic(vector<int>& A) { bool flag = true; int index = 1; int n = A.size(); while(index < n && A[index] == A[index-1])++index; if(index == n) return原创 2021-04-06 21:40:45 · 285 阅读 · 0 评论 -
计算三维体的表面积
题目题解class Solution {public: int surfaceArea(vector<vector<int>>& grid) { int m = grid.size(); if(!m) return 0; int n = grid[0].size(); int sum = 0; for(int i=0;i<m;++i){ for(int原创 2021-04-06 16:01:58 · 343 阅读 · 0 评论 -
字符串的双映射:查找和替换模式
题目:题解:class Solution {public: vector<string> findAndReplacePattern(vector<string>& words, string pattern) { vector<string> ans; int len = pattern.length(); for(string &word : words){ if(原创 2021-04-06 15:00:25 · 192 阅读 · 0 评论 -
重建二叉树:根据前序和后序遍历重构二叉树
题目题解/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode *build(vector&l原创 2021-04-06 14:17:32 · 341 阅读 · 0 评论 -
c++序列化二叉树
题目描述题解:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Codec {public: // Encodes a tree to a原创 2021-04-02 20:42:25 · 200 阅读 · 0 评论 -
跳跃游戏 II
题目:题解:class Solution {public: int jump(vector<int>& nums) { int position = nums.size() - 1; int steps = 0; while(position > 0){ for(int i = 0;i < position;++i){ if(i + nums[i] >原创 2021-03-26 22:03:00 · 56 阅读 · 0 评论 -
二叉树的最小深度(广度优先搜索)
题目:https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/来源:LeetCode代码:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), righ原创 2021-03-22 18:37:28 · 133 阅读 · 0 评论 -
接雨水(leetcode习题)
题目链接https://leetcode-cn.com/problems/trapping-rain-water/方法一:动态规划class Solution {public: int trap(vector<int>& height) { if(!height.size()) return 0; vector<int> left_max_arr(height.size(),0); vector<int&原创 2021-03-20 18:18:23 · 123 阅读 · 0 评论 -
面试题 17.23. 最大黑方阵
面试题 17.23. 最大黑方阵c++题解面试题 17.23. 最大黑方阵示例 1:题解:题解思路面试题 17.23. 最大黑方阵给定一个方阵,其中每个单元(像素)非黑即白。设计一个算法,找出 4 条边皆为黑色像素的最大子方阵。返回一个数组 [r, c, size] ,其中 r, c 分别代表子方阵左上角的行号和列号,size 是子方阵的边长。若有多个满足条件的子方阵,返回 r 最小的,若 r 相同,返回 c 最小的子方阵。若无满足条件的子方阵,返回空数组。示例 1:输入:[[1,0,1],原创 2021-03-17 11:37:10 · 160 阅读 · 0 评论 -
POJ练习题之:败方树
问题描述给定一个整数数组,要求对数组中的元素构建败方树(数组相邻元素两两比较,从第一个元素开始)。之后修改数组中的元素,要求输出初始构建以及修改后得到的败方树的所有内部结点代表的整数(从左到右从上到下输出)输入第一行为数组的元素个数n和修改的次数m。第二行为n个整数,即数组的元素。接下来m行代表m次修改操作,每次操作修改数组中的一个元素,每一行包括两个整数,第一个为被修改元素在数组中的标号,第二个为修改之后的元素值。输出输出m+1行。第一行为初始构建的败方树的所有内部结点代表的整数(按照树的原创 2020-06-30 23:58:20 · 869 阅读 · 4 评论