node

LeetCode All in One 题目讲解汇总(持续更新中...)

谁说我不能喝 提交于 2020-02-12 00:23:10
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. Example 1: Input: {"$id":"1","next":{"$id":"2","next":null,"random":{"$ref":"2"},"val":2},"random":{"$ref":"2"},"val":1} Explanation: Node 1's value is 1, both of its next and random pointer points to Node 2. Node 2's value is 2, its next pointer points to null and its random pointer points to itself. Note: You must return the copy of the given head as a reference to the cloned list. 这道链表的深度拷贝题的难点就在于如何处理随机指针的问题,由于每一个节点都有一个随机指针

线段树学习笔记

给你一囗甜甜゛ 提交于 2020-02-11 23:41:00
当要处理一个数组arr,求一定长度的和,并且对数组的单个值的大小进行修改。不进行特殊处理的话,不妨假设一定长度为n,那么求和的时间复杂度为O(n),修改为O(1)。 如果使用另外一个数组s,为arr的前缀和数组,那么求和的时间复杂度变为O(1),但是修改的时间复杂度变为O(n)。 这样的处理显然并不是很理想。 但使用线段树组进行处理的话,能让求和和修改的时间复杂度变为O(nlogn),从而达到减少时间复杂度的目的。 1.建立一个树状数组。 void build_tree(int arr[],int tree[],int node,int start,int endd) { if(start==endd) tree[node]=arr[endd];//递归的出口 else { int mid=(start+endd)/2; int left_node=2*node+1; int right_node=2*node+2; build_tree(arr,tree,left_node,start,mid); build_tree(arr,tree,right_node,mid+1,endd); tree[node]=tree[left_node]+tree[right_node]; } } 思路其实就是父亲等于左儿子+右儿子。 一直递归下去,直到出口。 2.对数组的区间值的询问 int

C盘清理,移动node 依赖和缓存文件

青春壹個敷衍的年華 提交于 2020-02-11 22:26:39
由于先前安装的node 没有做任何配置,都是傻瓜式下一步,导致了我很多依赖都放置C盘,内存占用过多;也不太好管理所有觉得将它移动到node安装目录 一、新建文件夹 在原本安装的nodejs目录下新建 node_cache 和 node_global 文件夹 二、重新配置 1、使用CMD进行配置 重新指定npm 的缓存路径,和全局配置, 你可以使用 npm config ls -l 或 npm config list 查看默认配置 我的是 prefix = "C:\\Users\\Lenovo\\AppData\\Roaming\\npm" cache = "C:\\Users\\Lenovo\\AppData\\Roaming\\npm-cache" 注意 请记住上面的路径 因为我比较懒,不想再重新拉一次依赖,所以我直接把这些目录对应的文件都直接拷贝到我新的目录下,然后再 重新配置 prefix cache 这个指向新的目录地址即可 原始目录 移动到新目录 移动到新目录 使用cmd 重新配置 npm config set prefix D:\develop\nodejs\node_global\npm npm config set cache D:\develop\nodejs\npm-cache 2、使用 npm config edit 可视化配置 也可以直接使用 C:

Picture POJ - 1177 线段树+离散化+扫描线 求交叉图像周长

混江龙づ霸主 提交于 2020-02-11 21:48:12
参考 https://www.cnblogs.com/null00/archive/2012/04/22/2464876.html #include <stdio.h> #include <algorithm> #define LEN 10000 using namespace std; struct Node { int left; int right; int count;//被覆盖次数 //所包含的区间数量,如三条[1,2],[2,3],[4,5]线段被覆盖,则line=2,因为 [1,2],[2,3]是连续的。 int line;//所包含的区间数量 int lbd;//左端点是否被覆盖 用来辅助对line的计算 int rbd;//右端点是否被覆盖 int m;//测度 ,即覆盖的区间长度,如[2,8]就为6 }node[LEN*4];; struct ScanLine { int x; int y1; int y2; int flag; }scan[LEN];; int y[LEN]; void build(int l, int r, int i) { node[i].left = l; node[i].right = r; node[i].count = 0; node[i].m = 0; node[i].line = 0; if (r - l > 1) { int

包含min函数的栈

浪子不回头ぞ 提交于 2020-02-11 18:37:33
题目描述: 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1)) 解题思路: 建立多一个辅助栈,用来存最小值 代码实现 package com . letcode . stackqueue ; import java . util . Stack ; public class No2 { Stack < Integer > stack1 = new Stack < > ( ) ; //辅助栈,存最小值的,大小与原栈一样,若最小值无更新,则存入上一个最小值 Stack < Integer > stack2 = new Stack < > ( ) ; private void push ( int node ) { stack1 . push ( node ) ; if ( stack2 . isEmpty ( ) ) stack2 . push ( node ) ; else stack2 . push ( node > stack2 . peek ( ) ? stack2 . peek ( ) : node ) ; } private int pop ( ) { if ( ! stack1 . isEmpty ( ) ) { stack1 . pop ( ) ; stack2 . pop ( ) ; } return stack1 .

Node中连接数据库

一笑奈何 提交于 2020-02-11 06:43:05
首先把mongodb数据库开启 在Node中操作mongodb数据库 通过第三方插件连接 mongoose 安装 : npm i moongoose 使用: const mongoose = require ( 'mongoose' ) ; //连接数据库,数据库名称为test 没有则会被创建 mongoose . connect ( "mongodb://localhost/test" , { useNewUrlParser : true , useUnifiedTopology : true } ) ; //创建表的模型 const Cat = mongoose . model ( '表名' , { name : String } ) ; //实例化一个Cat const kitty = new Cat ( { name : '陈林' } ) ; //持久化保存kitty实例(写入数据库) kitty . save ( ) . then ( ( ) => console . log ( '写入成功' ) ) ; 说明 Cat相当于模型,kitty相当于实例 Mongoose 会自动将大写开头的表名加复数,即数据库中是小写加复数形式 表名后面便是数据库模型 实例 const mongoose = require ( 'mongoose' ) //连接数据库 mongoose .

node.js建立简单应用

非 Y 不嫁゛ 提交于 2020-02-11 05:36:38
1. 建立工程 进入工程目录 cd D:\workspace\project 全局安装express,express作为命令被安装到了系统中 npm install -g express 查看express版本 express -V 3.2.2 使用express命令创建工程,并支持ejs D:\workspace\project>express -e nodejs-demo create : nodejs-demo create : nodejs-demo/package.json create : nodejs-demo/app.js create : nodejs-demo/public create : nodejs-demo/public/javascripts create : nodejs-demo/public/images create : nodejs-demo/public/stylesheets create : nodejs-demo/public/stylesheets/style.css create : nodejs-demo/routes create : nodejs-demo/routes/index.js create : nodejs-demo/routes/user.js create : nodejs-demo/views create

node-- express()模块

一笑奈何 提交于 2020-02-11 02:10:55
1、代码分析 var express = require('express'); var app = express(); app.get('/', function(req, res){ res.send('hello world'); console.log('hello world'); }); app.listen('8808'); require() 用于在当前模块中加载和使用其他模块;此方法是模块的基础,使用中大概有路径的概念就行。PS:JS文件可以去掉".js"后缀    exports 表示模块的导出对象,用于导出模块的属性和公共方法。    PS:一个模块的代码只会在模块第一次被使用时执行,不会因require多次而被初始化多次。 express() 表示创建express应用程序。简单几行代码其实就可以创建一个应用   app.listen() 就是在给定的主机和端口上监听请求,这个和node中http模块的http.createServer(function(){...}).listen()效果一致; app.set(name, value)和app.get(name)就是你想的那样,set()为设置 name 的值设为 value,get()为获取设置项 name 的值。如俺app.js的图片16行中的一句“app.set('port', process

AQS源码解析

。_饼干妹妹 提交于 2020-02-11 00:30:11
文大篇幅引用自HongJie大佬的 一行一行源码分析清楚AbstractQueuedSynchronizer ,这只是一篇简单的个人整理思路和总结(倒垃圾),如果觉得有些难懂的话,不要犹豫也不要疑惑,很明显是我这篇文章的问题,不是你的问题,这时你最好直接转去看HongJie大佬的原文,那个会好懂很多。还是看不懂的话建议隔一段时间再看,然后像我一样写(复制)一篇总结捋一下思路,加油! AQS 结构 属性 private transient volatile Node head; private transient volatile Node tail; // 这个是最重要的,代表当前锁的状态,0代表没有被占用,大于 0 代表有线程持有当前锁 // 这个值可以大于 1,是因为锁可以重入,每次重入都加上 1 private volatile int state; // 代表当前持有独占锁的线程,举个最重要的使用例子,因为锁可以重入 // reentrantLock.lock()可以嵌套调用多次,所以每次用这个来判断当前线程是否已经拥有了锁 // if (currentThread == getExclusiveOwnerThread()) {state++} private transient Thread exclusiveOwnerThread; 内部类 Node static

记录 electron node-gyp报错解决

不想你离开。 提交于 2020-02-11 00:11:15
参考1:[ https://github.com/nodejs/node-gyp#installation ] 参考2:[ https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules ] 1,npm install node-gyp -g // (已经装的卸载重新装) 2,npm install --global --production windows-build-tools // c++环境; 以管理员身份运行cmd [--2017]加这个参数为2017版本 3, node-gyp configure --msvs_version=2017 // 设置node-gyp使用的是2017版本,看你本装装的是哪个版本,有2015的 4,npm config set msvs_version 2017 // 设置npm对应的 windows-build-tools 版本,yarn同理吧 5,npm config set python python2.7 // 设置python版本,yarn同理吧 来源: https://www.cnblogs.com/ybixian/p/12293455.html