runtime

Finding largest and second-largest out of N numbers

北战南征 提交于 2020-01-10 11:34:52
问题 Given n numbers, how do I find the largest and second largest number using at most n+log(n) comparisons? Note that it's not O(n+log(n)), but really n+log(n) comparisons. 回答1: pajton gave a comment. Let me elaborate. As pajton said, this can be done by tournament selection. Think of this as a knock out singles tennis tournament, where player abilities have a strict order and the outcome of a match is decided solely by that order. In the first round half the people are eliminated. In the next

Finding largest and second-largest out of N numbers

不想你离开。 提交于 2020-01-10 11:32:51
问题 Given n numbers, how do I find the largest and second largest number using at most n+log(n) comparisons? Note that it's not O(n+log(n)), but really n+log(n) comparisons. 回答1: pajton gave a comment. Let me elaborate. As pajton said, this can be done by tournament selection. Think of this as a knock out singles tennis tournament, where player abilities have a strict order and the outcome of a match is decided solely by that order. In the first round half the people are eliminated. In the next

Finding largest and second-largest out of N numbers

允我心安 提交于 2020-01-10 11:32:34
问题 Given n numbers, how do I find the largest and second largest number using at most n+log(n) comparisons? Note that it's not O(n+log(n)), but really n+log(n) comparisons. 回答1: pajton gave a comment. Let me elaborate. As pajton said, this can be done by tournament selection. Think of this as a knock out singles tennis tournament, where player abilities have a strict order and the outcome of a match is decided solely by that order. In the first round half the people are eliminated. In the next

8.1Go并发

时光毁灭记忆、已成空白 提交于 2020-01-10 08:44:01
第八章 Go并发 Go语言区别于其他语言的一大特点就是出色的并发性能,最重要的一个特性那就是 go 关键字。 并发场景: UI小姐姐一边开着PS软件,一边微信疯狂的和产品经理打字交流,后台还听着网易云音乐。。 双11当天。。大伙疯狂的访问淘宝网站 CPU从单核向多核发展,计算机程序不该是串行的,浪费资源 串行程序由于IO操作被阻塞,整个程序处于停滞状态,其他IO无关的任务无法执行 并发必要性: 充分利用CPU核心的优势,提高程序执行效率 实现并发的模型: 多进程,多进程是在操作系统层面并发的基本模式,进程间互不影响,但是开销最大,进程由内核管理。 多线程,属于系统层面的并发模式,也是用的最多的有效模式,大多数软件使用多线程,开销小于多进程。 基于回调的非阻塞/异步IO。此架构处于多线程模式的危机,高并发服务器下,多线程会消耗殆尽服务器的内存和CPU资源。而通过事件驱动的方式使用异步IO,尽可能少用线程,降低开销,Node.js就是如此实践,但是此模式编程复杂度较高。 协程,Coroutine是一种用户态线程,寄存于线程中,系统开销极小,可以有效提高线程任务并发性,使用方式简单,结构清晰,避免多线程的缺点。需要编程语言的支持,如不支持,需要用户自行实现调度器。 共享内存系统 是比较常用的并发模式,线程之间通信采用共享内存的方式,程序员需要加锁等操作避免死锁、资源竞争等问题。

VBA in find function runtime error 91

喜你入骨 提交于 2020-01-10 04:45:27
问题 My question is concerning the runtime error 91 in VBA for excel. I've done some searching to no avail. My code is below. I have noted the section causing the error. Why is this happening, and how can i fix it and move on? Sub RemoveFooterRows(theFile) Dim found As Range Dim aggregateRow ''Error is from section below found = isItRow = Workbooks(theFile).Worksheets(1).Columns(1).Find _ ("Summary", Range("A1"), xlValues, xlPart, xlByRows, xlNext, False, , False) ''Error is from section above

babel学习笔记

泄露秘密 提交于 2020-01-10 00:22:27
babel 到底做了什么?怎么做的? 简单来说,babel主要用于把 JavaScript 中 es2015/2016/2017/2046 的新语法转化为 es5,让低端运行环境(如浏览器和 node )能够认识并执行。本文以 babel 6.x 为基准进行讨论。 严格来说,babel 也可以转化为更低的规范。但以目前情况来说,es5 规范已经足以覆盖绝大部分浏览器,因此常规来说转到 es5 是一个安全且流行的做法。 接下来,我们逐个给大家介绍一下babel里的包都是干什么的 包 babel-core 可以看做 babel 的编译器。babel 的核心 api 都在这里面,比如 transform,主要用来处理转码。它会把我们的 js 代码,抽象成 ast,即抽象语法树,是源代码的抽象语法结构的树状表现形式。我们可以理解为,它定义的一种分析 js 语法的树状结构。也就是说 es6 的新语法,跟老语法是不一样的,那我们怎么去定义这个语法呢。所以必须要先转成 ast,去发现这个语法的 kind,分别做对应的处理,才能转化成 es5。 babel-cli 提供命令行运行 babel。也就是你可以 babel filename 去对文件转码。 如下图: babel script.js --out-file script-compiled.js babel-runtime 这个包很简单

