Skip to content

Commit

Permalink
feat: 每日一题算法+面试
Browse files Browse the repository at this point in the history
  • Loading branch information
joywins-y committed Nov 3, 2023
1 parent d13e472 commit 19f6ace
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 0 deletions.
147 changes: 147 additions & 0 deletions docs/algorithm/117.populating-next-right-pointers-in-each-node-ii.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# 117. 填充每个节点的下一个右侧节点指针 II

> 难度:<span style="color: #ffb800; font-weight: 500">中等</span>
>
> 地址:https://leetcode.cn/problems/populating-next-right-pointers-in-each-node-ii/description/
给定一个二叉树:

> struct Node {
> int val;
> Node *left;
> Node *right;
> Node \*next;
> }
填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 `NULL`

初始状态下,所有 next 指针都被设置为 `NULL`

**示例 1:**

> **<font color=#000>输入</font>**:root = [1,2,3,4,5,null,7]
>
> **<font color=#000>输出</font>**[1,#,2,3,#,4,5,7,#]
>
> **<font color=#000>解释</font>**:给定二叉树如图 A 所示,你的函数应该填充它的每个 next 指针,以指向其下一个右侧节点,如图 B 所示。序列化输出按层序遍历顺序(由 next 指针连接),'#' 表示每层的末尾。
**示例 2:**

> **<font color=#000>输入</font>**:root = []
>
> **<font color=#000>输出</font>**[]
**提示:**

- 树中的节点数在范围 `[0, 6000]`
- -`100 <= Node.val <= 100`

**进阶:**

- 你只能使用常量级额外空间。
- 使用递归解题也符合要求,本题中递归程序的隐式栈空间不计入额外空间复杂度。

**题解:**

```js
/**
* // Definition for a Node.
* function Node(val, left, right, next) {
* this.val = val === undefined ? null : val;
* this.left = left === undefined ? null : left;
* this.right = right === undefined ? null : right;
* this.next = next === undefined ? null : next;
* };
*/

/**
* @param {Node} root
* @return {Node}
*/
var connect = function (root) {
if (root === null) {
return null;
}
const queue = [root];
while (queue.length) {
const n = queue.length;
let last = null;
for (let i = 1; i <= n; ++i) {
let f = queue.shift();
if (f.left != null) {
queue.push(f.left);
}
if (f.right != null) {
queue.push(f.right);
}
if (i !== 1) {
last.next = f;
}
last = f;
}
}
return root;
};
```

```java
/*
// Definition for a Node.
class Node {
public int val;
public Node left;
public Node right;
public Node next;
public Node() {}
public Node(int _val) {
val = _val;
}
public Node(int _val, Node _left, Node _right, Node _next) {
val = _val;
left = _left;
right = _right;
next = _next;
}
};
*/
class Solution {
public Node connect(Node root) {
if (root == null)
return root;
//cur我们可以把它看做是每一层的链表
Node cur = root;
while (cur != null) {
//遍历当前层的时候,为了方便操作在下一
//层前面添加一个哑结点(注意这里是访问
//当前层的节点,然后把下一层的节点串起来)
Node dummy = new Node(0);
//pre表示访下一层节点的前一个节点
Node pre = dummy;
//然后开始遍历当前层的链表
while (cur != null) {
if (cur.left != null) {
//如果当前节点的左子节点不为空,就让pre节点
//的next指向他,也就是把它串起来
pre.next = cur.left;
//然后再更新pre
pre = pre.next;
}
//同理参照左子树
if (cur.right != null) {
pre.next = cur.right;
pre = pre.next;
}
//继续访问这一行的下一个节点
cur = cur.next;
}
//把下一层串联成一个链表之后,让他赋值给cur,
//后续继续循环,直到cur为空为止
cur = dummy.next;
}
return root;
}
}
```
Empty file.
6 changes: 6 additions & 0 deletions docs/markdown/常用网址.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ passwd: 1234

<br/>

## 软件测试

#### [2023软件测试学习路线图](https://bbs.itheima.com/forum.php?mod=viewthread&tid=405757&ordertype=1)

#### [黑马程序员软件测试学习路线图(2023官方完整版)](https://yun.itheima.com/subject/testmap/index.html)

## 博客网站

#### [ChoDocs](https://chodocs.cn/)
Expand Down
22 changes: 22 additions & 0 deletions docs/webpack/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# webpack 面试题

## 1. webpack 的作用是什么,谈谈你对它的理解

现在的前端网页功能丰富,特别是 SPA(Single Page Web Application 单页应用)技术流行后,JavaScript 的复杂度增加和需要一大堆依赖包,还需要解决 Scss,Less 等新增样式的扩展写法的编译工作。

所以现代化的前端已经完全依赖于 webpack 的辅助了。

现在最流行的三个前端框架,可以说和 webpack 已经紧密相连,框架官方都推出了和自身框架依赖的 webpack 构建工具。

react.js + webpack
vue.js + webpack
angluar.js + webpack

## 2. webpack 的工作流程

webpack 可以看做是模块打包机:它做的事情是,分析你的项目结构,找到 javascript 模块以及其他的一些浏览器不能直接运行的拓展语言(Sass,TypeScript 等),并将其转换和打包为合适的格式供浏览器使用。在 3.0 出现后,webpack 还肩负起了优化项目的责任。

## 3. webpack 打包原理

把一切都视为模块:不管是 css、js、Image 还是 html 都可以互相引用,通过定 entry.js,对所有依赖的文件进行跟踪,将各个模块通过 loader 和 plugings 处理,然后打包在一起。
按需加载:打包过程中 webpack 通过 code splitting 功能将文件分为多个 chunks,还可以将重复的部分单独提取出来作为 commonChunk,从而实现按需加载。把所有依赖打包成一个 bundle.js 文件,通过代码分割成单元片段并按需加载。

0 comments on commit 19f6ace

Please sign in to comment.