![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
崔雨田
这个作者很懒,什么都没留下…
展开
-
队列, 使用数据模拟循环队列
AC code private int size; private int[] elements; private int front; /** * Initialize your data structure here. Set the size of the queue to be k. */ public T622(int k) { elements = new int[k]; } /** * Ins原创 2020-12-08 20:52:34 · 94 阅读 · 0 评论 -
秋招 笔试 微盟 10.27
思路:hash map 计算 数组位置的方法AC code /** * b 是 a 的 n 次 方 * 使用位运算 计算 a % b * * @param a int整型 * @param b int整型 * @return int整型 */ public int bitModulus(int a, int b) { return (b - 1) & a; } public原创 2020-10-27 20:09:40 · 235 阅读 · 4 评论 -
leetcode 110. 平衡二叉树
题目给定一个二叉树,判断它是否是高度平衡的二叉树。本题中,一棵高度平衡二叉树定义为 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1。示例 1:给定二叉树 [3,9,20,null,null,15,7] 3 / \ 9 20 / \ 15 7返回 true 。 一 /** * 给定一个二叉树,判断它是否是高度平衡的二叉树。 * <p> * 本题中,一棵高度平衡二叉树定义为: * <原创 2020-08-24 20:04:09 · 62 阅读 · 0 评论 -
leetcode 107. 二叉树的层次遍历 II
题目给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其自底向上的层次遍历为:[ [15,7], [9,20], [3]]AC codepublic class T107 { /** * 给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶子节点原创 2020-08-24 20:00:22 · 64 阅读 · 0 评论 -
leetcode 面试题 04.06. 后继者
题目设计一个算法,找出二叉搜索树中指定节点的“下一个”节点(也即中序后继)。如果指定节点没有对应的“下一个”节点,则返回null。示例 1:输入: root = [2,1,3], p = 1 2 / \1 3输出: 2示例 2:输入: root = [5,3,6,2,4,null,null,1], p = 6 5 / \ 3 6 / \ 2 4 / 1输出: null题目CODEclass Solution {原创 2020-08-16 19:40:29 · 131 阅读 · 0 评论 -
力扣 面试题 08.03. 魔术索引
面试题 08.03. 魔术索引魔术索引。 在数组A[0…n-1]中,有所谓的魔术索引,满足条件A[i] = i。给定一个有序整数数组,编写一种方法找出魔术索引,若有的话,在数组A中找出一个魔术索引,如果没有,则返回-1。若有多个魔术索引,返回索引值最小的一个。示例1:输入:nums = [0, 2, 3, 4, 5]输出:0说明: 0下标的元素为0示例2:输入:nums = [1, 1, 1]输出:1提示:nums长度在[1, 1000000]之间思路:直接模拟即可,,,,,,肯原创 2020-07-31 21:04:22 · 81 阅读 · 0 评论 -
力扣 104. 二叉树的最大深度
题目给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。说明: 叶子节点是指没有子节点的节点。示例: 3 / \9 20 / \ 15 7给定二叉树 [3,9,20,null,null,15,7],返回它的最大深度 3链接:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree思路使用递归, 每次传递当前节点, 以及当前节点的深度, 然后根据条件一次判断即原创 2020-07-28 14:40:24 · 198 阅读 · 0 评论 -
牛客网 14893 栈
链接:https://ac.nowcoder.com/acm/problem/14893来源:牛客网给你一个1->n的排列和一个栈,入栈顺序给定你要在不打乱入栈顺序的情况下,对数组进行从大到小排序当无法完全排序时,请输出字典序最大的出栈序列输入:52 1 5 3 4输出:5 4 3 1 2#include <iostream>#include <sta...原创 2020-04-11 16:29:57 · 371 阅读 · 0 评论 -
牛客网 15029 (栈)
链接:https://ac.nowcoder.com/acm/problem/15029来源:牛客网小鱼儿吐泡泡,嘟嘟嘟冒出来。小鱼儿会吐出两种泡泡:大泡泡"O",小泡泡"o"。两个相邻的小泡泡会融成一个大泡泡,两个相邻的大泡泡会爆掉。(是的你没看错,小气泡和大气泡不会产生任何变化的,原因我也不知道。)例如:ooOOoooO经过一段时间以后会变成oO。输入:ooOOoooO输出:...原创 2020-04-11 16:26:58 · 311 阅读 · 0 评论 -
牛客网 栈 21874
#include <iostream>#include <string>#include <stack> using namespace std;stack<char> s; /*括号匹配 */int main(){ string str; cin>>str; bool ans = true; for(int i...原创 2020-04-10 21:54:37 · 80 阅读 · 0 评论 -
c++ 栈实现括号匹配
#include <iostream>#include <stack>#include <string> using namespace std;/* 用栈来实现括号匹配 输入一个字符串: 1、未匹配的的 ( 用 ? 替代 2、未匹配的的 ) 用 $ 替代 */int main(){ string str; stack<in...原创 2020-04-09 17:52:25 · 501 阅读 · 0 评论 -
最大视野 (单调栈)
#include <iostream>#include <stack>#include <vector>using namespace std;int fieldsum(vector<int>& v){ int sum = 0; // 放入最大的值 v.push_back(INT_MAX); stack<int>...原创 2020-04-09 17:20:53 · 216 阅读 · 0 评论 -
算法之前缀和详解
前缀和前缀和就是求解一个数组的某个区间的数字之和, 下面直接简单举例数组 a[5]={0, 1, 2 ,3 ,4 }经过计算可以得到他的前缀和数组b[5] = {0, 1, 3 ,6, 10}简单观察可以发现前缀和数组是存在递推关系的即:b[ i ] = b[ i -1 ] + a[ i ]下面回到问题所在的地方:求解某个区间的前缀和, 输入区间的L, R, 那么就相当于是对b[ ...原创 2020-04-02 09:16:28 · 1206 阅读 · 0 评论 -
二分查找和快速幂
二分查找和快速幂二分主要考察的是思想、快速幂是递归。二分:#include <iostream>#include <algorithm>using namespace std; const int maxn = 10;int arr[maxn];int search(int* arr, int x, int y, int v){ /* 二分思想;...原创 2020-03-05 17:48:07 · 120 阅读 · 0 评论 -
DFS求八连通块Uva572
典型的搜索题,在搜索的时候需要注意的问题:1、是否访问越界2、是否访问过3、什么时候结束搜索(找到答案)4、是否能访问(满足题目的合法访问状态或者要求)5、标记访问过的节点#include <iostream>#include <string.h>#include <algorithm>using namespace std;const in...原创 2020-03-05 14:18:33 · 129 阅读 · 0 评论 -
排序vector
排序vector#include <iostream>#include <algorithm>#include <vector> using namespace std;struct student{ string name; int num; int grad; student(string name1,int num1,int grad1)...原创 2019-04-08 23:49:29 · 463 阅读 · 0 评论