自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(60)
  • 资源 (1)
  • 收藏
  • 关注

原创 提高运行速度的方法

① if (i > t++) return false;把自加写到循环里

2021-02-23 21:42:42 158 1

原创 2021-09-25

确定dp数组(dp table)以及下标的含义 确定递推公式 dp数组如何初始化 确定遍历顺序 举例推导dp数组斐波那契数列class Solution { public int fib(int n) { if(n==0||n==1) return n; int sum; int m=0,k=1; for(int i=0;i<n;i++) { ...

2021-09-25 21:06:59 72

原创 2021-09-07

平衡二叉树class Solution { public boolean isBalanced(TreeNode root) { if(root==null) return true; if(Math.abs(cal(root.left)-cal(root.right))>1) { return false; } return isBalanced(root.left)&&

2021-09-07 15:39:32 70

原创 2021-09-06

二叉树的前序遍历class Solution { List<Integer> x=new LinkedList<>(); public List<Integer> preorderTraversal(TreeNode root) { if(root==null) return x; x.add(root.val); preorderTraversal(root.left); preorder

2021-09-06 14:11:46 81

原创 2021-09-05

求多叉树最大深度class Solution { public int maxDepth(Node root) { if(root==null) return 0; int y=0; for(Node x : root.children) { y=Math.max(maxDepth(x),y); } return y+1; }}二叉树的坡度class Solutio

2021-09-05 17:42:43 66

原创 2021-09-04

中序先序构造二叉树class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { if (preorder == null || inorder == null || preorder.length != inorder.length || inorder.length < 1) return null; return construct(preor

2021-09-04 17:05:08 58

原创 2021.9.3刷题

求根节点到叶节点数字之和class Solution { static int sum; public int sumNumbers(TreeNode root) { sum=0; Sum(0,root); return sum; } public static void Sum(int val,TreeNode root) { if(root==null) return; int k=

2021-09-03 21:05:09 68

原创 2121.9.2刷题

二叉树的最小深度class Solution { public int minDepth(TreeNode root) { int ans=1000000; if(root==null) return 0; if(root.left==null) { return minDepth(root.right)+1; } if(root.right==null) {.

2021-09-02 21:13:23 62

原创 八大排序算法

https://www.cnblogs.com/morethink/p/8419151.html

2021-09-02 11:53:28 54

原创 图的操作最短路径最小生成树问题

import java.util.*;import java.util.Queue;import java.util.Stack;//有权无向图public class Graph { public Vertex[] vertexList; //存放顶点 public int[][] mGraph; //用矩阵表示边 public int size; //当前顶点数 public int[] distance; //

2021-09-01 17:51:17 67

原创 树的遍历插入最小平衡子树

import javax.swing.tree.TreeNode;import java.util.*;import java.util.Queue;import java.util.Stack;public class BinaryTreeNode { public Tree construct(int[] preorder, int[] inorder){ // 输入的合法性判断 if (preorder == null || inorder == nu

2021-09-01 15:00:41 93

原创 青蛙跳台阶和斐波那契数列

青蛙跳台阶class Solution {public: int numWays(int n) { int a = 1, b = 1, sum; for(int i = 0; i < n; i++){ sum = (a + b) % 1000000007; a = b; b = sum; } return a; }};斐波那契数列class

2021-08-16 11:48:03 54

原创 输入某二叉树的前序遍历和中序遍历的结果,请构建该二叉树并返回其根节点。

/** * 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: vector<int> Preorder ;

2021-08-16 11:39:39 516

原创 反转数组四种方式

https://blog.csdn.net/pro1515151515/article/details/90383807

2021-08-16 10:19:19 79

原创 2021-07-24

class Solution {public: vector<int> intersect(vector<int>& nums1, vector<int>& nums2) { vector<int> x; int j; sort(nums1.begin(),nums1.end()); //排序预处理 sort(nums2.begin(),nums2.end());

2021-07-24 19:13:08 52

原创 层次遍历存储

class Solution {public: vector<int> levelOrder(TreeNode* root) { if(!root) return {}; //如果节点为空放回空容器 queue<TreeNode*> data; //定义一个队列 TreeNode* p=root; //新增一个节点将头节点赋值给他 TreeNode* s; vector<in

2021-07-23 17:01:49 58

原创 2021-07-23

class Solution {public: bool validateStackSequences(vector<int>& pushed, vector<int>& popped) { stack<int> data; if(pushed.size() == 0 && popped.size() == 0){ return true; }

2021-07-23 16:13:34 42

原创 转圈循环数组

class Solution {public: vector<int> spiralOrder(vector<vector<int>>& matrix) { vector <int> x; if(matrix.empty()) return x; int top=0; int rh=matrix[0].size()-1; int rl=0; int

2021-07-23 15:36:09 81

原创 2021-07-23

class Solution {public: bool isSymmetric(TreeNode* root) { if(!root) return true; return Helper(root->left, root->right); } bool Helper(TreeNode* left, TreeNode* right) { if(!left && !right) {

2021-07-23 14:55:08 42

原创 镜像树xxx

TreeNode* mirrorTree(TreeNode* root) { if(!root) return root; TreeNode* tmp = root->left; root->left = root->right; root->right = tmp; mirrorTree(root->left); mirrorTree(root->right); .

2021-07-23 14:32:14 44

原创 2021-07-23

class Solution {public: int findRepeatNumber(vector<int>& nums) { unordered_set<int> c1; //定义哈希表存储数组 for(int num : nums) { if(c1.find(num)!=c1.end()) //利用迭代器判断是否存在这个元素 { return num;

2021-07-23 14:15:29 44

原创 2021-05-08

Android Studio中使用webview加载URL出现net::ERR_CLEARTEXT_NOT_PERMITTED cleartext为明文 permitted表示允许 即加载http时明文不被允许从Android 9.0(API级别28)开始,默认情况下禁用明文支持。因此http的url均无法在webview中加载因此需要添加允许权限<applicationandroid:allowBackup=“true”android:icon="@mipmap/ic_launcher"

2021-05-08 11:20:12 111 3

原创 不同的二叉搜索树

class Solution {public: int numTrees(int n) { vector<int> G(n + 1, 0); G[0] = 1; G[1] = 1; for (int i = 2; i <= n; ++i) { for (int j = 1; j <= i; ++j) { G[i] += G[j - 1] * G[i -

2021-04-24 20:46:00 29

原创 树的最小深度

class Solution {public: int minDepth(TreeNode* root) { if(root==NULL) { return 0; } int left = minDepth(root->left); int right = minDepth(root->right); if(left == 0) return right + 1;

2021-04-24 20:31:20 33

原创 前序遍历

class Solution {public: void visit(TreeNode* t,vector<int> &a) { if(t==NULL) { return; } a.push_back(t->val); visit(t->left,a); visit(t->right,a); } vector<in

2021-04-24 20:22:45 43

原创 平衡二叉树

class Solution{public: int dep(TreeNode* t) { if(t==NULL) { return 0; } else{ int l=dep(t->left); int r=dep(t->right); if(l>r) return l+1; else return r+1;;

2021-04-24 20:15:36 27

原创 2021-04-24

class Solution {public: int dep(TreeNode* t) { if(t==NULL) { return 0; } else { int l=maxDepth(t->left); int r=maxDepth(t->right); if(l>r) return l+1

2021-04-24 19:31:25 33

原创 对称二叉树

class Solution {public: void check(TreeNode* t,TreeNode* s,int &i) { if(s!=NULL&&t!=NULL){ //如果左右子树都不为空 if(s->val!=t->val||s->val!=t->val) //判断左右子树的值是否不相等 { i=1; //不相等使i=1 r

2021-04-24 13:57:41 41

原创 c++层序遍历倒序输出

c++层序遍历倒序输出class Solution {public: vector<vector<int>> levelOrderBottom(TreeNode* root) { vector<vector<int>> res; int j=0; queue<TreeNode*> k; while(root==NULL) { retu

2021-04-24 11:50:01 258

原创 二叉树层次遍历

class Solution {public: vector<vector<int>> levelOrder(TreeNode* root) { queue<TreeNode*> r; //定义一个队列储存树节点 vector<vector<int>> res; //定义一个容器储存多个储存整数的容器 if(root==NULL) //如果根节点为空返回res容器 { ret

2021-04-23 19:36:17 54

原创 递归实现判断两棵树是否相同

class Solution {public: void check(TreeNode *p,TreeNode *q,int &i) { if(p!=NULL&&q!=NULL) { if(p->val!=q->val) { i=0; return; } check(p->le

2021-04-23 18:07:51 382

原创 中序遍历递归实现栈实现

class Solution {public:void inorder(TreeNode* root, vector& a) {if (!root) {return;}inorder(root->left, a);a.push_back(root->val);inorder(root->right, a);};vector<int> inorderTraversal(TreeNode* root) { vector<int> a;

2021-04-23 17:56:15 127

原创 涂方格

class Solution {public int paintingPlan(int n, int k) {int res = 0;//边界问题if(k == 0)return 1;if(k == n * n)return 1; //第一层循环表示涂 i 行 第二层循环表示涂 j 列 for(int i = 0;i <= n;i++){ for(int j = 0;j <= n;j++) //当你涂了 i 行 j 列 则有 i

2021-03-02 16:20:13 96

原创 奇数位于偶数前面

class Solution { public int[] exchange(int[] nums) { int left = 0; int right = nums.length - 1; while (left < right) { while (left < right && nums[left] % 2 != 0) { left++; }

2021-03-01 19:11:08 40

转载 石子游戏

class Solution {public: int stoneGameVI(vector<int>& aliceValues, vector<int>& bobValues) { vector<pair<int, int>> mp; //记录价值和以及下标 int n = aliceValues.size(); for(int i = 0; i < n; i++){ int dis = aliceValue

2021-02-27 20:47:56 62

转载 岛屿的周长

将这个“相邻关系”对应到 DFS 遍历中,就是:每当在 DFS 遍历中,从一个岛屿方格走向一个非岛屿方格,就将周长加 1。class Solution { public int islandPerimeter(int[][] grid) { for (int r = 0; r < grid.length; r++) { for (int c = 0; c < grid[0].length; c++) { if (grid[r][c] ==

2021-02-26 22:41:17 51

原创 设计哈希映射

class MyHashMap {public class Entry {public int key;public int value;public Entry(int k, int v) {key = k;value = v;}}private Entry[] data;private static final int SIZE = 13_333; // 10000 / 0.75private static final int DELETED = -1;public M

2021-02-26 22:03:21 36

原创 Java字符串压缩

class Solution { public String compressString(String S) { char[] s=S.toCharArray(); int n=S.length(); int k=1; StringBuilder str = new StringBuilder(n); for(int i=0;i<n;++i) { k=1; while(i<n-1&&s[i+

2021-02-25 20:17:00 66

转载 找树左下角的值

BFS用队列存储节点,先进先出从右往左遍历,也就是在往队列中添加数据时,先添加右子节点,再添加左子节点当队列为空时,循环结束,最后一个遍历到的节点就是最左边的节点返回最左边节点的值/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * Tre

2021-02-25 11:21:15 37

原创 转置矩阵

Javaclass Solution { public int[][] transpose(int[][] matrix) { int m=matrix.length; int n=matrix[0].length; int[][] k=new int[n][m]; for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { k[j][i]=matrix[i]

2021-02-25 09:37:32 43

Appinventor高尔夫源码下载Mini_golf.aia

Appinventor源码,高尔夫球,背景音乐,AI对战,计时系统,记最高分

2019-07-14

空空如也

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

TA关注的人

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