Egg插件到底封装了啥
迫于比较好奇,下载了egg-redis,看看他如何将node直接可以引用的包,封装成为egg的插件
核心代码通过
迫于比较好奇,下载了egg-redis,看看他如何将node直接可以引用的包,封装成为egg的插件
核心代码通过
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Note: A leaf is a node with no children.
Example:
Given binary tree [3,9,20,null,null,15,7]
,
1 | 3 |
return its depth = 3.
判断树的深浅,采用
int left = max(root.left);
int right = max(root.right);
return Math.max(left,right) + 1;
//或者简写
return Math.max(max(root.left) + 1, max(root.right) + 1);
进行递归
Runtime: 0 ms, faster than 100.00% of Java online submissions for Maximum Depth of Binary Tree.
Memory Usage: 39.2 MB, less than 94.62% of Java online submissions for Maximum Depth of Binary Tree.
1 | /** |
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3]
is symmetric:
1 | 1 |
But the following [1,2,2,null,3,null,3]
is not:
1 | 1 |
Note:
Bonus points if you could solve it both recursively and iteratively.
一道验证树是否是对称的问题,主要采取递归的方法
1 | /** |
AMD:Asynchronous Module Definition (RequireJS)
CMD:Common Module Definition(SeaJS)
AMD | CMD | |
---|---|---|
1. | 提前执行 | 延迟执行(类似饿汉模式) |
2. | 依赖前置 | 依赖就近 |
3. | 浏览器(加载缓慢,异步load更好) | 服务器端 |
4. | 异步模块定义 | 通用模块定义 |
待补充,import-export
一个文件就是一个模块,在我们的代码外层,会套上一层CMD规范,这也就是为什么我们可以直接引用require,export,module的原因
1 | define(function(require, exports, module) { |
单个参数
1 | define(factory) |
多个参数define define(id?, deps?, factory)
1 | define('hello', ['jquery'], function(require, exports, module) { |
define.cmd Object
1 | if (typeof define === "function" && define.cmd) { |
同步加载
1 | define(function(require, exports) { |
异步加载
1 | define(function(require, exports, module) { |
返回解析后的绝对路径
return Object,对外提供接口
1 | define(function(require, exports) { |
但以下写法是错误的
1 | define(function(require, exports) { |
exports
仅仅是 module.exports
的一个引用。在 factory
内部给 exports
重新赋值时,并不会改变 module.exports
的值。因此给 exports
赋值是无效的,不能用来更改模块接口。
我说句简单的话:exports和module.exports,都是地址,指向同一个内容,如果你给exports赋值了一个新对象,他指向的内容就完全变了,和module.exprots就指向不是同一个地方了
modeule是一个对象,存储与当前模块相关联的一些属性和方法,默认为{}
module:function
module.id:String模块标识
module.url:String返回绝对路径(默认id=url,除非手写id)
module.dependencies:Array模块依赖
module.export:Object 大部分情况下和exports通用,但如果模块是一个类,就应该直接赋值给module.exports,这样调用就是一个类的构造器,可以直接new实例
1 | module.exports=new Person(); |
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
For example, given
1 | preorder = [3,9,20,15,7] |
Return the following binary tree:
1 | 3 |
题目是一个根据前序中序,生成二叉树的题目
前序遍历有个特点:根节点在前面,root -left-right
则遍历到3作为root,根据中序可以知道左子树是9,右子树是15 20 7
然后遍历9作为root,根据中序得到没有左子树,没有右子树
然后遍历20作为root,依次类推可以得到
1 | TreeNode root = new TreeNode(rootVal); |
其中insort比较好理解,确定root后
左子树在inStart, rootIndex-1之间
右子树在rootIndex+1, inEnd之间
对于presort
int len = rootIndex - inStart;获得root的左子树长度(根据中序获取rootIndex)
左子树在preStart+1, preStart+len之间
右子树在preStart+len+1, preEnd之间
1 | /** |
参考于百度,在递归条件乱了
Given a binary tree, return the inorder traversal of its nodes’ values.
给定一二叉树,中序遍历输出
ps:preorder,inorder,postorder,前中后
利用递归解决B树的遍历问题,这种问题的代码其实大同小异,前中后的遍历输出,只需要调整递归部分即可
1 | //preorder |
Solution
Runtime: 0 ms, faster than 100.00% of Java online submissions for Binary Tree Inorder Traversal.
Memory Usage: 37.9 MB, less than 5.11% of Java online submissions for Binary Tree Inorder Traversal.
1 | /** |
Complexity Analysis
solution还提供了另外一种方法通过stack pop的方式来完成:
https://leetcode.com/problems/binary-tree-inorder-traversal/solution/
同上
I find hexo’s theme:nexT v7.7.2 has some new features
we can set
1 | darkmode:true |
to open native dark mode
and there are other features like
1.git clone https://github.com/theme-next/hexo-theme-next themes/next
or in releases to download newest source code
2.copy file to hexo/theme/ such as :
/themes/hexo-theme-next-7.7.2/
3.open hexo’s _config.yml,and change theme’s value to hexo-theme-next-7.7.2 and u change your them successfully
4.update /themes/hexo-theme-next-7.7.2/_config.yml
Last , u can create new post to log your daily life
1 | yarn upgrade caniuse-lite browserslist |
and these days ,zehai.info ,may Expired ,sad
今天确实发生了一些事情,避之不谈
让我想起来了之前我在bili遇到的一件事情,一个up主癌症,自己经济能力不是很好,拍了一些很粗糙,没有剪辑过的视频,大意交代了自己得病,没有钱,拍了病历本,化验单,希望大家有能力的捐一点,后来up大概是拿到了一部分钱,具体多少我不太清楚,后来不知道发生了什么,画风开始转变
up视频的下面出现了很多评论
评论up有两个手机,家里有钱,然后up就对焦给大家看了他的两个手机,我记得两个都是红米类似的便宜机器,而且买了很久了
后来又人评论他家多有钱,然后up就拍下了回家和奶奶在一起的场面(当时已经没钱住院,就回家筹钱换医院试试)
后来又有人评论up主根本就没病,出来骗人钱,up就拍视频给人看治疗过程中的病历,化验单,至少我看不出来造假的证据
后来up出院了,买了张车票回家,和一个月前相比头发掉了很多,弹幕里面各种质疑,评论里面一片质疑,
亲身经历,环顾整个过程,我没有给up捐赠一分钱,也没有给予他任何帮助,就看了他整个生病的过程,从开始的加油,变成了一个‘骗子’,人们存在于网络之后,确实可以发表自己对于一件事情的看法,我想我如果是那个up,深陷其中一定很无奈
陈述结束
最后疫情一定会过去的
今天中午有收到Egg团队公开的文件调查,提及了很多技术名词,虽然不一定用到,但我也觉得列举出来会方便大家了解和比较,后续可能更新我用过的部分
引入目的:规范代码 | |
---|---|
ESLint | 通过extend继承某一个大类,然后配置rules来进行代码规范 |
JSCS | |
JSHint | |
JSDoc | |
Standard | |
TSLint | |
Flow |
解决了以下问题
其实ESLint只是一种语法校验,更多的还有流程上的规范,就像网传阿里的开发规范一样,就好比node中你可以用类的语法糖,也可以用原型,当一件事情有多种实现方式时,需要规范来选择一个普遍公用的,易维护,易扩展的方案
除去语法校验,还有TS的类型校验,比如GIT的分支规范,如master,staging,backup,develop,other branch
转移语言是2019年聊的比较多的,解决问题:
面试常被问到框架的问题,因为很多公司不会将项目搭建在原生的node服务上
一个好的框架事半功倍,
express是一个非常轻量的框架
Egg是一个企业级框架,约定大于配置
数据库是仅此于语言本身,另外的考点了,因为没有一个服务不涉猎存储,而数据库作为系统的数据基础,不仅重要也成为了面试的重点
Nginx
Tomcat
Apache
解决负载均衡
预处理一些请求,如过滤重复请求
docker集大成者,在微服务等场景应用较多
模式共计八种:
设计模式的提出,为了更好的解耦,可拓展,服务可靠,不限定某种语言的实现
一个类只有一个实例,如果存在就不实例化,如果不存在则new,以保证一个类只有一个实例
如网站的计数器,多线程的线程池
1 | (function(){ |