ICode9

精准搜索请尝试: 精确搜索
  • tp5.1 + think-queue + supervisor2022-04-14 00:04:29

    项目用的是 TP5.1 框架,消息队列用的think-queue消息队列,结合 supervisor 进程管理使队列进程常驻。在这里记录一下顺便分享给大家,下面逻辑是加入队列、消费队列和写入数据库。 一、tp5.1的安装方法  用 composer 安装最新稳定版本 composer create-project topthink/think 5.1

  • Heap堆的基本功能数组实现2022-04-14 00:01:52

    众所周知,堆是一种很好用的数据结构,是基于完全二叉树的。 1 //堆的数组实现 2 const int Maxsize = 10000; 3 int len = 0; //记录当前size 4 int heap[Maxsize+1]; 5 6 //当然也可以用vector实现 7 vector <int> Heap; 8 9 //每一次插入新的数据,都要和它的父节点比

  • 778. Swim in Rising Water2022-04-12 08:01:43

    BFS, using PriorityQueue to poll out the smallest number every time. The largest number you get will be the result. class Solution { public int swimInWater(int[][] grid) { if(grid==null) return 0; int m = grid.length, n =

  • 515. Find Largest Value in Each Tree Row2022-04-12 01:32:37

    My BFS solution: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, T

  • P18-二叉树最小深度-广度优先2022-04-11 11:33:23

    //二叉树的最小深度 /* * 给定一个二叉树,找出其最小深度 * 最小深度是从根节点到最近叶子节点的最短路径上的节点数量 * */ public class P18 { static class TreeNode{ int val; TreeNode left; TreeNode right; //记录当前深度

  • rabbitmq保证消息顺序2022-04-10 19:00:58

    1. rabbitmq消息顺序错乱 (1)场景:顺序消息 分发给不同消费者后,处理速度不一样,写入数据库书序乱掉        (2)解决方案: 给每个消费者开一个queue,需要保证数据的3个数据,放在同一个queue中  

  • 23. Merge k Sorted Lists2022-04-09 06:31:05

    My Solution 1: class Solution { public ListNode mergeKLists(ListNode[] lists) { PriorityQueue<ListNode> queue = new PriorityQueue<>((a,b)-> a.val-b.val); for(ListNode node:lists){ while(node!=null){

  • 346. Moving Average from Data Stream2022-04-09 05:31:06

    class MovingAverage { Queue<Integer> queue = new LinkedList<>(); int size = 0; double sum=0; public MovingAverage(int size) { this.size = size; } public double next(int val) { if(queue.size()==size)

  • Python:【列表】基本用法2022-04-08 13:01:55

    一、列表 列表(list)中的数据项不需要具有相同的类型,索引从0开始,元素方括号[]中,每个元素用逗号","隔开。 1.初始化 ① 空列表 可使用直接初始化空列表[],也可用list()方法。 list()方法语法: list(seq) seq:要转换为列表的元组或字符串。 返回值:列表。 >>>lis1=[] >>>lis1 [] >>>

  • 【LeetCode】二叉树的序列化和反序列化(dfs/bfs)2022-04-07 19:03:53

    二叉树的序列化和反序列化 题目链接:https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/ 题目大意:写两个函数,能够分别对二叉树进行序列化和反序列化 方法1:bfs 序列化:采用队列实现,根节点先入队,处理时按照左孩子右孩子的顺序处理 func (this *Codec) serializ

  • 56. Merge Intervals2022-04-07 07:00:07

    My PriorityQueue Solution: class Solution { public int[][] merge(int[][] intervals) { PriorityQueue<int[]> queue = new PriorityQueue<>((a,b)->a[0]-b[0]); for(int[] inter: intervals){ queue.offer(inter);

  • 301. Remove Invalid Parentheses2022-04-07 03:00:05

    Just use BFS to solve this problem: 1. put the s to queue 2. if s is not a valid string, then remove a '(' or ')', and then put to the queue. 3. once find valid strings, return. class Solution { public List<String> removeInv

  • locust 使用队列进行参数化操作2022-04-05 23:31:26

    Queue是python标准库中的线程安全的队列(FIFO)实现,提供了一个适用于多线程编程的先进先出的数据结构,即队列,用来在生产者和消费者线程之间的信息传递 基本方法: Queue.Queue(maxsize=0) FIFO,如果maxsize小于1就表示队列长度无限Queue.LifoQueue(maxsize=0) LIFO,如果maxsize小于1就表

  • 2022-4-5 高频面试题2022-04-05 16:01:43

    179. 最大数 给定一组非负整数 nums,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。 注意:输出结果可能非常大,所以你需要返回一个字符串而不是整数。 1 class Solution { 2 public String largestNumber(int[] nums) { 3 PriorityQueue<Integer

  • condition 实现生产者和消费者简单示例2022-04-04 18:31:06

    synchronized 与 wait()和 notify() 、notifyAll() 方法相结合可以实现等待/通知模式,ReentantLock 同样也可以实现,需要借助 Condition 实现 public class ConditionTest { private Lock lock = new ReentrantLock(); private Condition condition = lock.newCondition

  • tea queue2022-04-04 12:04:33

    题面: 有n个学生排队喝茶。 第i 个学生在li​的时刻来排队。如果在同一时刻有多名学生来排队,那么id 较大的学生就会在id 较小的学生之后。 队列中的学生的行为如下:如果学生面前没有人排队,那么他就用茶一秒钟,然后出队。否则会等待。如果第i 个学生在ri​的开始,仍然喝不到茶(队列前面

  • [简单] 622. 设计循环队列2022-04-04 03:00:47

    https://leetcode-cn.com/problems/design-circular-queue/   请原谅我直接,这一题。。。我这么傻心里都嘀咕,怎么出得那么傻~没有灵魂得题目。   class MyCircularQueue { List<Integer> queue = new ArrayList<>(); Integer capacity = 100000; public MyCirc

  • STL--容器stack、queue、priority_queue2022-04-03 13:33:11

    STL--容器stack、queue、priority_queue   一、栈(stack)   使用前要添加头文件#include <stack> 1.构造:stack<T> stk; //T为数据类型,这里为一个模板类型 2.赋值操作:stack<T>stk(s); //用s赋值给stk 3.数据存取:stk.push(elem); //将elem 压入栈stk中stk.pop(); //栈顶元素

  • 3.262022-04-03 08:00:41

    优先级队列 priority_queue<int,vector<int>,greater<int>  >  q; //升序队列,小顶堆 priority_queue <int,vector<int>,greater<int> > q; //降序队列,大顶堆 priority_queue <int,vector<int>,less<int> >q; 常用的成员函数: top 访问队头元素 empt

  • dotnev 使用.2022-04-01 14:00:39

    1 使用场景. 诸如:数据库账号密码,redis 地址,各种ak,sk 等信息.你是无法放置到代码中的. 这时将这些配置放入至一个 .env 文件下. 使用时,直接 $_ENV['xx'] 调取即可. 2 代码整备 // 2.1 编写 composer.json "require" : { ... "vlucas/phpdotenv": "^5.1@dev", ...

  • python 进程间利用queue 传递参数2022-03-31 12:33:56

    from multiprocessing import Process def chulibkk(bka,q): global connect,con for acc in acca: result=[] aty=str(acc["rootId"]) userid=str(acc['userId']) q.put(userid) def wm0323(q): g

  • Cloud Design Patterns & Architecture Styles2022-03-30 22:00:58

    Cloud Design Patterns Categories Data Management Design and Implementation Messaging Patterns Ambassador Anti-Corruption Layer Asynchronous Request-Reply Backends for Frontends Bulkhead Cache-Aside Choreography Circuit Breaker Claim Check Compensating Tr

  • 牛客华为机试HJ142022-03-29 08:33:35

    原题传送门 1. 问题描述 2. Solution 1、思路分析 逐个读入word,放到PriorityQueue中,读入结束后,逐个出队输出即可。 2、代码实现 Java实现 import java.io.IOException; import java.nio.file.Paths; import java.util.PriorityQueue; import java.util.Scanner; public class Ma

  • 二叉树2022-03-28 12:01:47

    继续把昨天剩的两道打完。 104. 二叉树的最大深度 层次遍历迭代 class Solution { public int maxDepth(TreeNode root) { int depth = 0; Deque<TreeNode> queue = new LinkedList<>(); if (root != null) queue.offer(root); while (!queue

  • 做题常用容器及方法2022-03-28 00:34:01

    queue,stack,priority_queue,没有clear函数,如果要清除 q=queue(); 创建一个新的

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

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

ICode9版权所有