Spring AOP

允我心安 提交于 2020-01-10 00:13:26
Spring整合单元测试 在前面的案例中我么需要自己创建ApplicationContext对象,然后在调用getBean来获取需要测试的Bean Spring提供了一种更加方便的方式来创建测试所需的ApplicationContext,并且可以帮助我们把需要测试的Bean直接注入到测试类中 添加依赖: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.2.2.RELEASE</version> </dependency> 测试代码: import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; @RunWith(SpringJUnit4ClassRunner.class)//固定写法 @ContextConfiguration("classpath

开发函数计算的正确姿势——使用交互模式安装依赖

…衆ロ難τιáo~ 提交于 2020-01-09 16:19:26
前言 首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute) : 函数计算 是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。函数计算更多信息 参考 。 Fun : Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API 网关、日志服务等资源。它通过一个资源配置文件(template.yml),协助您进行开发、构建、部署操作。Fun 的更多文档 参考 。 备注: 本文介绍的技巧需要 Fun 版本大于等于 3.0.0-beta.1 。 依赖工具 本项目是在 MacOS 下开发的,涉及到的工具是平台无关的,对于 Linux 和 Windows 桌面系统应该也同样适用。在开始本例之前请确保如下工具已经正确的安装,更新到最新版本,并进行正确的配置。 Docker Fun Fun 和 Fcli 工具依赖于 docker 来模拟本地环境。 对于 MacOS 用户可以使用 homebrew 进行安装: brew cask install docker brew tap vangie/formula brew install fun Windows 和 Linux 用户安装请参考:<

【Leetcode 做题学算法周刊】第五期

天涯浪子 提交于 2020-01-08 05:39:45
首发于微信公众号《前端成长记》,写于 2019.12.06 背景 本文记录刷题过程中的整个思考过程,以供参考。主要内容涵盖: 题目分析设想 编写代码验证 查阅他人解法 思考总结 目录 100.相同的树 101.对称二叉树 104.二叉树的最大深度 107.二叉树的层次遍历II 108.将有序数组转换为二叉搜索树 Easy 100.相同的树 题目地址 题目描述 给定两个二叉树,编写一个函数来检验它们是否相同。 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。 示例: 输入: 1 1 / \ / \ 2 3 2 3 [1,2,3], [1,2,3] 输出: true 输入: 1 1 / \ 2 2 [1,2], [1,null,2] 输出: false 输入: 1 1 / \ / \ 2 1 1 2 [1,2,1], [1,1,2] 输出: false 题目分析设想 题目直接说了是二叉树,而二叉树的遍历方式有两种:深度优先和广度优先,我就从这两个思路来作答。 编写代码验证 Ⅰ.深度优先 代码: /** * @param {TreeNode} p * @param {TreeNode} q * @return {boolean} */ var isSameTree = function(p, q) { if (p === null && q === null)

Maven-02: 依赖

不打扰是莪最后的温柔 提交于 2020-01-08 03:11:56
其实一个 依赖声明 可以包含如下的一些元素: groupId,artifactId,version:依赖的基本坐标。 type :依赖的类型,对应于项目坐标定义的packaging。大多数情况下,该元素不必声明,其默认值为jar。 scope :依赖的范围。 optional :标记依赖是否可选。 exclusions :用来排除传递性依赖。 ----------------------------------------------------------------------- 依赖范围 : 依赖范围就是用来控制依赖与三种classpath(编译classpath,测试classpath,运行classpath)的关系,Maven有以下几种依赖范围: compile :编译依赖范围。如果没有指定,就会默认使用该依赖范围。使用此依赖范围的Maven依赖,对于编译,测试和运行三种classpath都有效,典型的例子是spring-core。 test :测试依赖范围。使用此依赖范围的Maven依赖,只对于测试classpath有效,典型的例子是JUnit。 provided :已提供依赖范围。使用此依赖范围的Maven依赖,对于编译和测试classpath有效,但在运行时无效,典型的例子是servlet-api。 runtime :运行时依赖范围。使用此依赖范围的Maven依赖