ICode9

精准搜索请尝试: 精确搜索
  • leetcode 155. Min Stack最小栈(中等)2022-08-08 13:02:29

    一、题目大意 标签: 栈和队列 https://leetcode.cn/problems/min-stack 设计一个支持 push ,pop ,top 操作,并能在常数时间内检索到最小元素的栈。 实现 MinStack 类: MinStack() // 初始化堆栈对象。 void push(int val) // 将元素val推入堆栈。 void pop() // 删除堆栈顶部的元素。

  • LeetCode-7. 整数反转2022-02-06 14:32:11

    题目来源 7. 整数反转 题目详情 给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果。 如果反转后整数超过 32 位的有符号整数的范围 [−231,  231 − 1] ,就返回 0。 假设环境不允许存储 64 位整数(有符号或无符号)。 示例 1: 输入: x = 123 输出: 321 示例 2: 输入: x

  • 剑指 Offer 30. 包含 min 函数的栈 C++ 时间91%2021-12-26 10:31:40

    用一个记录当前最小值的栈mins作为辅助,如果新入栈的数小于等于(因为可能有重复数值,所以取等号)mins.top或者mins是空的,则两个栈一起入栈。 随后出栈时如果出的是当前最小值,则两个栈一起出栈。 class MinStack { public: stack<int> s, mins; public: /** initialize your

  • 20202323 实验九《数据结构与面向对象程序设计》实验报告2021-12-23 23:06:28

     # 20202323  2021-2022-1 《数据结构与面向对象程序设计》实验九报告课程:《程序设计与数据结构》班级: 2023姓名: 蒙思洋学号:20202323实验教师:王志强实验日期:2021年12月20日必修/选修: 必修## 1.实验内容 (1) 初始化:根据屏幕提示(例如:输入1为无向图,输入2为有向图)初始化无向图和有

  • 【题解】AcWing 102.Best Cow Fences2021-11-27 23:59:28

    AcWing 102.最佳牛围栏 题目描述 农夫约翰的农场由 N N N 块田地组成,每块地里都有一定数量的牛,其数量不会少于 1 1

  • c++在类的声明中初始化私有成员变量2021-11-14 14:33:13

    c++在类的声明中初始化私有成员变量 之前的学习都没有做博客记录一下,心血来潮想试一下,记录一下自己的学习历程,方便自己复习,大家见笑了。这个做法是突然想到,查了一下确实允许这样的做法,自己随便写的头文件 time.h class Time { private: int hours = 3; //c++ 11 允许这样

  • POJ - 2018 Best Cow Fences(二分)2021-10-22 17:32:47

    POJ - 2018 Best Cow Fences #include<iostream> #include<cstdio> using namespace std; const int N = 100010; const double eps = 1e-5; int n,m; int w[N]; double sum[N]; bool check(double avg) { for(int i=1;i<=n;i++) sum[i]=sum[i

  • LeetCode lc111.二叉树的最小深度2021-09-27 22:04:17

    1. 题目地址:https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/submissions/ 2. 题目解析:【1】使用广度优先搜索BFS,对于每一层的节点,如果第一次发现某节点左、右子结点均为空,则此节点为二叉树的最小深度. var minDepth = function(root) { if (!root) { retu

  • 秒转时分秒2021-09-23 21:02:54

        代码: public static void main(String[] args) { //秒 转 时分秒 long srcSecs = 2370; long hours = srcSecs / 3600; long mins = (srcSecs % 3600) / 60; long secs = srcSecs % 60; //转 时分秒 Sys

  • 8-1 最大连续和2021-08-07 23:34:00

    #include <bits/stdc++.h> using namespace std; const int maxn = 10010; int a[maxn], s[maxn]; int main() { int n; int mins = 999999, ans = -999999; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; s[i] = s[i - 1] +

  • GO网络编程目录2021-06-13 20:03:33

    Acknowledgments (02:18 mins)Introduction (05:45 mins)Part I: Network Architecture (01:09 mins) Chapter 1: An Overview of Networked Systems (25:18 mins) Chapter 2: Resource Location and Traffic Routing (47:09 mins)Part II: Socket-level Programming (01:09 m

  • 回文划分(dp的应用)2021-05-30 12:30:08

    自己没写出来,看了别人的才会 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char s[1001]; int dp[1001];//dp数组 const int big=999999999; int if_hui (int l,int r) { while(l<r){

  • 蓝桥杯真题-连号区间数2021-02-13 18:58:53

    题目描述 小明这些天一直在思考这样一个奇怪而有趣的问题: 在1~N的某个全排列中有多少个连号区间呢?这里所说的连号区间的定义是: 如果区间[L, R] 里的所有元素(即此排列的第L个到第R个元素)递增排序后能得到一个长度为R-L+1的“连续”数列,则称这个区间连号区间。 当N很小的时候,小

  • 数据挖掘-数据分类 python实现2021-02-13 17:01:13

    数据挖掘-数据分类 python实现 利用KNN实现性别判定 # -*-coding:utf-8-*- """ Author: Thinkgamer Desc: 代码4-5 利用KNN算法实现性别预测 """ import numpy as np class KNN: def __init__(self, k): # k为最近邻个数 self.K = k

  • 剑指offer:包含min函数的栈2020-10-13 21:00:46

    题目描述 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1))。 、 class Solution { public: stack<int> s; stack<int> minS; void push(int value) { if(s.empty()) { minS.push(value);

  • 设计一个有getMin功能的栈2020-09-08 11:31:48

    1 #include <bits/stdc++.h> 2 using namespace std; 3 4 class minStack{ 5 private: 6 stack<int> s; 7 stack<int> mins; 8 public: 9 void push(int x){ 10 s.push(x); 11 if(mins.empty()==true || mins.top()&

  • 如何实现可以获取最小值的栈?2020-06-07 11:58:27

    小史是一个应届生,虽然学的是电子专业,但是自己业余时间看了很多互联网与编程方面的书,一心想进BAT。  今天他又去BAT中的一家面试了。 简单的自我介绍后,面试官给了小史一个问题。 【面试现场】 如何实现可以获取最小值的栈 基础数据结构灵活运用 题目:我现在需要实现一个栈,这个栈除

  • webpack构建速度优化2020-05-16 10:06:41

    webpack打包速度优化 前言 Webpack打包优化并没有什么固定的模式,一般我们常见的就是缓存、多进程、抽离、拆分。 一、分析打包速度 优化webpack构建速度的第一步就是知道时间花费在哪里,才可以集中的进行针对性的优化。 这边我们用到speed-measure-webpack-plugin插件。 // 分析打

  • 如何实现可以获取最小值的栈?2020-04-04 12:57:00

        我在某校研究生考试初试真题中见到了这个题目,这是一个非常有趣又有深度的问题,随即找到了这个问题的出处,在《剑指Offer》和LeetCode中均有该题,下面我贴一个CSDN官方给出的解题思路,循循渐进非常精彩   CSDN【面试现场】如何实现获取最小值的栈?     以及LeetCode链接  

  • AcWing 168. 生日蛋糕 (dfs剪枝)2020-03-02 23:05:28

    AcWing 168. 生日蛋糕 问题 传送门 代码 #include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int N = 25,INF = 1e9; int n,m; int minv[N],mins[N]; i

  • hdu 4786 Fibonacci Tree2020-02-01 12:44:18

    题目链接:hdu4786 题意:给你一个图,判断是否存在一个生成树,使得权值之和为一个斐波那契数。 思路:分别跑一次最大生成树和最小生成树。然后判断两个生成树的权值中间是否存在一个斐波那契数。如果存在则输出yes,否则输出no 代码: #include<bits/stdc++.h> using namespace std; c

  • typedef使用2020-01-07 11:01:40

    typedef是干嘛的 typedef是用来定义新类型的 这里的新有两个意思: 1、旧类型改成新的名字 比如:typedef INT int; 是说程序中应该使用int的地方统一使用INT了.这么做是不是有些脱裤子放屁了???其实不是.这种做法在移植上很常见.有些系统上的int长度不一样.比如有的系统上int是16位

  • 2019-09-18 20:54:20

    树的重心 int sz[N],mins = 1e9,rt; void dfs(int u,int fa) { sz[u] = 1; int maxs = 0; for(int i = head[u]; i;i = e[i].nxt) { int v = e[i].v; if(v == fa) continue; dfs(v,u); sz[u] += sz[v]; if(maxs < sz[v]) maxs =

  • Fishing Master(2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛)2019-08-26 23:04:24

    Problem Description Heard that eom is a fishing MASTER, you want to acknowledge him as your mentor. As everybody knows, if you want to be a MASTER's apprentice, you should pass the trial. So when you find fishing MASTER eom, the trial is as follow:Th

  • 2019CCPC秦皇岛站网络赛-1008-Fishing Master(贪心+思维)2019-08-23 20:01:03

    Fishing Master(贪心+思维) Problem Description Heard that eom is a fishing MASTER, you want to acknowledge him as your mentor. As everybody knows, if you want to be a MASTER’s apprentice, you should pass the trial. So when you find fishing MASTER eom, th

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有