-
-
-- 这一题需要确定 k 和 m 两个数的值。m 和 k 是有关系的,确定了一个值,另外一个值也确定了。由
-
-
-
-
-
-
-可得:
-
-
-
-
-
-
-根据题意,可以知道 k ≥2,m ≥1 ,所以有:
-
-
-
-
-
-
-所以 m 的取值范围确定了。那么外层循环从 1 到 log n 遍历。找到一个最小的 k ,能满足:
-
-可以用二分搜索来逼近找到最小的 k。先找到 k 的取值范围。由
-
-
-
-
-
-
-可得,
-
-
-
-
-
-所以 k 的取值范围是 [2, n*(1/m) ]。再利用二分搜索逼近找到最小的 k 即为答案。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
- "strconv"
-)
-
-func smallestGoodBase(n string) string {
- num, _ := strconv.ParseUint(n, 10, 64)
- for bit := uint64(math.Log2(float64(num))); bit >= 1; bit-- {
- low, high := uint64(2), uint64(math.Pow(float64(num), 1.0/float64(bit)))
- for low < high {
- mid := uint64(low + (high-low)>>1)
- sum := findBase(mid, bit)
- if sum == num {
- return strconv.FormatUint(mid, 10)
- } else if sum > num {
- high = mid - 1
- } else {
- low = mid + 1
- }
- }
- }
- return strconv.FormatUint(num-1, 10)
-}
-
-// 计算 k^m + k^(m-1) + ... + k + 1
-func findBase(mid, bit uint64) uint64 {
- sum, base := uint64(1), uint64(1)
- for i := uint64(1); i <= bit; i++ {
- base *= mid
- sum += base
- }
- return sum
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0485.Max-Consecutive-Ones.md b/website/content/ChapterFour/0485.Max-Consecutive-Ones.md
deleted file mode 100644
index 6bd2c40eb..000000000
--- a/website/content/ChapterFour/0485.Max-Consecutive-Ones.md
+++ /dev/null
@@ -1,59 +0,0 @@
-# [485. Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones/)
-
-
-## 题目
-
-Given a binary array, find the maximum number of consecutive 1s in this array.
-
-**Example 1**:
-
-```
-Input: [1,1,0,1,1,1]
-Output: 3
-Explanation: The first two digits or the last three digits are consecutive 1s.
- The maximum number of consecutive 1s is 3.
-```
-
-**Note**:
-
-- The input array will only contain `0` and `1`.
-- The length of input array is a positive integer and will not exceed 10,000
-
-
-## 题目大意
-
-给定一个二进制数组, 计算其中最大连续1的个数。
-
-注意:
-
-- 输入的数组只包含 0 和 1。
-- 输入数组的长度是正整数,且不超过 10,000。
-
-
-## 解题思路
-
-- 给定一个二进制数组, 计算其中最大连续1的个数。
-- 简单题。扫一遍数组,累计 1 的个数,动态维护最大的计数,最终输出即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func findMaxConsecutiveOnes(nums []int) int {
- maxCount, currentCount := 0, 0
- for _, v := range nums {
- if v == 1 {
- currentCount++
- } else {
- currentCount = 0
- }
- if currentCount > maxCount {
- maxCount = currentCount
- }
- }
- return maxCount
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0491.Increasing-Subsequences.md b/website/content/ChapterFour/0491.Increasing-Subsequences.md
deleted file mode 100755
index 9a262bb73..000000000
--- a/website/content/ChapterFour/0491.Increasing-Subsequences.md
+++ /dev/null
@@ -1,84 +0,0 @@
-# [491. Increasing Subsequences](https://leetcode.com/problems/increasing-subsequences/)
-
-
-## 题目
-
-Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2.
-
-**Example**:
-
- Input: [4, 6, 7, 7]
- Output: [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]
-
-**Note**:
-
-1. The length of the given array will not exceed 15.
-2. The range of integer in the given array is [-100,100].
-3. The given array may contain duplicates, and two equal integers should also be considered as a special case of increasing sequence.
-
-
-
-## 题目大意
-
-
-给定一个整型数组, 你的任务是找到所有该数组的递增子序列,递增子序列的长度至少是 2。
-
-说明:
-
-1. 给定数组的长度不会超过15。
-2. 数组中的整数范围是 [-100,100]。
-3. 给定数组中可能包含重复数字,相等的数字应该被视为递增的一种情况。
-
-
-
-
-## 解题思路
-
-
-- 给出一个数组,要求找出这个数组中所有长度大于 2 的非递减子序列。子序列顺序和原数组元素下标必须是顺序的,不能是逆序的。
-- 这一题和第 78 题和第 90 题是类似的题目。第 78 题和第 90 题是求所有子序列,这一题在这两题的基础上增加了非递减和长度大于 2 的条件。需要注意的两点是,原数组中元素可能会重复,最终结果输出的时候需要去重。最终结果输出的去重用 map 处理,数组中重复元素用 DFS 遍历搜索。在每次 DFS 中,用 map 记录遍历过的元素,保证本轮 DFS 中不出现重复的元素,递归到下一层还可以选择值相同,但是下标不同的另外一个元素。外层循环也要加一个 map,这个 map 是过滤每组解因为重复元素导致的重复解,经过过滤以后,起点不同了,最终的解也会不同。
-- 这一题和第 78 题,第 90 题类似,可以一起解答和复习。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func findSubsequences(nums []int) [][]int {
- c, visited, res := []int{}, map[int]bool{}, [][]int{}
- for i := 0; i < len(nums)-1; i++ {
- if _, ok := visited[nums[i]]; ok {
- continue
- } else {
- visited[nums[i]] = true
- generateIncSubsets(nums, i, c, &res)
- }
- }
- return res
-}
-
-func generateIncSubsets(nums []int, current int, c []int, res *[][]int) {
- c = append(c, nums[current])
- if len(c) >= 2 {
- b := make([]int, len(c))
- copy(b, c)
- *res = append(*res, b)
- }
- visited := map[int]bool{}
- for i := current + 1; i < len(nums); i++ {
- if nums[current] <= nums[i] {
- if _, ok := visited[nums[i]]; ok {
- continue
- } else {
- visited[nums[i]] = true
- generateIncSubsets(nums, i, c, res)
- }
- }
- }
- c = c[:len(c)-1]
- return
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0493.Reverse-Pairs.md b/website/content/ChapterFour/0493.Reverse-Pairs.md
deleted file mode 100755
index 6335db07b..000000000
--- a/website/content/ChapterFour/0493.Reverse-Pairs.md
+++ /dev/null
@@ -1,126 +0,0 @@
-# [493. Reverse Pairs](https://leetcode.com/problems/reverse-pairs/)
-
-
-## 题目
-
-Given an array `nums`, we call `(i, j)` an **important reverse pair** if `i < j` and `nums[i] > 2*nums[j]`.
-
-You need to return the number of important reverse pairs in the given array.
-
-**Example1:**
-
- Input: [1,3,2,3,1]
- Output: 2
-
-**Example2:**
-
- Input: [2,4,3,5,1]
- Output: 3
-
-**Note**:
-
-1. The length of the given array will not exceed `50,000`.
-2. All the numbers in the input array are in the range of 32-bit integer.
-
-
-## 题目大意
-
-给定一个数组 nums ,如果 i < j 且 nums[i] > 2\*nums[j] 我们就将 (i, j) 称作一个重要翻转对。你需要返回给定数组中的重要翻转对的数量。
-
-注意:
-
-- 给定数组的长度不会超过 50000。
-- 输入数组中的所有数字都在 32 位整数的表示范围内。
-
-
-## 解题思路
-
-
-- 给出一个数组,要求找出满足条件的所有的“重要的反转对” (i,j)。重要的反转对的定义是:`i 2*nums[j]`。
-- 这一题是 327 题的变种题。首先将数组中所有的元素以及各自的 `2*nums[i] + 1` 都放在字典中去重。去重以后再做离散化处理。这一题的测试用例会卡离散化,如果不离散化,Math.MaxInt32 会导致数字溢出,见测试用例中 2147483647, -2147483647 这组测试用例。离散后,映射关系 保存在字典中。从左往右遍历数组,先 query ,再 update ,这个顺序和第 327 题是反的。先 query 查找 `[2*nums[i] + 1, len(indexMap)-1]` 这个区间内满足条件的值,这个区间内的值都是 `> 2*nums[j]` 的。这一题移动的是 `j`,`j` 不断的变化,往线段树中不断插入的是 `i`。每轮循环先 query 一次前一轮循环中累积插入线段树中的 `i`,这些累积在线段树中的代表的是所有在 `j` 前面的 `i`。query 查询的是本轮 `[2*nums[j] + 1, len(indexMap)-1]`,如果能找到,即找到了这样一个 `j`,能满足 `nums[i] > 2*nums[j`, 把整个数组都扫完,累加的 query 出来的 count 计数就是最终答案。
-- 类似的题目:第 327 题,第 315 题。
-- 这一题用线段树并不是最优解,用线段树解这一题是为了训练线段树这个数据结构。最优解是解法二中的 mergesort。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-// 解法一 线段树,时间复杂度 O(n log n)
-func reversePairs(nums []int) int {
- if len(nums) < 2 {
- return 0
- }
- st, numsMap, indexMap, numsArray, res := template.SegmentCountTree{}, make(map[int]int, 0), make(map[int]int, 0), []int{}, 0
- numsMap[nums[0]] = nums[0]
- for _, num := range nums {
- numsMap[num] = num
- numsMap[2*num+1] = 2*num + 1
- }
- // numsArray 是 prefixSum 去重之后的版本,利用 numsMap 去重
- for _, v := range numsMap {
- numsArray = append(numsArray, v)
- }
- // 排序是为了使得线段树中的区间 left <= right,如果此处不排序,线段树中的区间有很多不合法。
- sort.Ints(numsArray)
- // 离散化,构建映射关系
- for i, n := range numsArray {
- indexMap[n] = i
- }
- numsArray = []int{}
- // 离散化,此题如果不离散化,MaxInt32 的数据会使得数字越界。
- for i := 0; i < len(indexMap); i++ {
- numsArray = append(numsArray, i)
- }
- // 初始化线段树,节点内的值都赋值为 0,即计数为 0
- st.Init(numsArray, func(i, j int) int {
- return 0
- })
- for _, num := range nums {
- res += st.Query(indexMap[num*2+1], len(indexMap)-1)
- st.UpdateCount(indexMap[num])
- }
- return res
-}
-
-// 解法二 mergesort
-func reversePairs1(nums []int) int {
- buf := make([]int, len(nums))
- return mergesortCount(nums, buf)
-}
-
-func mergesortCount(nums, buf []int) int {
- if len(nums) <= 1 {
- return 0
- }
- mid := (len(nums) - 1) / 2
- cnt := mergesortCount(nums[:mid+1], buf)
- cnt += mergesortCount(nums[mid+1:], buf)
- for i, j := 0, mid+1; i < mid+1; i++ { // Note!!! j is increasing.
- for ; j < len(nums) && nums[i] <= 2*nums[j]; j++ {
- }
- cnt += len(nums) - j
- }
- copy(buf, nums)
- for i, j, k := 0, mid+1, 0; k < len(nums); {
- if j >= len(nums) || i < mid+1 && buf[i] > buf[j] {
- nums[k] = buf[i]
- i++
- } else {
- nums[k] = buf[j]
- j++
- }
- k++
- }
- return cnt
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0494.Target-Sum.md b/website/content/ChapterFour/0494.Target-Sum.md
deleted file mode 100644
index dd3c2b103..000000000
--- a/website/content/ChapterFour/0494.Target-Sum.md
+++ /dev/null
@@ -1,108 +0,0 @@
-# [494. Target Sum](https://leetcode.com/problems/target-sum/)
-
-
-## 题目
-
-You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols `+` and `-`. For each integer, you should choose one from `+` and `-` as its new symbol.
-
-Find out how many ways to assign symbols to make sum of integers equal to target S.
-
-**Example 1**:
-
-```
-Input: nums is [1, 1, 1, 1, 1], S is 3.
-Output: 5
-Explanation:
-
--1+1+1+1+1 = 3
-+1-1+1+1+1 = 3
-+1+1-1+1+1 = 3
-+1+1+1-1+1 = 3
-+1+1+1+1-1 = 3
-
-There are 5 ways to assign symbols to make the sum of nums be target 3.
-```
-
-**Note**:
-
-1. The length of the given array is positive and will not exceed 20.
-2. The sum of elements in the given array will not exceed 1000.
-3. Your output answer is guaranteed to be fitted in a 32-bit integer.
-
-## 题目大意
-
-给定一个非负整数数组,a1, a2, ..., an, 和一个目标数,S。现在有两个符号 + 和 -。对于数组中的任意一个整数,可以从 + 或 - 中选择一个符号添加在前面。返回可以使最终数组和为目标数 S 的所有添加符号的方法数。
-
-提示:
-
-- 数组非空,且长度不会超过 20 。
-- 初始的数组的和不会超过 1000 。
-- 保证返回的最终结果能被 32 位整数存下。
-
-## 解题思路
-
-- 给出一个数组,要求在这个数组里面的每个元素前面加上 + 或者 - 号,最终总和等于 S。问有多少种不同的方法。
-- 这一题可以用 DP 和 DFS 解答。DFS 方法就不比较暴力简单了。见代码。这里分析一下 DP 的做法。题目要求在数组元素前加上 + 或者 - 号,其实相当于把数组分成了 2 组,一组全部都加 + 号,一组都加 - 号。记 + 号的一组 P ,记 - 号的一组 N,那么可以推出以下的关系。
-
- ```go
- sum(P) - sum(N) = target
- sum(P) + sum(N) + sum(P) - sum(N) = target + sum(P) + sum(N)
- 2 * sum(P) = target + sum(nums)
- ```
-
- 等号两边都加上 `sum(N) + sum(P)`,于是可以得到结果 `2 * sum(P) = target + sum(nums)`,那么这道题就转换成了,能否在数组中找到这样一个集合,和等于 `(target + sum(nums)) / 2`。那么这题就转化为了第 416 题了。`dp[i]` 中存储的是能使和为 `i` 的方法个数。
-
-- 如果和不是偶数,即不能被 2 整除,那说明找不到满足题目要求的解了,直接输出 0 。
-
-## 代码
-
-```go
-
-func findTargetSumWays(nums []int, S int) int {
- total := 0
- for _, n := range nums {
- total += n
- }
- if S > total || (S+total)%2 == 1 {
- return 0
- }
- target := (S + total) / 2
- dp := make([]int, target+1)
- dp[0] = 1
- for _, n := range nums {
- for i := target; i >= n; i-- {
- dp[i] += dp[i-n]
- }
- }
- return dp[target]
-}
-
-// 解法二 DFS
-func findTargetSumWays1(nums []int, S int) int {
- // sums[i] 存储的是后缀和 nums[i:],即从 i 到结尾的和
- sums := make([]int, len(nums))
- sums[len(nums)-1] = nums[len(nums)-1]
- for i := len(nums) - 2; i > -1; i-- {
- sums[i] = sums[i+1] + nums[i]
- }
- res := 0
- dfsFindTargetSumWays(nums, 0, 0, S, &res, sums)
- return res
-}
-
-func dfsFindTargetSumWays(nums []int, index int, curSum int, S int, res *int, sums []int) {
- if index == len(nums) {
- if curSum == S {
- *(res) = *(res) + 1
- }
- return
- }
- // 剪枝优化:如果 sums[index] 值小于剩下需要正数的值,那么右边就算都是 + 号也无能为力了,所以这里可以剪枝了
- if S-curSum > sums[index] {
- return
- }
- dfsFindTargetSumWays(nums, index+1, curSum+nums[index], S, res, sums)
- dfsFindTargetSumWays(nums, index+1, curSum-nums[index], S, res, sums)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0497.Random-Point-in-Non-overlapping-Rectangles.md b/website/content/ChapterFour/0497.Random-Point-in-Non-overlapping-Rectangles.md
deleted file mode 100755
index 3c68e0533..000000000
--- a/website/content/ChapterFour/0497.Random-Point-in-Non-overlapping-Rectangles.md
+++ /dev/null
@@ -1,134 +0,0 @@
-# [497. Random Point in Non-overlapping Rectangles](https://leetcode.com/problems/random-point-in-non-overlapping-rectangles)
-
-
-## 题目
-
-Given a list of **non-overlapping** axis-aligned rectangles `rects`, write a function `pick` which randomly and uniformily picks an **integer point** in the space covered by the rectangles.
-
-**Note**:
-
-1. An **integer point** is a point that has integer coordinates.
-2. A point on the perimeter of a rectangle is **included** in the space covered by the rectangles.
-3. `i`th rectangle = `rects[i]` = `[x1,y1,x2,y2]`, where `[x1, y1]` are the integer coordinates of the bottom-left corner, and `[x2, y2]` are the integer coordinates of the top-right corner.
-4. length and width of each rectangle does not exceed `2000`.
-5. `1 <= rects.length <= 100`
-6. `pick` return a point as an array of integer coordinates `[p_x, p_y]`
-7. `pick` is called at most `10000` times.
-
-**Example 1**:
-
- Input:
- ["Solution","pick","pick","pick"]
- [[[[1,1,5,5]]],[],[],[]]
- Output:
- [null,[4,1],[4,1],[3,3]]
-
-**Example 2**:
-
- Input:
- ["Solution","pick","pick","pick","pick","pick"]
- [[[[-2,-2,-1,-1],[1,0,3,0]]],[],[],[],[],[]]
- Output:
- [null,[-1,-2],[2,0],[-2,-1],[3,0],[-2,-2]]
-
-**Explanation of Input Syntax:**
-
-The input is two lists: the subroutines called and their arguments. `Solution`'s constructor has one argument, the array of rectangles `rects`. `pick` has no arguments. Arguments are always wrapped with a list, even if there aren't any.
-
-
-## 题目大意
-
-给定一个非重叠轴对齐矩形的列表 rects,写一个函数 pick 随机均匀地选取矩形覆盖的空间中的整数点。
-
-提示:
-
-1. 整数点是具有整数坐标的点。
-2. 矩形周边上的点包含在矩形覆盖的空间中。
-3. 第 i 个矩形 rects [i] = [x1,y1,x2,y2],其中 [x1,y1] 是左下角的整数坐标,[x2,y2] 是右上角的整数坐标。
-4. 每个矩形的长度和宽度不超过 2000。
-5. 1 <= rects.length <= 100
-6. pick 以整数坐标数组 [p_x, p_y] 的形式返回一个点。
-7. pick 最多被调用10000次。
-
-
-输入语法的说明:
-
-输入是两个列表:调用的子例程及其参数。Solution 的构造函数有一个参数,即矩形数组 rects。pick 没有参数。参数总是用列表包装的,即使没有也是如此。
-
-
-## 解题思路
-
-
-- 给出一个非重叠轴对齐矩形列表,每个矩形用左下角和右上角的两个坐标表示。要求 `pick()` 随机均匀地选取矩形覆盖的空间中的整数点。
-- 这一题是第 528 题的变种题,这一题权重是面积,按权重(面积)选择一个矩形,然后再从矩形中随机选择一个点即可。思路和代码和第 528 题一样。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math/rand"
-
-// Solution497 define
-type Solution497 struct {
- rects [][]int
- arr []int
-}
-
-// Constructor497 define
-func Constructor497(rects [][]int) Solution497 {
- s := Solution497{
- rects: rects,
- arr: make([]int, len(rects)),
- }
-
- for i := 0; i < len(rects); i++ {
- area := (rects[i][2] - rects[i][0] + 1) * (rects[i][3] - rects[i][1] + 1)
- if area < 0 {
- area = -area
- }
- if i == 0 {
- s.arr[0] = area
- } else {
- s.arr[i] = s.arr[i-1] + area
- }
- }
- return s
-}
-
-// Pick define
-func (so *Solution497) Pick() []int {
- r := rand.Int() % so.arr[len(so.arr)-1]
- //get rectangle first
- low, high, index := 0, len(so.arr)-1, -1
- for low <= high {
- mid := low + (high-low)>>1
- if so.arr[mid] > r {
- if mid == 0 || so.arr[mid-1] <= r {
- index = mid
- break
- }
- high = mid - 1
- } else {
- low = mid + 1
- }
- }
- if index == -1 {
- index = low
- }
- if index > 0 {
- r = r - so.arr[index-1]
- }
- length := so.rects[index][2] - so.rects[index][0]
- return []int{so.rects[index][0] + r%(length+1), so.rects[index][1] + r/(length+1)}
-}
-
-/**
- * Your Solution object will be instantiated and called as such:
- * obj := Constructor(rects);
- * param_1 := obj.Pick();
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0498.Diagonal-Traverse.md b/website/content/ChapterFour/0498.Diagonal-Traverse.md
deleted file mode 100755
index f28348a6b..000000000
--- a/website/content/ChapterFour/0498.Diagonal-Traverse.md
+++ /dev/null
@@ -1,184 +0,0 @@
-# [498. Diagonal Traverse](https://leetcode.com/problems/diagonal-traverse/)
-
-
-## 题目
-
-Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image.
-
-**Example**:
-
- Input:
- [
- [ 1, 2, 3 ],
- [ 4, 5, 6 ],
- [ 7, 8, 9 ]
- ]
-
- Output: [1,2,4,7,5,3,6,8,9]
-
- Explanation:
-
-
-
-**Note**:
-
-The total number of elements of the given matrix will not exceed 10,000.
-
-
-## 题目大意
-
-给定一个含有 M x N 个元素的矩阵(M 行,N 列),请以对角线遍历的顺序返回这个矩阵中的所有元素,对角线遍历如下图所示。
-
-
-
-说明: 给定矩阵中的元素总数不会超过 100000 。
-
-## 解题思路
-
-- 给出一个二维数组,要求按照如图的方式遍历整个数组。
-- 这一题用模拟的方式就可以解出来。需要注意的是边界条件:比如二维数组为空,二维数组退化为一行或者一列,退化为一个元素。具体例子见测试用例。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一
-func findDiagonalOrder1(matrix [][]int) []int {
- if matrix == nil || len(matrix) == 0 || len(matrix[0]) == 0 {
- return nil
- }
- row, col, dir, i, x, y, d := len(matrix), len(matrix[0]), [2][2]int{
- {-1, 1},
- {1, -1},
- }, 0, 0, 0, 0
- total := row * col
- res := make([]int, total)
- for i < total {
- for x >= 0 && x < row && y >= 0 && y < col {
- res[i] = matrix[x][y]
- i++
- x += dir[d][0]
- y += dir[d][1]
- }
- d = (d + 1) % 2
- if x == row {
- x--
- y += 2
- }
- if y == col {
- y--
- x += 2
- }
- if x < 0 {
- x = 0
- }
- if y < 0 {
- y = 0
- }
- }
- return res
-}
-
-// 解法二
-func findDiagonalOrder(matrix [][]int) []int {
- if len(matrix) == 0 {
- return []int{}
- }
- if len(matrix) == 1 {
- return matrix[0]
- }
- // dir = 0 代表从右上到左下的方向, dir = 1 代表从左下到右上的方向 dir = -1 代表上一次转变了方向
- m, n, i, j, dir, res := len(matrix), len(matrix[0]), 0, 0, 0, []int{}
- for index := 0; index < m*n; index++ {
- if dir == -1 {
- if (i == 0 && j < n-1) || (j == n-1) { // 上边界和右边界
- i++
- if j > 0 {
- j--
- }
- dir = 0
- addTraverse(matrix, i, j, &res)
- continue
- }
- if (j == 0 && i < m-1) || (i == m-1) { // 左边界和下边界
- if i > 0 {
- i--
- }
- j++
- dir = 1
- addTraverse(matrix, i, j, &res)
- continue
- }
- }
- if i == 0 && j == 0 {
- res = append(res, matrix[i][j])
- if j < n-1 {
- j++
- dir = -1
- addTraverse(matrix, i, j, &res)
- continue
- } else {
- if i < m-1 {
- i++
- dir = -1
- addTraverse(matrix, i, j, &res)
- continue
- }
- }
- }
- if i == 0 && j < n-1 { // 上边界
- if j < n-1 {
- j++
- dir = -1
- addTraverse(matrix, i, j, &res)
- continue
- }
- }
- if j == 0 && i < m-1 { // 左边界
- if i < m-1 {
- i++
- dir = -1
- addTraverse(matrix, i, j, &res)
- continue
- }
- }
- if j == n-1 { // 右边界
- if i < m-1 {
- i++
- dir = -1
- addTraverse(matrix, i, j, &res)
- continue
- }
- }
- if i == m-1 { // 下边界
- j++
- dir = -1
- addTraverse(matrix, i, j, &res)
- continue
- }
- if dir == 1 {
- i--
- j++
- addTraverse(matrix, i, j, &res)
- continue
- }
- if dir == 0 {
- i++
- j--
- addTraverse(matrix, i, j, &res)
- continue
- }
- }
- return res
-}
-
-func addTraverse(matrix [][]int, i, j int, res *[]int) {
- if i >= 0 && i <= len(matrix)-1 && j >= 0 && j <= len(matrix[0])-1 {
- *res = append(*res, matrix[i][j])
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0500.Keyboard-Row.md b/website/content/ChapterFour/0500.Keyboard-Row.md
deleted file mode 100755
index 6d6eda08f..000000000
--- a/website/content/ChapterFour/0500.Keyboard-Row.md
+++ /dev/null
@@ -1,62 +0,0 @@
-# [500. Keyboard Row](https://leetcode.com/problems/keyboard-row/)
-
-
-## 题目
-
-Given a List of words, return the words that can be typed using letters of **alphabet** on only one row's of American keyboard like the image below.
-
-
-
-**Example**:
-
- Input: ["Hello", "Alaska", "Dad", "Peace"]
- Output: ["Alaska", "Dad"]
-
-**Note**:
-
-1. You may use one character in the keyboard more than once.
-2. You may assume the input string will only contain letters of alphabet.
-
-
-## 题目大意
-
-给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词。键盘如上图所示。
-
-## 解题思路
-
-- 给出一个字符串数组,要求依次判断数组中的每个字符串是否都位于键盘上的同一个行,如果是就输出。这也是一道水题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strings"
-
-func findWords500(words []string) []string {
- rows := []string{"qwertyuiop", "asdfghjkl", "zxcvbnm"}
- output := make([]string, 0)
- for _, s := range words {
- if len(s) == 0 {
- continue
- }
- lowerS := strings.ToLower(s)
- oneRow := false
- for _, r := range rows {
- if strings.ContainsAny(lowerS, r) {
- oneRow = !oneRow
- if !oneRow {
- break
- }
- }
- }
- if oneRow {
- output = append(output, s)
- }
- }
- return output
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0503.Next-Greater-Element-II.md b/website/content/ChapterFour/0503.Next-Greater-Element-II.md
deleted file mode 100644
index a8d5f46c9..000000000
--- a/website/content/ChapterFour/0503.Next-Greater-Element-II.md
+++ /dev/null
@@ -1,78 +0,0 @@
-# [503. Next Greater Element II](https://leetcode.com/problems/next-greater-element-ii/)
-
-## 题目
-
-Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, output -1 for this number.
-
-**Example 1**:
-
-```
-
-Input: [1,2,1]
-Output: [2,-1,2]
-Explanation: The first 1's next greater number is 2;
-The number 2 can't find next greater number;
-The second 1's next greater number needs to search circularly, which is also 2.
-
-```
-
-**Note**: The length of given array won't exceed 10000.
-
-## 题目大意
-
-题目给出数组 A,针对 A 中的每个数组中的元素,要求在 A 数组中找出比该元素大的数,A 是一个循环数组。如果找到了就输出这个值,如果找不到就输出 -1。
-
-
-## 解题思路
-
-这题是第 496 题的加强版,在第 496 题的基础上增加了循环数组的条件。这一题可以依旧按照第 496 题的做法继续模拟。更好的做法是用单调栈,栈中记录单调递增的下标。
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 单调栈
-func nextGreaterElements(nums []int) []int {
- res := make([]int, 0)
- indexes := make([]int, 0)
- for i := 0; i < len(nums); i++ {
- res = append(res, -1)
- }
- for i := 0; i < len(nums)*2; i++ {
- num := nums[i%len(nums)]
- for len(indexes) > 0 && nums[indexes[len(indexes)-1]] < num {
- index := indexes[len(indexes)-1]
- res[index] = num
- indexes = indexes[:len(indexes)-1]
- }
- indexes = append(indexes, i%len(nums))
- }
- return res
-}
-
-// 解法二
-func nextGreaterElements1(nums []int) []int {
- if len(nums) == 0 {
- return []int{}
- }
- res := []int{}
- for i := 0; i < len(nums); i++ {
- j, find := (i+1)%len(nums), false
- for j != i {
- if nums[j] > nums[i] {
- find = true
- res = append(res, nums[j])
- break
- }
- j = (j + 1) % len(nums)
- }
- if !find {
- res = append(res, -1)
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0507.Perfect-Number.md b/website/content/ChapterFour/0507.Perfect-Number.md
deleted file mode 100644
index 12d0c7649..000000000
--- a/website/content/ChapterFour/0507.Perfect-Number.md
+++ /dev/null
@@ -1,64 +0,0 @@
-# [507. Perfect Number](https://leetcode.com/problems/perfect-number/)
-
-
-
-## 题目
-
-We define the Perfect Number is a **positive** integer that is equal to the sum of all its **positive** divisors except itself.
-
-Now, given an
-
-**integer**
-
-n, write a function that returns true when it is a perfect number and false when it is not.
-
-**Example**:
-
-```
-Input: 28
-Output: True
-Explanation: 28 = 1 + 2 + 4 + 7 + 14
-```
-
-**Note**: The input number **n** will not exceed 100,000,000. (1e8)
-
-## 题目大意
-
-对于一个 正整数,如果它和除了它自身以外的所有正因子之和相等,我们称它为“完美数”。给定一个 整数 n, 如果他是完美数,返回 True,否则返回 False
-
-## 解题思路
-
-- 给定一个整数,要求判断这个数是不是完美数。整数的取值范围小于 1e8 。
-- 简单题。按照题意描述,先获取这个整数的所有正因子,如果正因子的和等于原来这个数,那么它就是完美数。
-- 这一题也可以打表,1e8 以下的完美数其实并不多,就 5 个。
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math"
-
-// 方法一
-func checkPerfectNumber(num int) bool {
- if num <= 1 {
- return false
- }
- sum, bound := 1, int(math.Sqrt(float64(num)))+1
- for i := 2; i < bound; i++ {
- if num%i != 0 {
- continue
- }
- corrDiv := num / i
- sum += corrDiv + i
- }
- return sum == num
-}
-
-// 方法二 打表
-func checkPerfectNumber_(num int) bool {
- return num == 6 || num == 28 || num == 496 || num == 8128 || num == 33550336
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0508.Most-Frequent-Subtree-Sum.md b/website/content/ChapterFour/0508.Most-Frequent-Subtree-Sum.md
deleted file mode 100755
index 91c2a9a6d..000000000
--- a/website/content/ChapterFour/0508.Most-Frequent-Subtree-Sum.md
+++ /dev/null
@@ -1,123 +0,0 @@
-# [508. Most Frequent Subtree Sum](https://leetcode.com/problems/most-frequent-subtree-sum/)
-
-
-## 题目
-
-Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself). So what is the most frequent subtree sum value? If there is a tie, return all the values with the highest frequency in any order.
-
-**Examples 1**
-
-Input:
-
- 5
- / \
- 2 -3
-
-return [2, -3, 4], since all the values happen only once, return all of them in any order.
-
-**Examples 2**
-
-Input:
-
- 5
- / \
- 2 -5
-
-return [2], since 2 happens twice, however -5 only occur once.
-
-**Note**: You may assume the sum of values in any subtree is in the range of 32-bit signed integer.
-
-
-## 题目大意
-
-给出二叉树的根,找出出现次数最多的子树元素和。一个结点的子树元素和定义为以该结点为根的二叉树上所有结点的元素之和(包括结点本身)。然后求出出现次数最多的子树元素和。如果有多个元素出现的次数相同,返回所有出现次数最多的元素(不限顺序)。提示: 假设任意子树元素和均可以用 32 位有符号整数表示。
-
-## 解题思路
-
-
-- 给出一个树,要求求出每个节点以自己为根节点的子树的所有节点值的和,最后按照这些和出现的频次,输出频次最多的和,如果频次出现次数最多的对应多个和,则全部输出。
-- 递归找出每个节点的累加和,用 map 记录频次,最后把频次最多的输出即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-
-// 解法一 维护最大频次,不用排序
-func findFrequentTreeSum(root *TreeNode) []int {
- memo := make(map[int]int)
- collectSum(root, memo)
- res := []int{}
- most := 0
- for key, val := range memo {
- if most == val {
- res = append(res, key)
- } else if most < val {
- most = val
- res = []int{key}
- }
- }
- return res
-}
-
-func collectSum(root *TreeNode, memo map[int]int) int {
- if root == nil {
- return 0
- }
- sum := root.Val + collectSum(root.Left, memo) + collectSum(root.Right, memo)
- if v, ok := memo[sum]; ok {
- memo[sum] = v + 1
- } else {
- memo[sum] = 1
- }
- return sum
-}
-
-// 解法二 求出所有和再排序
-func findFrequentTreeSum1(root *TreeNode) []int {
- if root == nil {
- return []int{}
- }
- freMap, freList, reFreMap := map[int]int{}, []int{}, map[int][]int{}
- findTreeSum(root, freMap)
- for k, v := range freMap {
- tmp := reFreMap[v]
- tmp = append(tmp, k)
- reFreMap[v] = tmp
- }
- for k := range reFreMap {
- freList = append(freList, k)
- }
- sort.Ints(freList)
- return reFreMap[freList[len(freList)-1]]
-}
-
-func findTreeSum(root *TreeNode, fre map[int]int) int {
- if root == nil {
- return 0
- }
- if root != nil && root.Left == nil && root.Right == nil {
- fre[root.Val]++
- return root.Val
- }
- val := findTreeSum(root.Left, fre) + findTreeSum(root.Right, fre) + root.Val
- fre[val]++
- return val
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0509.Fibonacci-Number.md b/website/content/ChapterFour/0509.Fibonacci-Number.md
deleted file mode 100755
index ee3046077..000000000
--- a/website/content/ChapterFour/0509.Fibonacci-Number.md
+++ /dev/null
@@ -1,171 +0,0 @@
-# [509. Fibonacci Number](https://leetcode.com/problems/fibonacci-number/)
-
-
-## 题目
-
-The **Fibonacci numbers**, commonly denoted `F(n)` form a sequence, called the **Fibonacci sequence**, such that each number is the sum of the two preceding ones, starting from `0` and `1`. That is,
-
- F(0) = 0, F(1) = 1
- F(N) = F(N - 1) + F(N - 2), for N > 1.
-
-Given `N`, calculate `F(N)`.
-
-**Example 1**:
-
- Input: 2
- Output: 1
- Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
-
-**Example 2**:
-
- Input: 3
- Output: 2
- Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
-
-**Example 3**:
-
- Input: 4
- Output: 3
- Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
-
-**Note**:
-
-0 ≤ `N` ≤ 30.
-
-
-## 题目大意
-
-斐波那契数,通常用 F(n) 表示,形成的序列称为斐波那契数列。该数列由 0 和 1 开始,后面的每一项数字都是前面两项数字的和。也就是:
-
-```
-F(0) = 0, F(1) = 1
-F(N) = F(N - 1) + F(N - 2), 其中 N > 1.
-```
-
-给定 N,计算 F(N)。
-
-提示:0 ≤ N ≤ 30
-
-## 解题思路
-
-
-- 求斐波那契数列
-- 这一题解法很多,大的分类是四种,递归,记忆化搜索(dp),矩阵快速幂,通项公式。其中记忆化搜索可以写 3 种方法,自底向上的,自顶向下的,优化空间复杂度版的。通项公式方法实质是求 a^b 这个还可以用快速幂优化时间复杂度到 O(log n) 。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math"
-
-// 解法一 递归法 时间复杂度 O(2^n),空间复杂度 O(n)
-func fib(N int) int {
- if N <= 1 {
- return N
- }
- return fib(N-1) + fib(N-2)
-}
-
-// 解法二 自底向上的记忆化搜索 时间复杂度 O(n),空间复杂度 O(n)
-func fib1(N int) int {
- if N <= 1 {
- return N
- }
- cache := map[int]int{0: 0, 1: 1}
- for i := 2; i <= N; i++ {
- cache[i] = cache[i-1] + cache[i-2]
- }
- return cache[N]
-}
-
-// 解法三 自顶向下的记忆化搜索 时间复杂度 O(n),空间复杂度 O(n)
-func fib2(N int) int {
- if N <= 1 {
- return N
- }
- return memoize(N, map[int]int{0: 0, 1: 1})
-}
-
-func memoize(N int, cache map[int]int) int {
- if _, ok := cache[N]; ok {
- return cache[N]
- }
- cache[N] = memoize(N-1, cache) + memoize(N-2, cache)
- return memoize(N, cache)
-}
-
-// 解法四 优化版的 dp,节约内存空间 时间复杂度 O(n),空间复杂度 O(1)
-func fib3(N int) int {
- if N <= 1 {
- return N
- }
- if N == 2 {
- return 1
- }
- current, prev1, prev2 := 0, 1, 1
- for i := 3; i <= N; i++ {
- current = prev1 + prev2
- prev2 = prev1
- prev1 = current
- }
- return current
-}
-
-// 解法五 矩阵快速幂 时间复杂度 O(log n),空间复杂度 O(log n)
-// | 1 1 | ^ n = | F(n+1) F(n) |
-// | 1 0 | | F(n) F(n-1) |
-func fib4(N int) int {
- if N <= 1 {
- return N
- }
- var A = [2][2]int{
- {1, 1},
- {1, 0},
- }
- A = matrixPower(A, N-1)
- return A[0][0]
-}
-
-func matrixPower(A [2][2]int, N int) [2][2]int {
- if N <= 1 {
- return A
- }
- A = matrixPower(A, N/2)
- A = multiply(A, A)
-
- var B = [2][2]int{
- {1, 1},
- {1, 0},
- }
- if N%2 != 0 {
- A = multiply(A, B)
- }
-
- return A
-}
-
-func multiply(A [2][2]int, B [2][2]int) [2][2]int {
- x := A[0][0]*B[0][0] + A[0][1]*B[1][0]
- y := A[0][0]*B[0][1] + A[0][1]*B[1][1]
- z := A[1][0]*B[0][0] + A[1][1]*B[1][0]
- w := A[1][0]*B[0][1] + A[1][1]*B[1][1]
- A[0][0] = x
- A[0][1] = y
- A[1][0] = z
- A[1][1] = w
- return A
-}
-
-// 解法六 公式法 f(n)=(1/√5)*{[(1+√5)/2]^n -[(1-√5)/2]^n},用 时间复杂度在 O(log n) 和 O(n) 之间,空间复杂度 O(1)
-// 经过实际测试,会发现 pow() 系统函数比快速幂慢,说明 pow() 比 O(log n) 慢
-// 斐波那契数列是一个自然数的数列,通项公式却是用无理数来表达的。而且当 n 趋向于无穷大时,前一项与后一项的比值越来越逼近黄金分割 0.618(或者说后一项与前一项的比值小数部分越来越逼近 0.618)。
-// 斐波那契数列用计算机计算的时候可以直接用四舍五入函数 Round 来计算。
-func fib5(N int) int {
- var goldenRatio float64 = float64((1 + math.Sqrt(5)) / 2)
- return int(math.Round(math.Pow(goldenRatio, float64(N)) / math.Sqrt(5)))
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md b/website/content/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md
deleted file mode 100755
index c4f7f0830..000000000
--- a/website/content/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md
+++ /dev/null
@@ -1,112 +0,0 @@
-# [513. Find Bottom Left Tree Value](https://leetcode.com/problems/find-bottom-left-tree-value/)
-
-
-## 题目
-
-Given a binary tree, find the leftmost value in the last row of the tree.
-
-**Example 1**:
-
- Input:
-
- 2
- / \
- 1 3
-
- Output:
- 1
-
-**Example 2**:
-
- Input:
-
- 1
- / \
- 2 3
- / / \
- 4 5 6
- /
- 7
-
- Output:
- 7
-
-**Note**: You may assume the tree (i.e., the given root node) is not **NULL**.
-
-
-## 题目大意
-
-给定一个二叉树,在树的最后一行找到最左边的值。注意: 您可以假设树(即给定的根节点)不为 NULL。
-
-
-
-
-
-
-## 解题思路
-
-
-- 给出一棵树,输出这棵树最下一层中最左边的节点的值。
-- 这一题用 DFS 和 BFS 均可解题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-
-// 解法一 DFS
-func findBottomLeftValue(root *TreeNode) int {
- if root == nil {
- return 0
- }
- res, maxHeight := 0, -1
- findBottomLeftValueDFS(root, 0, &res, &maxHeight)
- return res
-}
-
-func findBottomLeftValueDFS(root *TreeNode, curHeight int, res, maxHeight *int) {
- if curHeight > *maxHeight && root.Left == nil && root.Right == nil {
- *maxHeight = curHeight
- *res = root.Val
- }
- if root.Left != nil {
- findBottomLeftValueDFS(root.Left, curHeight+1, res, maxHeight)
- }
- if root.Right != nil {
- findBottomLeftValueDFS(root.Right, curHeight+1, res, maxHeight)
- }
-}
-
-// 解法二 BFS
-func findBottomLeftValue1(root *TreeNode) int {
- queue := []*TreeNode{root}
- for len(queue) > 0 {
- next := []*TreeNode{}
- for _, node := range queue {
- if node.Left != nil {
- next = append(next, node.Left)
- }
- if node.Right != nil {
- next = append(next, node.Right)
- }
- }
- if len(next) == 0 {
- return queue[0].Val
- }
- queue = next
- }
- return 0
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md b/website/content/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md
deleted file mode 100755
index 7cf9f3034..000000000
--- a/website/content/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md
+++ /dev/null
@@ -1,93 +0,0 @@
-# [515. Find Largest Value in Each Tree Row](https://leetcode.com/problems/find-largest-value-in-each-tree-row/)
-
-
-## 题目
-
-You need to find the largest value in each row of a binary tree.
-
-**Example**:
-
- Input:
-
- 1
- / \
- 3 2
- / \ \
- 5 3 9
-
- Output: [1, 3, 9]
-
-
-## 题目大意
-
-求在二叉树的每一行中找到最大的值。
-
-
-## 解题思路
-
-
-- 给出一个二叉树,要求依次输出每行的最大值
-- 用 BFS 层序遍历,将每层排序取出最大值。改进的做法是遍历中不断更新每层的最大值。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
- "sort"
-)
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-
-// 解法一 层序遍历二叉树,再将每层排序取出最大值
-func largestValues(root *TreeNode) []int {
- tmp := levelOrder(root)
- res := []int{}
- for i := 0; i < len(tmp); i++ {
- sort.Ints(tmp[i])
- res = append(res, tmp[i][len(tmp[i])-1])
- }
- return res
-}
-
-// 解法二 层序遍历二叉树,遍历过程中不断更新最大值
-func largestValues1(root *TreeNode) []int {
- if root == nil {
- return []int{}
- }
- q := []*TreeNode{root}
- var res []int
- for len(q) > 0 {
- qlen := len(q)
- max := math.MinInt32
- for i := 0; i < qlen; i++ {
- node := q[0]
- q = q[1:]
- if node.Val > max {
- max = node.Val
- }
- if node.Left != nil {
- q = append(q, node.Left)
- }
- if node.Right != nil {
- q = append(q, node.Right)
- }
- }
- res = append(res, max)
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md b/website/content/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md
deleted file mode 100644
index d139890af..000000000
--- a/website/content/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md
+++ /dev/null
@@ -1,76 +0,0 @@
-# [524. Longest Word in Dictionary through Deleting](https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/)
-
-## 题目
-
-Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.
-
-
-**Example 1**:
-
-```
-
-Input:
-s = "abpcplea", d = ["ale","apple","monkey","plea"]
-
-Output:
-"apple"
-
-```
-
-
-**Example 2**:
-
-```
-
-Input:
-s = "abpcplea", d = ["a","b","c"]
-
-Output:
-"a"
-
-```
-
-**Note**:
-
-- All the strings in the input will only contain lower-case letters.
-- The size of the dictionary won't exceed 1,000.
-- The length of all the strings in the input won't exceed 1,000.
-
-
-## 题目大意
-
-
-给出一个初始串,再给定一个字符串数组,要求在字符串数组中找到能在初始串中通过删除字符得到的最长的串,如果最长的串有多组解,要求输出字典序最小的那组解。
-
-## 解题思路
-
-
-这道题就单纯的用 O(n^2) 暴力循环即可,注意最终解的要求,如果都是最长的串,要求输出字典序最小的那个串,只要利用字符串比较得到字典序最小的串即可。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func findLongestWord(s string, d []string) string {
- res := ""
- for i := 0; i < len(d); i++ {
- pointS := 0
- pointD := 0
- for pointS < len(s) && pointD < len(d[i]) {
- if s[pointS] == d[i][pointD] {
- pointD++
- }
- pointS++
- }
- if pointD == len(d[i]) && (len(res) < len(d[i]) || (len(res) == len(d[i]) && res > d[i])) {
- res = d[i]
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0526.Beautiful-Arrangement.md b/website/content/ChapterFour/0526.Beautiful-Arrangement.md
deleted file mode 100755
index f9f005cda..000000000
--- a/website/content/ChapterFour/0526.Beautiful-Arrangement.md
+++ /dev/null
@@ -1,110 +0,0 @@
-# [526. Beautiful Arrangement](https://leetcode.com/problems/beautiful-arrangement/)
-
-
-## 题目
-
-Suppose you have **N** integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these **N** numbers successfully if one of the following is true for the ith position (1 <= i <= N) in this array:
-
-1. The number at the i position is divisible by **i**.th
-2. **i** is divisible by the number at the i position.th
-
-Now given N, how many beautiful arrangements can you construct?
-
-**Example 1**:
-
- Input: 2
- Output: 2
- Explanation:
-
- The first beautiful arrangement is [1, 2]:
-
- Number at the 1st position (i=1) is 1, and 1 is divisible by i (i=1).
-
- Number at the 2nd position (i=2) is 2, and 2 is divisible by i (i=2).
-
- The second beautiful arrangement is [2, 1]:
-
- Number at the 1st position (i=1) is 2, and 2 is divisible by i (i=1).
-
- Number at the 2nd position (i=2) is 1, and i (i=2) is divisible by 1.
-
-**Note**:
-
-1. **N** is a positive integer and will not exceed 15.
-
-
-## 题目大意
-
-假设有从 1 到 N 的 N 个整数,如果从这 N 个数字中成功构造出一个数组,使得数组的第 i 位 (1 <= i <= N) 满足如下两个条件中的一个,我们就称这个数组为一个优美的排列。条件:
-
-- 第 i 位的数字能被 i 整除
-- i 能被第 i 位上的数字整除
-
-现在给定一个整数 N,请问可以构造多少个优美的排列?
-
-
-
-## 解题思路
-
-
-- 这一题是第 46 题的加强版。由于这一题给出的数组里面的数字都是不重复的,所以可以当做第 46 题来做。
-- 这题比第 46 题多的一个条件是,要求数字可以被它对应的下标 + 1 整除,或者下标 + 1 可以整除下标对应的这个数字。在 DFS 回溯过程中加入这个剪枝条件就可以了。
-- 当前做法时间复杂度不是最优的,大概只有 33.3%
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 暴力打表法
-func countArrangement1(N int) int {
- res := []int{0, 1, 2, 3, 8, 10, 36, 41, 132, 250, 700, 750, 4010, 4237, 10680, 24679, 87328, 90478, 435812}
- return res[N]
-}
-
-// 解法二 DFS 回溯
-func countArrangement(N int) int {
- if N == 0 {
- return 0
- }
- nums, used, p, res := make([]int, N), make([]bool, N), []int{}, [][]int{}
- for i := range nums {
- nums[i] = i + 1
- }
- generatePermutation526(nums, 0, p, &res, &used)
- return len(res)
-}
-
-func generatePermutation526(nums []int, index int, p []int, res *[][]int, used *[]bool) {
- if index == len(nums) {
- temp := make([]int, len(p))
- copy(temp, p)
- *res = append(*res, temp)
- return
- }
- for i := 0; i < len(nums); i++ {
- if !(*used)[i] {
- if !(checkDivisible(nums[i], len(p)+1) || checkDivisible(len(p)+1, nums[i])) { // 关键的剪枝条件
- continue
- }
- (*used)[i] = true
- p = append(p, nums[i])
- generatePermutation526(nums, index+1, p, res, used)
- p = p[:len(p)-1]
- (*used)[i] = false
- }
- }
- return
-}
-
-func checkDivisible(num, d int) bool {
- tmp := num / d
- if int(tmp)*int(d) == num {
- return true
- }
- return false
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0528.Random-Pick-with-Weight.md b/website/content/ChapterFour/0528.Random-Pick-with-Weight.md
deleted file mode 100755
index 9e5d63976..000000000
--- a/website/content/ChapterFour/0528.Random-Pick-with-Weight.md
+++ /dev/null
@@ -1,108 +0,0 @@
-# [528. Random Pick with Weight](https://leetcode.com/problems/random-pick-with-weight/)
-
-
-## 题目
-
-Given an array `w` of positive integers, where `w[i]` describes the weight of index `i`, write a function `pickIndex` which randomly picks an index in proportion to its weight.
-
-**Note**:
-
-1. `1 <= w.length <= 10000`
-2. `1 <= w[i] <= 10^5`
-3. `pickIndex` will be called at most `10000` times.
-
-**Example 1**:
-
- Input:
- ["Solution","pickIndex"]
- [[[1]],[]]
- Output: [null,0]
-
-**Example 2**:
-
- Input:
- ["Solution","pickIndex","pickIndex","pickIndex","pickIndex","pickIndex"]
- [[[1,3]],[],[],[],[],[]]
- Output: [null,0,1,1,1,0]
-
-**Explanation of Input Syntax:**
-
-The input is two lists: the subroutines called and their arguments. `Solution`'s constructor has one argument, the array `w`. `pickIndex` has no arguments. Arguments are always wrapped with a list, even if there aren't any.
-
-
-## 题目大意
-
-给定一个正整数数组 w ,其中 w[i] 代表位置 i 的权重,请写一个函数 pickIndex ,它可以随机地获取位置 i,选取位置 i 的概率与 w[i] 成正比。
-
-说明:
-
-1. 1 <= w.length <= 10000
-2. 1 <= w[i] <= 10^5
-3. pickIndex 将被调用不超过 10000 次
-
-
-输入语法说明:
-
-输入是两个列表:调用成员函数名和调用的参数。Solution 的构造函数有一个参数,即数组 w。pickIndex 没有参数。输入参数是一个列表,即使参数为空,也会输入一个 [] 空列表。
-
-
-
-## 解题思路
-
-- 给出一个数组,每个元素值代表该下标的权重值,`pickIndex()` 随机取一个位置 i,这个位置出现的概率和该元素值成正比。
-- 由于涉及到了权重的问题,这一题可以先考虑用前缀和处理权重。在 `[0,prefixSum)` 区间内随机选一个整数 `x`,下标 `i` 是满足 `x< prefixSum[i]` 条件的最小下标,求这个下标 `i` 即是最终解。二分搜索查找下标 `i` 。对于某些下标 `i`,所有满足 `prefixSum[i] - w[i] ≤ v < prefixSum[i]` 的整数 `v` 都映射到这个下标。因此,所有的下标都与下标权重成比例。
-- 时间复杂度:预处理的时间复杂度是 O(n),`pickIndex()` 的时间复杂度是 O(log n)。空间复杂度 O(n)。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math/rand"
-)
-
-// Solution528 define
-type Solution528 struct {
- prefixSum []int
-}
-
-// Constructor528 define
-func Constructor528(w []int) Solution528 {
- prefixSum := make([]int, len(w))
- for i, e := range w {
- if i == 0 {
- prefixSum[i] = e
- continue
- }
- prefixSum[i] = prefixSum[i-1] + e
- }
- return Solution528{prefixSum: prefixSum}
-}
-
-// PickIndex define
-func (so *Solution528) PickIndex() int {
- n := rand.Intn(so.prefixSum[len(so.prefixSum)-1]) + 1
- low, high := 0, len(so.prefixSum)-1
- for low < high {
- mid := low + (high-low)>>1
- if so.prefixSum[mid] == n {
- return mid
- } else if so.prefixSum[mid] < n {
- low = mid + 1
- } else {
- high = mid
- }
- }
- return low
-}
-
-/**
- * Your Solution object will be instantiated and called as such:
- * obj := Constructor(w);
- * param_1 := obj.PickIndex();
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0529.Minesweeper.md b/website/content/ChapterFour/0529.Minesweeper.md
deleted file mode 100644
index f2166a692..000000000
--- a/website/content/ChapterFour/0529.Minesweeper.md
+++ /dev/null
@@ -1,145 +0,0 @@
-# [529. Minesweeper](https://leetcode.com/problems/minesweeper/)
-
-
-
-## 题目
-
-Let's play the minesweeper game ([Wikipedia](https://en.wikipedia.org/wiki/Minesweeper_(video_game)), [online game](http://minesweeperonline.com/))!
-
-You are given a 2D char matrix representing the game board. **'M'** represents an **unrevealed** mine, **'E'** represents an **unrevealed** empty square, **'B'** represents a **revealed** blank square that has no adjacent (above, below, left, right, and all 4 diagonals) mines, **digit** ('1' to '8') represents how many mines are adjacent to this **revealed** square, and finally **'X'** represents a **revealed** mine.
-
-Now given the next click position (row and column indices) among all the **unrevealed** squares ('M' or 'E'), return the board after revealing this position according to the following rules:
-
-1. If a mine ('M') is revealed, then the game is over - change it to **'X'**.
-2. If an empty square ('E') with **no adjacent mines** is revealed, then change it to revealed blank ('B') and all of its adjacent **unrevealed** squares should be revealed recursively.
-3. If an empty square ('E') with **at least one adjacent mine** is revealed, then change it to a digit ('1' to '8') representing the number of adjacent mines.
-4. Return the board when no more squares will be revealed.
-
-**Example 1**:
-
-```
-Input:
-
-[['E', 'E', 'E', 'E', 'E'],
- ['E', 'E', 'M', 'E', 'E'],
- ['E', 'E', 'E', 'E', 'E'],
- ['E', 'E', 'E', 'E', 'E']]
-
-Click : [3,0]
-
-Output:
-
-[['B', '1', 'E', '1', 'B'],
- ['B', '1', 'M', '1', 'B'],
- ['B', '1', '1', '1', 'B'],
- ['B', 'B', 'B', 'B', 'B']]
-
-Explanation:
-```
-
-
-
-**Example 2**:
-
-```
-Input:
-
-[['B', '1', 'E', '1', 'B'],
- ['B', '1', 'M', '1', 'B'],
- ['B', '1', '1', '1', 'B'],
- ['B', 'B', 'B', 'B', 'B']]
-
-Click : [1,2]
-
-Output:
-
-[['B', '1', 'E', '1', 'B'],
- ['B', '1', 'X', '1', 'B'],
- ['B', '1', '1', '1', 'B'],
- ['B', 'B', 'B', 'B', 'B']]
-
-Explanation:
-```
-
-
-
-**Note**:
-
-1. The range of the input matrix's height and width is [1,50].
-2. The click position will only be an unrevealed square ('M' or 'E'), which also means the input board contains at least one clickable square.
-3. The input board won't be a stage when game is over (some mines have been revealed).
-4. For simplicity, not mentioned rules should be ignored in this problem. For example, you **don't** need to reveal all the unrevealed mines when the game is over, consider any cases that you will win the game or flag any squares.
-
-
-## 题目大意
-
-给定一个代表游戏板的二维字符矩阵。 'M' 代表一个未挖出的地雷,'E' 代表一个未挖出的空方块,'B' 代表没有相邻(上,下,左,右,和所有4个对角线)地雷的已挖出的空白方块,数字('1' 到 '8')表示有多少地雷与这块已挖出的方块相邻,'X' 则表示一个已挖出的地雷。现在给出在所有未挖出的方块中('M'或者'E')的下一个点击位置(行和列索引),根据以下规则,返回相应位置被点击后对应的面板:
-
-1. 如果一个地雷('M')被挖出,游戏就结束了- 把它改为 'X'。
-2. 如果一个没有相邻地雷的空方块('E')被挖出,修改它为('B'),并且所有和其相邻的未挖出方块都应该被递归地揭露。
-3. 如果一个至少与一个地雷相邻的空方块('E')被挖出,修改它为数字('1'到'8'),表示相邻地雷的数量。
-4. 如果在此次点击中,若无更多方块可被揭露,则返回面板。
-
-
-注意:
-
-- 输入矩阵的宽和高的范围为 [1,50]。
-- 点击的位置只能是未被挖出的方块 ('M' 或者 'E'),这也意味着面板至少包含一个可点击的方块。
-- 输入面板不会是游戏结束的状态(即有地雷已被挖出)。
-- 简单起见,未提及的规则在这个问题中可被忽略。例如,当游戏结束时你不需要挖出所有地雷,考虑所有你可能赢得游戏或标记方块的情况。
-
-
-
-## 解题思路
-
-- 给出一张扫雷地图和点击的坐标,M 代表雷,E 代表还没有点击过的空砖块,B 代表点击过的空砖块,1-8 代表砖块周围 8 个方块里面有雷的个数,X 代表点到了雷。问点击一次以后,输出更新点击以后的地图。
-- DPS 和 BFS 都可以解题。先根据原图预处理地图,记录出最终地图的状态,0 代表空白砖块,1-8 代表雷的个数,-1 代表是雷。再 DFS 遍历这张处理后的图,输出最终的地图即可。
-
-## 代码
-
-```go
-func updateBoard(board [][]byte, click []int) [][]byte {
- if board[click[0]][click[1]] == 'M' {
- board[click[0]][click[1]] = 'X'
- return board
- }
- mineMap := make([][]int, len(board))
- for i := range board {
- mineMap[i] = make([]int, len(board[i]))
- }
- for i := range board {
- for j := range board[i] {
- if board[i][j] == 'M' {
- mineMap[i][j] = -1
- for _, d := range dir8 {
- nx, ny := i+d[0], j+d[1]
- if isInBoard(board, nx, ny) && mineMap[nx][ny] >= 0 {
- mineMap[nx][ny]++
- }
- }
- }
- }
- }
- mineSweeper(click[0], click[1], board, mineMap, dir8)
- return board
-}
-
-func mineSweeper(x, y int, board [][]byte, mineMap [][]int, dir8 [][]int) {
- if board[x][y] != 'M' && board[x][y] != 'E' {
- return
- }
- if mineMap[x][y] == -1 {
- board[x][y] = 'X'
- } else if mineMap[x][y] > 0 {
- board[x][y] = '0' + byte(mineMap[x][y])
- } else {
- board[x][y] = 'B'
- for _, d := range dir8 {
- nx, ny := x+d[0], y+d[1]
- if isInBoard(board, nx, ny) && mineMap[nx][ny] >= 0 {
- mineSweeper(nx, ny, board, mineMap, dir8)
- }
- }
- }
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0532.K-diff-Pairs-in-an-Array.md b/website/content/ChapterFour/0532.K-diff-Pairs-in-an-Array.md
deleted file mode 100644
index 20aa28893..000000000
--- a/website/content/ChapterFour/0532.K-diff-Pairs-in-an-Array.md
+++ /dev/null
@@ -1,95 +0,0 @@
-# [532. K-diff Pairs in an Array](https://leetcode.com/problems/k-diff-pairs-in-an-array/)
-
-## 题目
-
-Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in the array and their absolute difference is k.
-
-
-**Example 1**:
-
-```
-
-Input: [3, 1, 4, 1, 5], k = 2
-Output: 2
-Explanation: There are two 2-diff pairs in the array, (1, 3) and (3, 5).
-Although we have two 1s in the input, we should only return the number of unique pairs.
-
-```
-
-**Example 2**:
-
-```
-
-Input:[1, 2, 3, 4, 5], k = 1
-Output: 4
-Explanation: There are four 1-diff pairs in the array, (1, 2), (2, 3), (3, 4) and (4, 5).
-
-```
-
-**Example 3**:
-
-```
-
-Input: [1, 3, 1, 5, 4], k = 0
-Output: 1
-Explanation: There is one 0-diff pair in the array, (1, 1).
-
-```
-
-
-**Note**:
-
-1. The pairs (i, j) and (j, i) count as the same pair.
-2. The length of the array won't exceed 10,000.
-3. All the integers in the given input belong to the range: [-1e7, 1e7].
-
-## 题目大意
-
-
-给定一个数组,在数组里面找到几组不同的 pair 对,每个 pair 对相差 K 。问能找出多少组这样的 pair 对。
-
-
-## 解题思路
-
-这一题可以用 map 记录每个数字出现的次数。重复的数字也会因为唯一的 key,不用担心某个数字会判断多次。遍历一次 map,每个数字都加上 K 以后,判断字典里面是否存在,如果存在, count ++,如果 K = 0 的情况需要单独判断,如果字典中这个元素频次大于 1,count 也需要 ++。
-
-
-
-
-
-
-
-
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func findPairs(nums []int, k int) int {
- if k < 0 || len(nums) == 0 {
- return 0
- }
- var count int
- m := make(map[int]int, len(nums))
- for _, value := range nums {
- m[value]++
- }
- for key := range m {
- if k == 0 && m[key] > 1 {
- count++
- continue
- }
- if k > 0 && m[key+k] > 0 {
- count++
- }
- }
- return count
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0537.Complex-Number-Multiplication.md b/website/content/ChapterFour/0537.Complex-Number-Multiplication.md
deleted file mode 100644
index 568404bab..000000000
--- a/website/content/ChapterFour/0537.Complex-Number-Multiplication.md
+++ /dev/null
@@ -1,73 +0,0 @@
-# [537. Complex Number Multiplication](https://leetcode.com/problems/complex-number-multiplication/)
-
-
-## 题目
-
-Given two strings representing two [complex numbers](https://en.wikipedia.org/wiki/Complex_number).
-
-You need to return a string representing their multiplication. Note i2 = -1 according to the definition.
-
-**Example 1**:
-
-```
-Input: "1+1i", "1+1i"
-Output: "0+2i"
-Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.
-```
-
-**Example 2**:
-
-```
-Input: "1+-1i", "1+-1i"
-Output: "0+-2i"
-Explanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.
-```
-
-**Note**:
-
-1. The input strings will not have extra blank.
-2. The input strings will be given in the form of **a+bi**, where the integer **a** and **b** will both belong to the range of [-100, 100]. And **the output should be also in this form**.
-
-## 题目大意
-
-给定两个表示复数的字符串。返回表示它们乘积的字符串。注意,根据定义 i^2 = -1 。
-
-注意:
-
-- 输入字符串不包含额外的空格。
-- 输入字符串将以 a+bi 的形式给出,其中整数 a 和 b 的范围均在 [-100, 100] 之间。输出也应当符合这种形式。
-
-
-
-## 解题思路
-
-- 给定 2 个字符串,要求这两个复数的乘积,输出也是字符串格式。
-- 数学题。按照复数的运算法则,i^2 = -1,最后输出字符串结果即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "strconv"
- "strings"
-)
-
-func complexNumberMultiply(a string, b string) string {
- realA, imagA := parse(a)
- realB, imagB := parse(b)
- real := realA*realB - imagA*imagB
- imag := realA*imagB + realB*imagA
- return strconv.Itoa(real) + "+" + strconv.Itoa(imag) + "i"
-}
-
-func parse(s string) (int, int) {
- ss := strings.Split(s, "+")
- r, _ := strconv.Atoi(ss[0])
- i, _ := strconv.Atoi(ss[1][:len(ss[1])-1])
- return r, i
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0541.Reverse-String-II.md b/website/content/ChapterFour/0541.Reverse-String-II.md
deleted file mode 100755
index 8d9ebdafb..000000000
--- a/website/content/ChapterFour/0541.Reverse-String-II.md
+++ /dev/null
@@ -1,56 +0,0 @@
-# [541. Reverse String II](https://leetcode.com/problems/reverse-string-ii/)
-
-
-## 题目
-
-Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the other as original.
-
-**Example**:
-
- Input: s = "abcdefg", k = 2
- Output: "bacdfeg"
-
-**Restrictions:**
-
-1. The string consists of lower English letters only.
-2. Length of the given string and k will in the range [1, 10000]
-
-## 题目大意
-
-给定一个字符串和一个整数 k,你需要对从字符串开头算起的每个 2k 个字符的前k个字符进行反转。如果剩余少于 k 个字符,则将剩余的所有全部反转。如果有小于 2k 但大于或等于 k 个字符,则反转前 k 个字符,并将剩余的字符保持原样。
-
-要求:
-
-- 该字符串只包含小写的英文字母。
-- 给定字符串的长度和 k 在[1, 10000]范围内。
-
-
-## 解题思路
-
-- 要求按照一定规则反转字符串:每 `2 * K` 长度的字符串,反转前 `K` 个字符,后 `K` 个字符串保持不变;对于末尾不够 `2 * K` 的字符串,如果长度大于 `K`,那么反转前 `K` 个字符串,剩下的保持不变。如果长度小于 `K`,则把小于 `K` 的这部分字符串全部反转。
-- 这一题是简单题,按照题意反转字符串即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func reverseStr(s string, k int) string {
- if k > len(s) {
- k = len(s)
- }
- for i := 0; i < len(s); i = i + 2*k {
- if len(s)-i >= k {
- ss := revers(s[i : i+k])
- s = s[:i] + ss + s[i+k:]
- } else {
- ss := revers(s[i:])
- s = s[:i] + ss
- }
- }
- return s
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0542.01-Matrix.md b/website/content/ChapterFour/0542.01-Matrix.md
deleted file mode 100755
index deb16e4c7..000000000
--- a/website/content/ChapterFour/0542.01-Matrix.md
+++ /dev/null
@@ -1,202 +0,0 @@
-# [542. 01 Matrix](https://leetcode.com/problems/01-matrix/)
-
-
-## 题目
-
-Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.
-
-The distance between two adjacent cells is 1.
-
-**Example 1**:
-
- Input:
- [[0,0,0],
- [0,1,0],
- [0,0,0]]
-
- Output:
- [[0,0,0],
- [0,1,0],
- [0,0,0]]
-
-**Example 2**:
-
- Input:
- [[0,0,0],
- [0,1,0],
- [1,1,1]]
-
- Output:
- [[0,0,0],
- [0,1,0],
- [1,2,1]]
-
-**Note**:
-
-1. The number of elements of the given matrix will not exceed 10,000.
-2. There are at least one 0 in the given matrix.
-3. The cells are adjacent in only four directions: up, down, left and right.
-
-
-## 题目大意
-
-给定一个由 0 和 1 组成的矩阵,找出每个元素到最近的 0 的距离。两个相邻元素间的距离为 1 。
-
-
-## 解题思路
-
-
-- 给出一个二维数组,数组里面只有 0 和 1 。要求计算每个 1 距离最近的 0 的距离。
-- 这一题有 3 种解法,第一种解法最容易想到,BFS。先预处理一下棋盘,将每个 0 都处理为 -1 。将 1 都处理为 0 。将每个 -1 (即原棋盘的 0)都入队,每次出队都将四周的 4 个位置都入队。这就想一颗石头扔进了湖里,一圈一圈的波纹荡开,每一圈都是一层。由于棋盘被我们初始化了,所有为 -1 的都是原来为 0 的,所以波纹扫过来不需要处理这些 -1 的点。棋盘上为 0 的点都是原来为 1 的点,这些点在波纹扫过来的时候就需要赋值更新 level。当下次波纹再次扫到原来为 1 的点的时候,由于它已经被第一次到的波纹更新了值,所以这次不用再更新了。(第一次波纹到的时候一定是最短的)
-- 第二种解法是 DFS。先预处理,把周围没有 0 的 1 都重置为最大值。当周围有 0 的 1,距离 0 的位置都是 1,这些点是不需要动的,需要更新的点恰恰应该是那些周围没有 0 的点。当递归的步数 val 比点的值小(这也就是为什么会先把 1 更新成最大值的原因)的时候,不断更新它。
-- 第三种解法是 DP。由于有 4 个方向,每次处理 2 个方向,可以降低时间复杂度。第一次循环从上到下,从左到右遍历,先处理上边和左边,第二次循环从下到上,从右到左遍历,再处理右边和下边。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
-)
-
-// 解法一 BFS
-func updateMatrixBFS(matrix [][]int) [][]int {
- res := make([][]int, len(matrix))
- if len(matrix) == 0 || len(matrix[0]) == 0 {
- return res
- }
- queue := make([][]int, 0)
- for i := range matrix {
- res[i] = make([]int, len(matrix[0]))
- for j := range res[i] {
- if matrix[i][j] == 0 {
- res[i][j] = -1
- queue = append(queue, []int{i, j})
- }
- }
- }
- level := 1
- for len(queue) > 0 {
- size := len(queue)
- for size > 0 {
- size--
- node := queue[0]
- queue = queue[1:]
- i, j := node[0], node[1]
- for _, direction := range [][]int{{-1, 0}, {1, 0}, {0, 1}, {0, -1}} {
- x := i + direction[0]
- y := j + direction[1]
- if x < 0 || x >= len(matrix) || y < 0 || y >= len(matrix[0]) || res[x][y] < 0 || res[x][y] > 0 {
- continue
- }
- res[x][y] = level
- queue = append(queue, []int{x, y})
- }
- }
- level++
- }
- for i, row := range res {
- for j, cell := range row {
- if cell == -1 {
- res[i][j] = 0
- }
- }
- }
- return res
-}
-
-// 解法二 DFS
-func updateMatrixDFS(matrix [][]int) [][]int {
- result := [][]int{}
- if len(matrix) == 0 || len(matrix[0]) == 0 {
- return result
- }
- maxRow, maxCol := len(matrix), len(matrix[0])
- for r := 0; r < maxRow; r++ {
- for c := 0; c < maxCol; c++ {
- if matrix[r][c] == 1 && hasZero(matrix, r, c) == false {
- // 将四周没有 0 的 1 特殊处理为最大值
- matrix[r][c] = math.MaxInt64
- }
- }
- }
- for r := 0; r < maxRow; r++ {
- for c := 0; c < maxCol; c++ {
- if matrix[r][c] == 1 {
- dfsMatrix(matrix, r, c, -1)
- }
- }
- }
- return (matrix)
-}
-
-// 判断四周是否有 0
-func hasZero(matrix [][]int, row, col int) bool {
- if row > 0 && matrix[row-1][col] == 0 {
- return true
- }
- if col > 0 && matrix[row][col-1] == 0 {
- return true
- }
- if row < len(matrix)-1 && matrix[row+1][col] == 0 {
- return true
- }
- if col < len(matrix[0])-1 && matrix[row][col+1] == 0 {
- return true
- }
- return false
-}
-
-func dfsMatrix(matrix [][]int, row, col, val int) {
- // 不超过棋盘氛围,且 val 要比 matrix[row][col] 小
- if row < 0 || row >= len(matrix) || col < 0 || col >= len(matrix[0]) || (matrix[row][col] <= val) {
- return
- }
- if val > 0 {
- matrix[row][col] = val
- }
- dfsMatrix(matrix, row-1, col, matrix[row][col]+1)
- dfsMatrix(matrix, row, col-1, matrix[row][col]+1)
- dfsMatrix(matrix, row+1, col, matrix[row][col]+1)
- dfsMatrix(matrix, row, col+1, matrix[row][col]+1)
-}
-
-// 解法三 DP
-func updateMatrixDP(matrix [][]int) [][]int {
- for i, row := range matrix {
- for j, val := range row {
- if val == 0 {
- continue
- }
- left, top := math.MaxInt16, math.MaxInt16
- if i > 0 {
- top = matrix[i-1][j] + 1
- }
- if j > 0 {
- left = matrix[i][j-1] + 1
- }
- matrix[i][j] = min(top, left)
- }
- }
- for i := len(matrix) - 1; i >= 0; i-- {
- for j := len(matrix[0]) - 1; j >= 0; j-- {
- if matrix[i][j] == 0 {
- continue
- }
- right, bottom := math.MaxInt16, math.MaxInt16
- if i < len(matrix)-1 {
- bottom = matrix[i+1][j] + 1
- }
- if j < len(matrix[0])-1 {
- right = matrix[i][j+1] + 1
- }
- matrix[i][j] = min(matrix[i][j], min(bottom, right))
- }
- }
- return matrix
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0547.Friend-Circles.md b/website/content/ChapterFour/0547.Friend-Circles.md
deleted file mode 100755
index a55972974..000000000
--- a/website/content/ChapterFour/0547.Friend-Circles.md
+++ /dev/null
@@ -1,111 +0,0 @@
-# [547. Friend Circles](https://leetcode.com/problems/friend-circles/)
-
-## 题目
-
-There are **N** students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a **direct** friend of B, and B is a **direct**friend of C, then A is an **indirect** friend of C. And we defined a friend circle is a group of students who are direct or indirect friends.
-
-Given a **N*N** matrix **M** representing the friend relationship between students in the class. If M[i][j] = 1, then the ith and jth students are **direct** friends with each other, otherwise not. And you have to output the total number of friend circles among all the students.
-
-**Example 1**:
-
- Input:
- [[1,1,0],
- [1,1,0],
- [0,0,1]]
- Output: 2
- Explanation:The 0th and 1st students are direct friends, so they are in a friend circle.
- The 2nd student himself is in a friend circle. So return 2.
-
-**Example 2**:
-
- Input:
- [[1,1,0],
- [1,1,1],
- [0,1,1]]
- Output: 1
- Explanation:The 0th and 1st students are direct friends, the 1st and 2nd students are direct friends,
- so the 0th and 2nd students are indirect friends. All of them are in the same friend circle, so return 1.
-
-**Note**:
-
-1. N is in range [1,200].
-2. M[i][i] = 1 for all students.
-3. If M[i][j] = 1, then M[j][i] = 1.
-
-
-## 题目大意
-
-班上有 N 名学生。其中有些人是朋友,有些则不是。他们的友谊具有是传递性。如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友。所谓的朋友圈,是指所有朋友的集合。
-
-给定一个 N * N 的矩阵 M,表示班级中学生之间的朋友关系。如果 M[i][j] = 1,表示已知第 i 个和 j 个学生互为朋友关系,否则为不知道。你必须输出所有学生中的已知的朋友圈总数。
-
-
-注意:
-
-- N 在[1,200]的范围内。
-- 对于所有学生,有M[i][i] = 1。
-- 如果有 M[i][j] = 1,则有 M[j][i] = 1。
-
-
-## 解题思路
-
-
-- 给出一个二维矩阵,矩阵中的行列表示的是两个人之间是否是朋友关系,如果是 1,代表两个人是朋友关系。由于自己和自肯定朋友关系,所以对角线上都是 1,并且矩阵也是关于从左往右下的这条对角线对称。
-- 这题有 2 种解法,第一种解法是并查集,依次扫描矩阵,如果两个人认识,并且 root 并不相等就执行 union 操作。扫完所有矩阵,最后数一下还有几个不同的 root 就是最终答案。第二种解法是 DFS 或者 BFS。利用 FloodFill 的想法去染色,每次染色一次,计数器加一。最终扫完整个矩阵,计数器的结果就是最终结果。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-// 解法一 并查集
-
-func findCircleNum(M [][]int) int {
- n := len(M)
- if n == 0 {
- return 0
- }
- uf := template.UnionFind{}
- uf.Init(n)
- for i := 0; i < n; i++ {
- for j := 0; j <= i; j++ {
- if M[i][j] == 1 {
- uf.Union(i, j)
- }
- }
- }
- return uf.TotalCount()
-}
-
-// 解法二 FloodFill DFS 暴力解法
-func findCircleNum1(M [][]int) int {
- if len(M) == 0 {
- return 0
- }
- visited := make([]bool, len(M))
- res := 0
- for i := range M {
- if !visited[i] {
- dfs547(M, i, visited)
- res++
- }
- }
- return res
-}
-
-func dfs547(M [][]int, cur int, visited []bool) {
- visited[cur] = true
- for j := 0; j < len(M[cur]); j++ {
- if !visited[j] && M[cur][j] == 1 {
- dfs547(M, j, visited)
- }
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0557.Reverse-Words-in-a-String-III.md b/website/content/ChapterFour/0557.Reverse-Words-in-a-String-III.md
deleted file mode 100755
index 68363ed8d..000000000
--- a/website/content/ChapterFour/0557.Reverse-Words-in-a-String-III.md
+++ /dev/null
@@ -1,57 +0,0 @@
-# [557. Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii/)
-
-
-## 题目
-
-Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
-
-**Example 1**:
-
- Input: "Let's take LeetCode contest"
- Output: "s'teL ekat edoCteeL tsetnoc"
-
-**Note**: In the string, each word is separated by single space and there will not be any extra space in the string.
-
-
-## 题目大意
-
-给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。注意:在字符串中,每个单词由单个空格分隔,并且字符串中不会有任何额外的空格。
-
-
-## 解题思路
-
-
-- 反转字符串,要求按照空格隔开的小字符串为单位反转。
-- 这是一道简单题。按照题意反转每个空格隔开的单词即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "strings"
-)
-
-func reverseWords(s string) string {
- ss := strings.Split(s, " ")
- for i, s := range ss {
- ss[i] = revers(s)
- }
- return strings.Join(ss, " ")
-}
-
-func revers(s string) string {
- bytes := []byte(s)
- i, j := 0, len(bytes)-1
- for i < j {
- bytes[i], bytes[j] = bytes[j], bytes[i]
- i++
- j--
- }
- return string(bytes)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0561.Array-Partition-I.md b/website/content/ChapterFour/0561.Array-Partition-I.md
deleted file mode 100644
index d72ea633d..000000000
--- a/website/content/ChapterFour/0561.Array-Partition-I.md
+++ /dev/null
@@ -1,58 +0,0 @@
-# [561. Array Partition I](https://leetcode.com/problems/array-partition-i/)
-
-
-## 题目
-
-Given an array of **2n** integers, your task is to group these integers into **n** pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible.
-
-**Example 1**:
-
-```
-Input: [1,4,3,2]
-
-Output: 4
-Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).
-```
-
-**Note**:
-
-1. **n** is a positive integer, which is in the range of [1, 10000].
-2. All the integers in the array will be in the range of [-10000, 10000].
-
-## 题目大意
-
-给定长度为 2n 的数组, 你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), ..., (an, bn) ,使得从1 到 n 的 min(ai, bi) 总和最大。
-
-
-## 解题思路
-
-- 给定一个 2n 个数组,要求把它们分为 n 组一行,求出各组最小值的总和的最大值。
-- 由于题目给的数据范围不大,[-10000, 10000],所以我们可以考虑用一个哈希表数组,里面存储 i - 10000 元素的频次,偏移量是 10000。这个哈希表能按递增的顺序访问数组,这样可以减少排序的耗时。题目要求求出分组以后求和的最大值,那么所有偏小的元素尽量都安排在一组里面,这样取 min 以后,对最大和影响不大。例如,(1 , 1) 这样安排在一起,min 以后就是 1 。但是如果把相差很大的两个元素安排到一起,那么较大的那个元素就“牺牲”了。例如,(1 , 10000),取 min 以后就是 1,于是 10000 就“牺牲”了。所以需要优先考虑较小值。
-- 较小值出现的频次可能是奇数也可能是偶数。如果是偶数,那比较简单,把它们俩俩安排在一起就可以了。如果是奇数,那么它会落单一次,落单的那个需要和距离它最近的一个元素进行配对,这样对最终的和影响最小。较小值如果是奇数,那么就会影响后面元素的选择,后面元素如果是偶数,由于需要一个元素和前面的较小值配对,所以它剩下的又是奇数个。这个影响会依次传递到后面。所以用一个 flag 标记,如果当前集合中有剩余元素将被再次考虑,则此标志设置为 1。在从下一组中选择元素时,会考虑已考虑的相同额外元素。
-- 最后扫描过程中动态的维护 sum 值就可以了。
-
-## 代码
-
-```go
-
-package leetcode
-
-func arrayPairSum(nums []int) int {
- array := [20001]int{}
- for i := 0; i < len(nums); i++ {
- array[nums[i]+10000]++
- }
- flag, sum := true, 0
- for i := 0; i < len(array); i++ {
- for array[i] > 0 {
- if flag {
- sum = sum + i - 10000
- }
- flag = !flag
- array[i]--
- }
- }
- return sum
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0563.Binary-Tree-Tilt.md b/website/content/ChapterFour/0563.Binary-Tree-Tilt.md
deleted file mode 100755
index b5a8ce5cf..000000000
--- a/website/content/ChapterFour/0563.Binary-Tree-Tilt.md
+++ /dev/null
@@ -1,83 +0,0 @@
-# [563. Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt/)
-
-
-## 题目
-
-Given a binary tree, return the tilt of the **whole tree**.
-
-The tilt of a **tree node** is defined as the **absolute difference** between the sum of all left subtree node values and the sum of all right subtree node values. Null node has tilt 0.
-
-The tilt of the **whole tree** is defined as the sum of all nodes' tilt.
-
-**Example**:
-
- Input:
- 1
- / \
- 2 3
- Output: 1
- Explanation:
- Tilt of node 2 : 0
- Tilt of node 3 : 0
- Tilt of node 1 : |2-3| = 1
- Tilt of binary tree : 0 + 0 + 1 = 1
-
-**Note**:
-
-1. The sum of node values in any subtree won't exceed the range of 32-bit integer.
-2. All the tilt values won't exceed the range of 32-bit integer.
-
-
-## 题目大意
-
-
-给定一个二叉树,计算整个树的坡度。一个树的节点的坡度定义即为,该节点左子树的结点之和和右子树结点之和的差的绝对值。空结点的的坡度是0。整个树的坡度就是其所有节点的坡度之和。
-
-注意:
-
-1. 任何子树的结点的和不会超过32位整数的范围。
-2. 坡度的值不会超过32位整数的范围。
-
-## 解题思路
-
-
-- 给出一棵树,计算每个节点的“倾斜度”累加和。“倾斜度”的定义是:左子树和右子树的节点值差值的绝对值。
-- 这一题虽然是简单题,但是如果对题目中的“倾斜度”理解的不对,这一题就会出错。“倾斜度”计算的是左子树所有节点的值总和,和,右子树所有节点的值总和的差值。并不是只针对一个节点的左节点值和右节点值的差值。这一点明白以后,这一题就是简单题了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math"
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-func findTilt(root *TreeNode) int {
- if root == nil {
- return 0
- }
- sum := 0
- findTiltDFS(root, &sum)
- return sum
-}
-
-func findTiltDFS(root *TreeNode, sum *int) int {
- if root == nil {
- return 0
- }
- left := findTiltDFS(root.Left, sum)
- right := findTiltDFS(root.Right, sum)
- *sum += int(math.Abs(float64(left) - float64(right)))
- return root.Val + left + right
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0566.Reshape-the-Matrix.md b/website/content/ChapterFour/0566.Reshape-the-Matrix.md
deleted file mode 100755
index a55a7028c..000000000
--- a/website/content/ChapterFour/0566.Reshape-the-Matrix.md
+++ /dev/null
@@ -1,102 +0,0 @@
-# [566. Reshape the Matrix](https://leetcode.com/problems/reshape-the-matrix/)
-
-
-## 题目
-
-In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.
-
-You're given a matrix represented by a two-dimensional array, and two **positive** integers **r** and **c**representing the **row** number and **column** number of the wanted reshaped matrix, respectively.
-
-The reshaped matrix need to be filled with all the elements of the original matrix in the same **row-traversing** order as they were.
-
-If the 'reshape' operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.
-
-**Example 1**:
-
- Input:
- nums =
- [[1,2],
- [3,4]]
- r = 1, c = 4
- Output:
- [[1,2,3,4]]
- Explanation:
- The row-traversing of nums is [1,2,3,4]. The new reshaped matrix is a 1 * 4 matrix, fill it row by row by using the previous list.
-
-**Example 2**:
-
- Input:
- nums =
- [[1,2],
- [3,4]]
- r = 2, c = 4
- Output:
- [[1,2],
- [3,4]]
- Explanation:
- There is no way to reshape a 2 * 2 matrix to a 2 * 4 matrix. So output the original matrix.
-
-**Note**:
-
-1. The height and width of the given matrix is in range [1, 100].
-2. The given r and c are all positive.
-
-
-## 题目大意
-
-在 MATLAB 中,有一个非常有用的函数 reshape,它可以将一个矩阵重塑为另一个大小不同的新矩阵,但保留其原始数据。
-
-给出一个由二维数组表示的矩阵,以及两个正整数r和c,分别表示想要的重构的矩阵的行数和列数。重构后的矩阵需要将原始矩阵的所有元素以相同的行遍历顺序填充。如果具有给定参数的reshape操作是可行且合理的,则输出新的重塑矩阵;否则,输出原始矩阵。
-
-
-
-## 解题思路
-
-
-- 给一个二维数组和 r,c,将这个二维数组“重塑”成行为 r,列为 c。如果可以“重塑”,输出“重塑”以后的数组,如果不能“重塑”,输出原有数组。
-- 这题也是水题,按照题意模拟即可。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func matrixReshape(nums [][]int, r int, c int) [][]int {
- if canReshape(nums, r, c) {
- return reshape(nums, r, c)
- }
- return nums
-}
-
-func canReshape(nums [][]int, r, c int) bool {
- row := len(nums)
- colume := len(nums[0])
- if row*colume == r*c {
- return true
- }
- return false
-}
-
-func reshape(nums [][]int, r, c int) [][]int {
- newShape := make([][]int, r)
- for index := range newShape {
- newShape[index] = make([]int, c)
- }
- rowIndex, colIndex := 0, 0
- for _, row := range nums {
- for _, col := range row {
- if colIndex == c {
- colIndex = 0
- rowIndex++
- }
- newShape[rowIndex][colIndex] = col
- colIndex++
- }
- }
- return newShape
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0567.Permutation-in-String.md b/website/content/ChapterFour/0567.Permutation-in-String.md
deleted file mode 100644
index e2e9d17ad..000000000
--- a/website/content/ChapterFour/0567.Permutation-in-String.md
+++ /dev/null
@@ -1,87 +0,0 @@
-# [567. Permutation in String](https://leetcode.com/problems/permutation-in-string/)
-
-## 题目
-
-Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string.
-
-
-**Example 1**:
-
-```
-
-Input:s1 = "ab" s2 = "eidbaooo"
-Output:True
-Explanation: s2 contains one permutation of s1 ("ba").
-
-```
-
-**Example 2**:
-
-```
-
-Input:s1= "ab" s2 = "eidboaoo"
-Output: False
-
-```
-
-**Note**:
-
-1. The input strings only contain lower case letters.
-2. The length of both given strings is in range [1, 10,000].
-
-## 题目大意
-
-
-在一个字符串重寻找子串出现的位置。子串可以是 Anagrams 形式存在的。Anagrams 是一个字符串任意字符的全排列组合。
-
-## 解题思路
-
-这一题和第 438 题,第 3 题,第 76 题,第 567 题类似,用的思想都是"滑动窗口"。
-
-
-这道题只需要判断是否存在,而不需要输出子串所在的下标起始位置。所以这道题是第 438 题的缩水版。具体解题思路见第 438 题。
-
-
-
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func checkInclusion(s1 string, s2 string) bool {
- var freq [256]int
- if len(s2) == 0 || len(s2) < len(s1) {
- return false
- }
- for i := 0; i < len(s1); i++ {
- freq[s1[i]-'a']++
- }
- left, right, count := 0, 0, len(s1)
-
- for right < len(s2) {
- if freq[s2[right]-'a'] >= 1 {
- count--
- }
- freq[s2[right]-'a']--
- right++
- if count == 0 {
- return true
- }
- if right-left == len(s1) {
- if freq[s2[left]-'a'] >= 0 {
- count++
- }
- freq[s2[left]-'a']++
- left++
- }
- }
- return false
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0572.Subtree-of-Another-Tree.md b/website/content/ChapterFour/0572.Subtree-of-Another-Tree.md
deleted file mode 100755
index 21611c120..000000000
--- a/website/content/ChapterFour/0572.Subtree-of-Another-Tree.md
+++ /dev/null
@@ -1,87 +0,0 @@
-# [572. Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/)
-
-
-## 题目
-
-Given two non-empty binary trees **s** and **t**, check whether tree **t** has exactly the same structure and node values with a subtree of **s**. A subtree of **s** is a tree consists of a node in **s** and all of this node's descendants. The tree **s** could also be considered as a subtree of itself.
-
-**Example 1**:
-
-Given tree s:
-
- 3
- / \
- 4 5
- / \
- 1 2
-
-Given tree t:
-
- 4
- / \
- 1 2
-
-Return **true**, because t has the same structure and node values with a subtree of s.
-
-**Example 2**:
-
-Given tree s:
-
- 3
- / \
- 4 5
- / \
- 1 2
- /
- 0
-
-Given tree t:
-
- 4
- / \
- 1 2
-
-Return **false**.
-
-
-## 题目大意
-
-给定两个非空二叉树 s 和 t,检验 s 中是否包含和 t 具有相同结构和节点值的子树。s 的一个子树包括 s 的一个节点和这个节点的所有子孙。s 也可以看做它自身的一棵子树。
-
-
-## 解题思路
-
-
-- 给出 2 棵树 `s` 和 `t`,要求判断 `t` 是否是 `s` 的子树🌲。
-- 这一题比较简单,针对 3 种情况依次递归判断,第一种情况 `s` 和 `t` 是完全一样的两棵树,第二种情况 `t` 是 `s` 左子树中的子树,第三种情况 `t` 是 `s` 右子树中的子树。第一种情况判断两棵数是否完全一致是第 100 题的原题。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-func isSubtree(s *TreeNode, t *TreeNode) bool {
- if isSameTree(s, t) {
- return true
- }
- if s == nil {
- return false
- }
- if isSubtree(s.Left, t) || isSubtree(s.Right, t) {
- return true
- }
- return false
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0575.Distribute-Candies.md b/website/content/ChapterFour/0575.Distribute-Candies.md
deleted file mode 100755
index 4e3299366..000000000
--- a/website/content/ChapterFour/0575.Distribute-Candies.md
+++ /dev/null
@@ -1,59 +0,0 @@
-# [575. Distribute Candies](https://leetcode.com/problems/distribute-candies/)
-
-
-## 题目
-
-Given an integer array with **even** length, where different numbers in this array represent different **kinds** of candies. Each number means one candy of the corresponding kind. You need to distribute these candies **equally** in number to brother and sister. Return the maximum number of **kinds** of candies the sister could gain.
-
-**Example 1**:
-
- Input: candies = [1,1,2,2,3,3]
- Output: 3
- Explanation:
- There are three different kinds of candies (1, 2 and 3), and two candies for each kind.
- Optimal distribution: The sister has candies [1,2,3] and the brother has candies [1,2,3], too.
- The sister has three different kinds of candies.
-
-**Example 2**:
-
- Input: candies = [1,1,2,3]
- Output: 2
- Explanation: For example, the sister has candies [2,3] and the brother has candies [1,1].
- The sister has two different kinds of candies, the brother has only one kind of candies.
-
-**Note**:
-
-1. The length of the given array is in range [2, 10,000], and will be even.
-2. The number in given array is in range [-100,000, 100,000].
-
-
-## 题目大意
-
-给定一个偶数长度的数组,其中不同的数字代表着不同种类的糖果,每一个数字代表一个糖果。你需要把这些糖果平均分给一个弟弟和一个妹妹。返回妹妹可以获得的最大糖果的种类数。
-
-
-## 解题思路
-
-
-- 给出一个糖果数组,里面每个元素代表糖果的种类,相同数字代表相同种类。把这些糖果分给兄弟姐妹,问姐妹最多可以分到多少种糖果。这一题比较简单,用 map 统计每个糖果的出现频次,如果总数比 `n/2` 小,那么就返回 `len(map)`,否则返回 `n/2` (即一半都分给姐妹)。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func distributeCandies(candies []int) int {
- n, m := len(candies), make(map[int]struct{}, len(candies))
- for _, candy := range candies {
- m[candy] = struct{}{}
- }
- res := len(m)
- if n/2 < res {
- return n / 2
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0594.Longest-Harmonious-Subsequence.md b/website/content/ChapterFour/0594.Longest-Harmonious-Subsequence.md
deleted file mode 100755
index 380ad65ae..000000000
--- a/website/content/ChapterFour/0594.Longest-Harmonious-Subsequence.md
+++ /dev/null
@@ -1,57 +0,0 @@
-# [594. Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence/)
-
-
-## 题目
-
-We define a harmounious array as an array where the difference between its maximum value and its minimum value is **exactly** 1.
-
-Now, given an integer array, you need to find the length of its longest harmonious subsequence among all its possible [subsequences](https://en.wikipedia.org/wiki/Subsequence).
-
-**Example 1**:
-
- Input: [1,3,2,2,5,2,3,7]
- Output: 5
- Explanation: The longest harmonious subsequence is [3,2,2,2,3].
-
-**Note**: The length of the input array will not exceed 20,000.
-
-
-## 题目大意
-
-和谐数组是指一个数组里元素的最大值和最小值之间的差别正好是1。现在,给定一个整数数组,你需要在所有可能的子序列中找到最长的和谐子序列的长度。说明: 输入的数组长度最大不超过20,000.
-
-## 解题思路
-
-- 在给出的数组里面找到这样一个子数组:要求子数组中的最大值和最小值相差 1 。这一题是简单题。先统计每个数字出现的频次,然后在 map 找相差 1 的 2 个数组的频次和,动态的维护两个数的频次和就是最后要求的子数组的最大长度。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func findLHS(nums []int) int {
- if len(nums) < 2 {
- return 0
- }
- res := make(map[int]int, len(nums))
- for _, num := range nums {
- if _, exist := res[num]; exist {
- res[num]++
- continue
- }
- res[num] = 1
- }
- longest := 0
- for k, c := range res {
- if n, exist := res[k+1]; exist {
- if c+n > longest {
- longest = c + n
- }
- }
- }
- return longest
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0598.Range-Addition-II.md b/website/content/ChapterFour/0598.Range-Addition-II.md
deleted file mode 100644
index a4606f951..000000000
--- a/website/content/ChapterFour/0598.Range-Addition-II.md
+++ /dev/null
@@ -1,82 +0,0 @@
-# [598. Range Addition II](https://leetcode.com/problems/range-addition-ii/)
-
-
-## 题目
-
-Given an m * n matrix **M** initialized with all **0**'s and several update operations.
-
-Operations are represented by a 2D array, and each operation is represented by an array with two **positive** integers **a** and **b**, which means **M[i][j]** should be **added by one** for all **0 <= i < a** and **0 <= j < b**.
-
-You need to count and return the number of maximum integers in the matrix after performing all the operations.
-
-**Example 1**:
-
-```
-Input:
-m = 3, n = 3
-operations = [[2,2],[3,3]]
-Output: 4
-Explanation:
-Initially, M =
-[[0, 0, 0],
- [0, 0, 0],
- [0, 0, 0]]
-
-After performing [2,2], M =
-[[1, 1, 0],
- [1, 1, 0],
- [0, 0, 0]]
-
-After performing [3,3], M =
-[[2, 2, 1],
- [2, 2, 1],
- [1, 1, 1]]
-
-So the maximum integer in M is 2, and there are four of it in M. So return 4.
-```
-
-**Note**:
-
-1. The range of m and n is [1,40000].
-2. The range of a is [1,m], and the range of b is [1,n].
-3. The range of operations size won't exceed 10,000.
-
-## 题目大意
-
-给定一个初始元素全部为 0,大小为 m*n 的矩阵 M 以及在 M 上的一系列更新操作。操作用二维数组表示,其中的每个操作用一个含有两个正整数 a 和 b 的数组表示,含义是将所有符合 0 <= i < a 以及 0 <= j < b 的元素 M[i][j] 的值都增加 1。在执行给定的一系列操作后,你需要返回矩阵中含有最大整数的元素个数。
-
-注意:
-
-- m 和 n 的范围是 [1,40000]。
-- a 的范围是 [1,m],b 的范围是 [1,n]。
-- 操作数目不超过 10000。
-
-
-## 解题思路
-
-- 给定一个初始都为 0 的 m * n 的矩阵,和一个操作数组。经过一系列的操作以后,最终输出矩阵中最大整数的元素个数。每次操作都使得一个矩形内的元素都 + 1 。
-- 这一题乍一看像线段树的区间覆盖问题,但是实际上很简单。如果此题是任意的矩阵,那就可能用到线段树了。这一题每个矩阵的起点都包含 [0 , 0] 这个元素,也就是说每次操作都会影响第一个元素。那么这道题就很简单了。经过 n 次操作以后,被覆盖次数最多的矩形区间,一定就是最大整数所在的区间。由于起点都是第一个元素,所以我们只用关心矩形的右下角那个坐标。右下角怎么计算呢?只用每次动态的维护一下矩阵长和宽的最小值即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func maxCount(m int, n int, ops [][]int) int {
- minM, minN := m, n
- for _, op := range ops {
- minM = min(minM, op[0])
- minN = min(minN, op[1])
- }
- return minM * minN
-}
-
-func min(a, b int) int {
- if a < b {
- return a
- }
- return b
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0599.Minimum-Index-Sum-of-Two-Lists.md b/website/content/ChapterFour/0599.Minimum-Index-Sum-of-Two-Lists.md
deleted file mode 100755
index 01cc155e0..000000000
--- a/website/content/ChapterFour/0599.Minimum-Index-Sum-of-Two-Lists.md
+++ /dev/null
@@ -1,77 +0,0 @@
-# [599. Minimum Index Sum of Two Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists/)
-
-## 题目
-
-Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.
-
-You need to help them find out their **common interest** with the **least list index sum**. If there is a choice tie between answers, output all of them with no order requirement. You could assume there always exists an answer.
-
-**Example 1**:
-
- Input:
- ["Shogun", "Tapioca Express", "Burger King", "KFC"]
- ["Piatti", "The Grill at Torrey Pines", "Hungry Hunter Steakhouse", "Shogun"]
- Output: ["Shogun"]
- Explanation: The only restaurant they both like is "Shogun".
-
-**Example 2**:
-
- Input:
- ["Shogun", "Tapioca Express", "Burger King", "KFC"]
- ["KFC", "Shogun", "Burger King"]
- Output: ["Shogun"]
- Explanation: The restaurant they both like and have the least index sum is "Shogun" with index sum 1 (0+1).
-
-**Note**:
-
-1. The length of both lists will be in the range of [1, 1000].
-2. The length of strings in both lists will be in the range of [1, 30].
-3. The index is starting from 0 to the list length minus 1.
-4. No duplicates in both lists.
-
-
-## 题目大意
-
-假设 Andy 和 Doris 想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示。你需要帮助他们用最少的索引和找出他们共同喜爱的餐厅。 如果答案不止一个,则输出所有答案并且不考虑顺序。 你可以假设总是存在一个答案。
-
-
-提示:
-
-- 两个列表的长度范围都在 [1, 1000] 内。
-- 两个列表中的字符串的长度将在 [1,30] 的范围内。
-- 下标从 0 开始,到列表的长度减 1。
-- 两个列表都没有重复的元素。
-
-
-
-## 解题思路
-
-
-- 在 Andy 和 Doris 两人分别有各自的餐厅喜欢列表,要求找出两人公共喜欢的一家餐厅,如果共同喜欢的次数相同,都输出。这一题是简单题,用 map 统计频次,输出频次最多的餐厅。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func findRestaurant(list1 []string, list2 []string) []string {
- m, ans := make(map[string]int, len(list1)), []string{}
- for i, r := range list1 {
- m[r] = i
- }
- for j, r := range list2 {
- if _, ok := m[r]; ok {
- m[r] += j
- if len(ans) == 0 || m[r] == m[ans[0]] {
- ans = append(ans, r)
- } else if m[r] < m[ans[0]] {
- ans = []string{r}
- }
- }
- }
- return ans
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md b/website/content/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md
deleted file mode 100755
index c51411ad5..000000000
--- a/website/content/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md
+++ /dev/null
@@ -1,96 +0,0 @@
-# [628. Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers/)
-
-
-## 题目
-
-Given an integer array, find three numbers whose product is maximum and output the maximum product.
-
-**Example 1**:
-
- Input: [1,2,3]
- Output: 6
-
-**Example 2**:
-
- Input: [1,2,3,4]
- Output: 24
-
-**Note**:
-
-1. The length of the given array will be in range [3,10^4] and all elements are in the range [-1000, 1000].
-2. Multiplication of any three numbers in the input won't exceed the range of 32-bit signed integer.
-
-
-## 题目大意
-
-给定一个整型数组,在数组中找出由三个数组成的最大乘积,并输出这个乘积。
-
-
-
-
-## 解题思路
-
-
-- 给出一个数组,要求求出这个数组中任意挑 3 个数能组成的乘积最大的值。
-- 题目的 test case 数据量比较大,如果用排序的话,时间复杂度高,可以直接考虑模拟,挑出 3 个数组成乘积最大值,必然是一个正数和二个负数,或者三个正数。那么选出最大的三个数和最小的二个数,对比一下就可以求出最大值了。时间复杂度 O(n)
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-// 解法一 排序,时间复杂度 O(n log n)
-func maximumProduct(nums []int) int {
- if len(nums) == 0 {
- return 0
- }
- res := 1
- if len(nums) <= 3 {
- for i := 0; i < len(nums); i++ {
- res = res * nums[i]
- }
- return res
- }
- sort.Ints(nums)
- if nums[len(nums)-1] <= 0 {
- return 0
- }
- return max(nums[0]*nums[1]*nums[len(nums)-1], nums[len(nums)-1]*nums[len(nums)-2]*nums[len(nums)-3])
-}
-
-// 解法二 模拟,时间复杂度 O(n)
-func maximumProduct1(nums []int) int {
- n1, n2, n3 := -1<<63, -1<<63, -1<<63
- n4, n5 := 0, 0
- for _, v := range nums {
- if v > n1 {
- n3 = n2
- n2 = n1
- n1 = v
- } else if v > n2 {
- n3 = n2
- n2 = v
- } else if v > n3 {
- n3 = v
- }
- if v < n4 {
- n5 = n4
- n4 = v
- } else if v < n5 {
- n5 = v
- }
- }
- if n2*n3 > n4*n5 {
- return n1 * n2 * n3
- }
- return n1 * n4 * n5
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md b/website/content/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md
deleted file mode 100755
index b1187be98..000000000
--- a/website/content/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md
+++ /dev/null
@@ -1,113 +0,0 @@
-# [632. Smallest Range Covering Elements from K Lists](https://leetcode.com/problems/smallest-range-covering-elements-from-k-lists/)
-
-
-## 题目
-
-You have `k` lists of sorted integers in ascending order. Find the **smallest** range that includes at least one number from each of the `k` lists.
-
-We define the range [a,b] is smaller than range [c,d] if `b-a < d-c` or `a < c` if `b-a == d-c`.
-
-**Example 1**:
-
- Input: [[4,10,15,24,26], [0,9,12,20], [5,18,22,30]]
- Output: [20,24]
- Explanation:
- List 1: [4, 10, 15, 24,26], 24 is in range [20,24].
- List 2: [0, 9, 12, 20], 20 is in range [20,24].
- List 3: [5, 18, 22, 30], 22 is in range [20,24].
-
-**Note**:
-
-1. The given list may contain duplicates, so ascending order means >= here.
-2. 1 <= `k` <= 3500
-3. -10^5 <= `value of elements` <= 10^5.
-
-
-## 题目大意
-
-你有 k 个升序排列的整数数组。找到一个最小区间,使得 k 个列表中的每个列表至少有一个数包含在其中。
-
-我们定义如果 b-a < d-c 或者在 b-a == d-c 时 a < c,则区间 [a,b] 比 [c,d] 小。
-
-注意:
-
-- 给定的列表可能包含重复元素,所以在这里升序表示 >= 。
-- 1 <= k <= 3500
-- -105 <= 元素的值 <= 105
-- 对于使用Java的用户,请注意传入类型已修改为List>。重置代码模板后可以看到这项改动。
-
-
-
-## 解题思路
-
-
-- 给出 K 个数组,要求在这 K 个数组中找到一个区间,至少能包含这 K 个数组中每个数组中的一个元素。
-- 这一题是第 76 题的变种版。第 76 题是用滑动窗口来解答的,它要求在母字符串 S 中找到最小的子串能包含 T 串的所有字母。这一题类似的,可以把母字符串看成 K 个数组合并起来的大数组,那么 T 串是由 K 个数组中每个数组中抽一个元素出来组成的。求的区间相同,都是能包含 T 的最小区间。另外一个区别在于,第 76 题里面都是字符串,这一题都是数字,在最终拼接成 T 串的时候需要保证 K 个数组中每个都有一个元素,所以理所当然的想到需要维护每个元素所在数组编号。经过上述的转换,可以把这道题转换成第 76 题的解法了。
-- 在具体解题过程中,用 map 来维护窗口内 K 个数组出现的频次。时间复杂度 O(n*log n),空间复杂度是O(n)。
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
- "sort"
-)
-
-func smallestRange(nums [][]int) []int {
- numList, left, right, count, freqMap, res, length := []element{}, 0, -1, 0, map[int]int{}, make([]int, 2), math.MaxInt64
- for i, ns := range nums {
- for _, v := range ns {
- numList = append(numList, element{val: v, index: i})
- }
- }
- sort.Sort(SortByVal{numList})
- for left < len(numList) {
- if right+1 < len(numList) && count < len(nums) {
- right++
- if freqMap[numList[right].index] == 0 {
- count++
- }
- freqMap[numList[right].index]++
- } else {
- if count == len(nums) {
- if numList[right].val-numList[left].val < length {
- length = numList[right].val - numList[left].val
- res[0] = numList[left].val
- res[1] = numList[right].val
- }
- }
- freqMap[numList[left].index]--
- if freqMap[numList[left].index] == 0 {
- count--
- }
- left++
- }
- }
- return res
-}
-
-type element struct {
- val int
- index int
-}
-
-type elements []element
-
-// Len define
-func (p elements) Len() int { return len(p) }
-
-// Swap define
-func (p elements) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
-
-// SortByVal define
-type SortByVal struct{ elements }
-
-// Less define
-func (p SortByVal) Less(i, j int) bool {
- return p.elements[i].val < p.elements[j].val
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0633.Sum-of-Square-Numbers.md b/website/content/ChapterFour/0633.Sum-of-Square-Numbers.md
deleted file mode 100755
index 4af1d2a4f..000000000
--- a/website/content/ChapterFour/0633.Sum-of-Square-Numbers.md
+++ /dev/null
@@ -1,53 +0,0 @@
-# [633. Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/)
-
-
-## 题目
-
-Given a non-negative integer `c`, your task is to decide whether there're two integers `a` and `b` such that a^2 + b^2 = c.
-
-**Example 1**:
-
- Input: 5
- Output: True
- Explanation: 1 * 1 + 2 * 2 = 5
-
-**Example 2**:
-
- Input: 3
- Output: False
-
-
-## 题目大意
-
-给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a^2 + b^2 = c。
-
-
-## 解题思路
-
-- 给出一个数,要求判断这个数能否由由 2 个完全平方数组成。能则输出 true,不能则输出 false。
-- 可以用二分搜索来解答这道题。判断题意,依次计算 `low * low + high * high` 和 c 是否相等。从 [1, sqrt(n)] 区间内进行二分,若能找到则返回 true,找不到就返回 false 。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math"
-
-func judgeSquareSum(c int) bool {
- low, high := 0, int(math.Sqrt(float64(c)))
- for low <= high {
- if low*low+high*high < c {
- low++
- } else if low*low+high*high > c {
- high--
- } else {
- return true
- }
- }
- return false
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0636.Exclusive-Time-of-Functions.md b/website/content/ChapterFour/0636.Exclusive-Time-of-Functions.md
deleted file mode 100755
index 71458a892..000000000
--- a/website/content/ChapterFour/0636.Exclusive-Time-of-Functions.md
+++ /dev/null
@@ -1,100 +0,0 @@
-# [636. Exclusive Time of Functions](https://leetcode.com/problems/exclusive-time-of-functions/)
-
-
-## 题目
-
-On a single threaded CPU, we execute some functions. Each function has a unique id between `0` and `N-1`.
-
-We store logs in timestamp order that describe when a function is entered or exited.
-
-Each log is a string with this format: `"{function_id}:{"start" | "end"}:{timestamp}"`. For example, `"0:start:3"` means the function with id `0` started at the beginning of timestamp `3`. `"1:end:2"` means the function with id `1` ended at the end of timestamp `2`.
-
-A function's *exclusive time* is the number of units of time spent in this function. Note that this does not include any recursive calls to child functions.
-
-Return the exclusive time of each function, sorted by their function id.
-
-**Example 1**:
-
-
-
- Input:
- n = 2
- logs = ["0:start:0","1:start:2","1:end:5","0:end:6"]
- Output: [3, 4]
- Explanation:
- Function 0 starts at the beginning of time 0, then it executes 2 units of time and reaches the end of time 1.
- Now function 1 starts at the beginning of time 2, executes 4 units of time and ends at time 5.
- Function 0 is running again at the beginning of time 6, and also ends at the end of time 6, thus executing for 1 unit of time.
- So function 0 spends 2 + 1 = 3 units of total time executing, and function 1 spends 4 units of total time executing.
-
-**Note**:
-
-1. `1 <= n <= 100`
-2. Two functions won't start or end at the same time.
-3. Functions will always log when they exit.
-
-
-
-## 题目大意
-
-给出一个非抢占单线程CPU的 n 个函数运行日志,找到函数的独占时间。每个函数都有一个唯一的 Id,从 0 到 n-1,函数可能会递归调用或者被其他函数调用。
-
-日志是具有以下格式的字符串:function_id:start_or_end:timestamp。例如:"0:start:0" 表示函数 0 从 0 时刻开始运行。"0:end:0" 表示函数 0 在 0 时刻结束。
-
-函数的独占时间定义是在该方法中花费的时间,调用其他函数花费的时间不算该函数的独占时间。你需要根据函数的 Id 有序地返回每个函数的独占时间。
-
-
-## 解题思路
-
-
-- 利用栈记录每一个开始了但是未完成的任务,完成以后任务就 pop 一个。
-- 注意题目中关于任务时长的定义,例如,start 7,end 7,这个任务执行了 1 秒而不是 0 秒
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "strconv"
- "strings"
-)
-
-type log struct {
- id int
- order string
- time int
-}
-
-func exclusiveTime(n int, logs []string) []int {
- res, lastLog, stack := make([]int, n), log{id: -1, order: "", time: 0}, []log{}
- for i := 0; i < len(logs); i++ {
- a := strings.Split(logs[i], ":")
- id, _ := strconv.Atoi(a[0])
- time, _ := strconv.Atoi(a[2])
-
- if (lastLog.order == "start" && a[1] == "start") || (lastLog.order == "start" && a[1] == "end") {
- res[lastLog.id] += time - lastLog.time
- if a[1] == "end" {
- res[lastLog.id]++
- }
- }
- if lastLog.order == "end" && a[1] == "end" {
- res[id] += time - lastLog.time
- }
- if lastLog.order == "end" && a[1] == "start" && len(stack) != 0 {
- res[stack[len(stack)-1].id] += time - lastLog.time - 1
- }
- if a[1] == "start" {
- stack = append(stack, log{id: id, order: a[1], time: time})
- } else {
- stack = stack[:len(stack)-1]
- }
- lastLog = log{id: id, order: a[1], time: time}
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md b/website/content/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md
deleted file mode 100644
index 34b0c41aa..000000000
--- a/website/content/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md
+++ /dev/null
@@ -1,85 +0,0 @@
-# [637. Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree/)
-
-## 题目
-
-Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.
-
-**Example 1**:
-
-```
-
-Input:
- 3
- / \
- 9 20
- / \
- 15 7
-Output: [3, 14.5, 11]
-Explanation:
-The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11].
-
-```
-
-**Note**:
-
-The range of node's value is in the range of 32-bit signed integer.
-
-
-## 题目大意
-
-按层序从上到下遍历一颗树,计算每一层的平均值。
-
-
-## 解题思路
-
-- 用一个队列即可实现。
-- 第 102 题和第 107 题都是按层序遍历的。
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-func averageOfLevels(root *TreeNode) []float64 {
- if root == nil {
- return []float64{0}
- }
- queue := []*TreeNode{}
- queue = append(queue, root)
- curNum, nextLevelNum, res, count, sum := 1, 0, []float64{}, 1, 0
- for len(queue) != 0 {
- if curNum > 0 {
- node := queue[0]
- if node.Left != nil {
- queue = append(queue, node.Left)
- nextLevelNum++
- }
- if node.Right != nil {
- queue = append(queue, node.Right)
- nextLevelNum++
- }
- curNum--
- sum += node.Val
- queue = queue[1:]
- }
- if curNum == 0 {
- res = append(res, float64(sum)/float64(count))
- curNum, count, nextLevelNum, sum = nextLevelNum, nextLevelNum, 0, 0
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0638.Shopping-Offers.md b/website/content/ChapterFour/0638.Shopping-Offers.md
deleted file mode 100644
index cf389acb3..000000000
--- a/website/content/ChapterFour/0638.Shopping-Offers.md
+++ /dev/null
@@ -1,129 +0,0 @@
-# [638. Shopping Offers](https://leetcode.com/problems/shopping-offers/)
-
-
-
-## 题目
-
-In LeetCode Store, there are some kinds of items to sell. Each item has a price.
-
-However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.
-
-You are given the each item's price, a set of special offers, and the number we need to buy for each item. The job is to output the lowest price you have to pay for **exactly** certain items as given, where you could make optimal use of the special offers.
-
-Each special offer is represented in the form of an array, the last number represents the price you need to pay for this special offer, other numbers represents how many specific items you could get if you buy this offer.
-
-You could use any of special offers as many times as you want.
-
-**Example 1**:
-
-```
-Input: [2,5], [[3,0,5],[1,2,10]], [3,2]
-Output: 14
-Explanation:
-There are two kinds of items, A and B. Their prices are $2 and $5 respectively.
-In special offer 1, you can pay $5 for 3A and 0B
-In special offer 2, you can pay $10 for 1A and 2B.
-You need to buy 3A and 2B, so you may pay $10 for 1A and 2B (special offer #2), and $4 for 2A.
-```
-
-**Example 2**:
-
-```
-Input: [2,3,4], [[1,1,0,4],[2,2,1,9]], [1,2,1]
-Output: 11
-Explanation:
-The price of A is $2, and $3 for B, $4 for C.
-You may pay $4 for 1A and 1B, and $9 for 2A ,2B and 1C.
-You need to buy 1A ,2B and 1C, so you may pay $4 for 1A and 1B (special offer #1), and $3 for 1B, $4 for 1C.
-You cannot add more items, though only $9 for 2A ,2B and 1C.
-```
-
-**Note**:
-
-1. There are at most 6 kinds of items, 100 special offers.
-2. For each item, you need to buy at most 6 of them.
-3. You are **not** allowed to buy more items than you want, even if that would lower the overall price.
-
-
-## 题目大意
-
-在 LeetCode 商店中, 有许多在售的物品。然而,也有一些大礼包,每个大礼包以优惠的价格捆绑销售一组物品。
-
-现给定每个物品的价格,每个大礼包包含物品的清单,以及待购物品清单。请输出确切完成待购清单的最低花费。每个大礼包的由一个数组中的一组数据描述,最后一个数字代表大礼包的价格,其他数字分别表示内含的其他种类物品的数量。任意大礼包可无限次购买。
-
-例子 1:
-
-```
-输入: [2,5], [[3,0,5],[1,2,10]], [3,2]
-输出: 14
-解释:
-有A和B两种物品,价格分别为¥2和¥5。
-大礼包1,你可以以¥5的价格购买3A和0B。
-大礼包2, 你可以以¥10的价格购买1A和2B。
-你需要购买3个A和2个B, 所以你付了¥10购买了1A和2B(大礼包2),以及¥4购买2A。
-
-```
-例子 2:
-
-```
-输入: [2,3,4], [[1,1,0,4],[2,2,1,9]], [1,2,1]
-输出: 11
-解释:
-A,B,C的价格分别为¥2,¥3,¥4.
-你可以用¥4购买1A和1B,也可以用¥9购买2A,2B和1C。
-你需要买1A,2B和1C,所以你付了¥4买了1A和1B(大礼包1),以及¥3购买1B, ¥4购买1C。
-你不可以购买超出待购清单的物品,尽管购买大礼包2更加便宜。
-```
-
-说明:
-
-- 最多6种物品, 100种大礼包。
-- 每种物品,你最多只需要购买6个。
-- 你不可以购买超出待购清单的物品,即使更便宜。
-
-
-## 解题思路
-
-- 给出 3 个数组,3 个数组分别代表的意义是在售的商品价格,多个礼包以及礼包内每个商品的数量和总价,购物清单上需要购买每个商品的数量。问购买清单上的所有商品所需的最低花费。
-- 这一题可以用 DFS 暴力解题,也可以用 DP。笔者这题先用 DFS 来解答。设当前搜索到的状态为 `shopping(price, special, needs)`,其中 `price` 和 `special` 为题目中所述的物品的单价和捆绑销售的大礼包,而 `needs` 为当前需要的每种物品的数量。针对于每个商品,可以有 3 种购买规则,第一种,选礼包里面的第一个优惠购买,第二种,不选当前礼包优惠,选下一个优惠进行购买,第三种,不使用优惠,直接购买。这样就对应了 3 种 DFS 的方向。具体见代码。如果选择了礼包优惠,那么递归到下一层,`need` 需要对应减少礼包里面的数量,最终金额累加。当所有情况遍历完以后,可以返回出最小花费。
-- 这一题需要注意的剪枝情况:是否需要购买礼包。题目中要求了,不能购买超过清单上数量的商品,即使价格便宜,也不行。例如可以买 n 个礼包 A,但是最终商品数量超过了清单上的商品,这种购买方式是不行的。所以需要先判断当前递归中,满足 `need` 和 `price` 条件的,能否使用礼包。这里包含 2 种情况,一种是当前商品已经满足清单个数了,不需要再买了;还有一种情况是已经超过清单数量了,那这种情况需要立即返回,当前这种购买方式不合题意。
-
-## 代码
-
-```go
-func shoppingOffers(price []int, special [][]int, needs []int) int {
- res := -1
- dfsShoppingOffers(price, special, needs, 0, &res)
- return res
-}
-
-func dfsShoppingOffers(price []int, special [][]int, needs []int, pay int, res *int) {
- noNeeds := true
- // 剪枝
- for _, need := range needs {
- if need < 0 {
- return
- }
- if need != 0 {
- noNeeds = false
- }
- }
- if len(special) == 0 || noNeeds {
- for i, p := range price {
- pay += (p * needs[i])
- }
- if pay < *res || *res == -1 {
- *res = pay
- }
- return
- }
- newNeeds := make([]int, len(needs))
- copy(newNeeds, needs)
- for i, n := range newNeeds {
- newNeeds[i] = n - special[0][i]
- }
- dfsShoppingOffers(price, special, newNeeds, pay+special[0][len(price)], res)
- dfsShoppingOffers(price, special[1:], newNeeds, pay+special[0][len(price)], res)
- dfsShoppingOffers(price, special[1:], needs, pay, res)
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0645.Set-Mismatch.md b/website/content/ChapterFour/0645.Set-Mismatch.md
deleted file mode 100755
index 9236fd4c2..000000000
--- a/website/content/ChapterFour/0645.Set-Mismatch.md
+++ /dev/null
@@ -1,62 +0,0 @@
-# [645. Set Mismatch](https://leetcode.com/problems/set-mismatch/)
-
-
-## 题目
-
-The set `S` originally contains numbers from 1 to `n`. But unfortunately, due to the data error, one of the numbers in the set got duplicated to **another** number in the set, which results in repetition of one number and loss of another number.
-
-Given an array `nums` representing the data status of this set after the error. Your task is to firstly find the number occurs twice and then find the number that is missing. Return them in the form of an array.
-
-**Example 1**:
-
- Input: nums = [1,2,2,4]
- Output: [2,3]
-
-**Note**:
-
-1. The given array size will in the range [2, 10000].
-2. The given array's numbers won't have any order.
-
-
-## 题目大意
-
-
-集合 S 包含从1到 n 的整数。不幸的是,因为数据错误,导致集合里面某一个元素复制了成了集合里面的另外一个元素的值,导致集合丢失了一个整数并且有一个元素重复。给定一个数组 nums 代表了集合 S 发生错误后的结果。你的任务是首先寻找到重复出现的整数,再找到丢失的整数,将它们以数组的形式返回。
-
-注意:
-
-- 给定数组的长度范围是 [2, 10000]。
-- 给定的数组是无序的。
-
-
-## 解题思路
-
-
-- 给出一个数组,数组里面装的是 1-n 的数字,由于错误导致有一个数字变成了另外一个数字,要求找出重复的一个数字和正确的数字。这一题是简单题,根据下标比对就可以找到哪个数字重复了,哪个数字缺少了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func findErrorNums(nums []int) []int {
- m, res := make([]int, len(nums)), make([]int, 2)
- for _, n := range nums {
- if m[n-1] == 0 {
- m[n-1] = 1
- } else {
- res[0] = n
- }
- }
- for i := range m {
- if m[i] == 0 {
- res[1] = i + 1
- break
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0648.Replace-Words.md b/website/content/ChapterFour/0648.Replace-Words.md
deleted file mode 100755
index 17614c9c6..000000000
--- a/website/content/ChapterFour/0648.Replace-Words.md
+++ /dev/null
@@ -1,111 +0,0 @@
-# [648. Replace Words](https://leetcode.com/problems/replace-words/)
-
-
-## 题目
-
-In English, we have a concept called `root`, which can be followed by some other words to form another longer word - let's call this word `successor`. For example, the root `an`, followed by `other`, which can form another word `another`.
-
-Now, given a dictionary consisting of many roots and a sentence. You need to replace all the `successor` in the sentence with the `root` forming it. If a `successor` has many `roots` can form it, replace it with the root with the shortest length.
-
-You need to output the sentence after the replacement.
-
-**Example 1**:
-
- Input: dict = ["cat", "bat", "rat"]
- sentence = "the cattle was rattled by the battery"
- Output: "the cat was rat by the bat"
-
-**Note**:
-
-1. The input will only have lower-case letters.
-2. 1 <= dict words number <= 1000
-3. 1 <= sentence words number <= 1000
-4. 1 <= root length <= 100
-5. 1 <= sentence words length <= 1000
-
-
-## 题目大意
-
-在英语中,我们有一个叫做 词根(root)的概念,它可以跟着其他一些词组成另一个较长的单词——我们称这个词为 继承词(successor)。例如,词根an,跟随着单词 other(其他),可以形成新的单词 another(另一个)。
-
-现在,给定一个由许多词根组成的词典和一个句子。你需要将句子中的所有继承词用词根替换掉。如果继承词有许多可以形成它的词根,则用最短的词根替换它。要求输出替换之后的句子。
-
-
-
-## 解题思路
-
-
-- 给出一个句子和一个可替换字符串的数组,如果句子中的单词和可替换列表里面的单词,有相同的首字母,那么就把句子中的单词替换成可替换列表里面的单词。输入最后替换完成的句子。
-- 这一题有 2 种解题思路,第一种就是单纯的用 Map 查找。第二种是用 Trie 去替换。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strings"
-
-// 解法一 哈希表
-func replaceWords(dict []string, sentence string) string {
- roots := make(map[byte][]string)
- for _, root := range dict {
- b := root[0]
- roots[b] = append(roots[b], root)
- }
- words := strings.Split(sentence, " ")
- for i, word := range words {
- b := []byte(word)
- for j := 1; j < len(b) && j <= 100; j++ {
- if findWord(roots, b[0:j]) {
- words[i] = string(b[0:j])
- break
- }
- }
- }
- return strings.Join(words, " ")
-}
-
-func findWord(roots map[byte][]string, word []byte) bool {
- if roots[word[0]] == nil {
- return false
- }
- for _, root := range roots[word[0]] {
- if root == string(word) {
- return true
- }
- }
- return false
-}
-
-//解法二 Trie
-func replaceWords1(dict []string, sentence string) string {
- trie := Constructor208()
- for _, v := range dict {
- trie.Insert(v)
- }
- words := strings.Split(sentence, " ")
- var result []string
- word := ""
- i := 0
- for _, value := range words {
- word = ""
- for i = 1; i < len(value); i++ {
- if trie.Search(value[:i]) {
- word = value[:i]
- break
- }
- }
-
- if len(word) == 0 {
- result = append(result, value)
- } else {
- result = append(result, word)
- }
-
- }
- return strings.Join(result, " ")
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0653.Two-Sum-IV---Input-is-a-BST.md b/website/content/ChapterFour/0653.Two-Sum-IV---Input-is-a-BST.md
deleted file mode 100755
index e203db033..000000000
--- a/website/content/ChapterFour/0653.Two-Sum-IV---Input-is-a-BST.md
+++ /dev/null
@@ -1,75 +0,0 @@
-# [653. Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst/)
-
-## 题目
-
-Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.
-
-**Example 1**:
-
- Input:
- 5
- / \
- 3 6
- / \ \
- 2 4 7
-
- Target = 9
-
- Output: True
-
-**Example 2**:
-
- Input:
- 5
- / \
- 3 6
- / \ \
- 2 4 7
-
- Target = 28
-
- Output: False
-
-
-## 题目大意
-
-给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定的目标结果,则返回 true。
-
-## 解题思路
-
-
-- 在树中判断是否存在 2 个数的和是 sum。
-- 这一题是 two sum 问题的变形题,只不过题目背景是在 BST 上处理的。处理思路大体一致,用 map 记录已经访问过的节点值。边遍历树边查看 map 里面是否有 sum 的另外一半。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-func findTarget(root *TreeNode, k int) bool {
- m := make(map[int]int, 0)
- return findTargetDFS(root, k, m)
-}
-
-func findTargetDFS(root *TreeNode, k int, m map[int]int) bool {
- if root == nil {
- return false
- }
- if _, ok := m[k-root.Val]; ok {
- return ok
- }
- m[root.Val]++
- return findTargetDFS(root.Left, k, m) || findTargetDFS(root.Right, k, m)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0658.Find-K-Closest-Elements.md b/website/content/ChapterFour/0658.Find-K-Closest-Elements.md
deleted file mode 100755
index b55ced18a..000000000
--- a/website/content/ChapterFour/0658.Find-K-Closest-Elements.md
+++ /dev/null
@@ -1,82 +0,0 @@
-# [658. Find K Closest Elements](https://leetcode.com/problems/find-k-closest-elements/)
-
-
-## 题目
-
-Given a sorted array, two integers `k` and `x`, find the `k` closest elements to `x` in the array. The result should also be sorted in ascending order. If there is a tie, the smaller elements are always preferred.
-
-**Example 1**:
-
- Input: [1,2,3,4,5], k=4, x=3
- Output: [1,2,3,4]
-
-**Example 2**:
-
- Input: [1,2,3,4,5], k=4, x=-1
- Output: [1,2,3,4]
-
-**Note**:
-
-1. The value k is positive and will always be smaller than the length of the sorted array.
-2. Length of the given array is positive and will not exceed 10^4
-3. Absolute value of elements in the array and x will not exceed 10^4
-
----
-
-**UPDATE (2017/9/19)**: The arr parameter had been changed to an **array of integers** (instead of a list of integers). **Please reload the code definition to get the latest changes**.
-
-
-## 题目大意
-
-
-给定一个排序好的数组,两个整数 k 和 x,从数组中找到最靠近 x(两数之差最小)的 k 个数。返回的结果必须要是按升序排好的。如果有两个数与 x 的差值一样,优先选择数值较小的那个数。
-
-
-说明:
-
-1. k 的值为正数,且总是小于给定排序数组的长度。
-2. 数组不为空,且长度不超过 104
-3. 数组里的每个元素与 x 的绝对值不超过 104
-
-
-更新(2017/9/19):
-这个参数 arr 已经被改变为一个整数数组(而不是整数列表)。 请重新加载代码定义以获取最新更改。
-
-
-
-
-## 解题思路
-
-
-- 给出一个数组,要求在数组中找到一个长度为 k 的区间,这个区间内每个元素距离 x 的距离都是整个数组里面最小的。
-- 这一题可以用双指针解题,最优解法是二分搜索。由于区间长度固定是 K 个,所以左区间最大只能到 `len(arr) - K` (因为长度为 K 以后,正好右区间就到数组最右边了),在 `[0,len(arr) - K]` 这个区间中进行二分搜索。如果发现 `a[mid]` 与 `x` 距离比 `a[mid + k]` 与 `x` 的距离要大,说明要找的区间一定在右侧,继续二分,直到最终 `low = high` 的时候退出。逼出的 `low` 值就是最终答案区间的左边界。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "sort"
-
-// 解法一 库函数二分搜索
-func findClosestElements(arr []int, k int, x int) []int {
- return arr[sort.Search(len(arr)-k, func(i int) bool { return x-arr[i] <= arr[i+k]-x }):][:k]
-}
-
-// 解法二 手撸二分搜索
-func findClosestElements1(arr []int, k int, x int) []int {
- low, high := 0, len(arr)-k
- for low < high {
- mid := low + (high-low)>>1
- if x-arr[mid] > arr[mid+k]-x {
- low = mid + 1
- } else {
- high = mid
- }
- }
- return arr[low : low+k]
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0661.Image-Smoother.md b/website/content/ChapterFour/0661.Image-Smoother.md
deleted file mode 100644
index 03fde6bf7..000000000
--- a/website/content/ChapterFour/0661.Image-Smoother.md
+++ /dev/null
@@ -1,111 +0,0 @@
-# [661. Image Smoother](https://leetcode.com/problems/image-smoother/)
-
-## 题目
-
-Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 surrounding cells and itself. If a cell has less than 8 surrounding cells, then use as many as you can.
-
-**Example 1**:
-
-```
-Input:
-[[1,1,1],
- [1,0,1],
- [1,1,1]]
-Output:
-[[0, 0, 0],
- [0, 0, 0],
- [0, 0, 0]]
-Explanation:
-For the point (0,0), (0,2), (2,0), (2,2): floor(3/4) = floor(0.75) = 0
-For the point (0,1), (1,0), (1,2), (2,1): floor(5/6) = floor(0.83333333) = 0
-For the point (1,1): floor(8/9) = floor(0.88888889) = 0
-
-```
-
-**Note**:
-
-1. The value in the given matrix is in the range of [0, 255].
-2. The length and width of the given matrix are in the range of [1, 150].
-
-
-## 题目大意
-
-包含整数的二维矩阵 M 表示一个图片的灰度。你需要设计一个平滑器来让每一个单元的灰度成为平均灰度 (向下舍入) ,平均灰度的计算是周围的8个单元和它本身的值求平均,如果周围的单元格不足八个,则尽可能多的利用它们。
-
-注意:
-
-- 给定矩阵中的整数范围为 [0, 255]。
-- 矩阵的长和宽的范围均为 [1, 150]。
-
-
-## 解题思路
-
-- 将二维数组中的每个元素变为周围 9 个元素的平均值。
-- 简单题,按照题意计算平均值即可。需要注意的是边界问题,四个角和边上的元素,这些点计算平均值的时候,计算平均值都不足 9 个元素。
-
-## 代码
-
-```go
-
-package leetcode
-
-func imageSmoother(M [][]int) [][]int {
- res := make([][]int, len(M))
- for i := range M {
- res[i] = make([]int, len(M[0]))
- }
- for y := 0; y < len(M); y++ {
- for x := 0; x < len(M[0]); x++ {
- res[y][x] = smooth(x, y, M)
- }
- }
- return res
-}
-
-func smooth(x, y int, M [][]int) int {
- count, sum := 1, M[y][x]
- // Check bottom
- if y+1 < len(M) {
- sum += M[y+1][x]
- count++
- }
- // Check Top
- if y-1 >= 0 {
- sum += M[y-1][x]
- count++
- }
- // Check left
- if x-1 >= 0 {
- sum += M[y][x-1]
- count++
- }
- // Check Right
- if x+1 < len(M[y]) {
- sum += M[y][x+1]
- count++
- }
- // Check Coners
- // Top Left
- if y-1 >= 0 && x-1 >= 0 {
- sum += M[y-1][x-1]
- count++
- }
- // Top Right
- if y-1 >= 0 && x+1 < len(M[0]) {
- sum += M[y-1][x+1]
- count++
- }
- // Bottom Left
- if y+1 < len(M) && x-1 >= 0 {
- sum += M[y+1][x-1]
- count++
- }
- //Bottom Right
- if y+1 < len(M) && x+1 < len(M[0]) {
- sum += M[y+1][x+1]
- count++
- }
- return sum / count
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0662.Maximum-Width-of-Binary-Tree.md b/website/content/ChapterFour/0662.Maximum-Width-of-Binary-Tree.md
deleted file mode 100755
index d60af0250..000000000
--- a/website/content/ChapterFour/0662.Maximum-Width-of-Binary-Tree.md
+++ /dev/null
@@ -1,152 +0,0 @@
-# [662. Maximum Width of Binary Tree](https://leetcode.com/problems/maximum-width-of-binary-tree/)
-
-
-## 题目
-
-Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a **full binary tree**, but some nodes are null.
-
-The width of one level is defined as the length between the end-nodes (the leftmost and right most non-null nodes in the level, where the `null` nodes between the end-nodes are also counted into the length calculation.
-
-**Example 1**:
-
- Input:
-
- 1
- / \
- 3 2
- / \ \
- 5 3 9
-
- Output: 4
- Explanation: The maximum width existing in the third level with the length 4 (5,3,null,9).
-
-**Example 2**:
-
- Input:
-
- 1
- /
- 3
- / \
- 5 3
-
- Output: 2
- Explanation: The maximum width existing in the third level with the length 2 (5,3).
-
-**Example 3**:
-
- Input:
-
- 1
- / \
- 3 2
- /
- 5
-
- Output: 2
- Explanation: The maximum width existing in the second level with the length 2 (3,2).
-
-**Example 4**:
-
- Input:
-
- 1
- / \
- 3 2
- / \
- 5 9
- / \
- 6 7
- Output: 8
- Explanation:The maximum width existing in the fourth level with the length 8 (6,null,null,null,null,null,null,7).
-
-**Note**: Answer will in the range of 32-bit signed integer.
-
-
-## 题目大意
-
-给定一个二叉树,编写一个函数来获取这个树的最大宽度。树的宽度是所有层中的最大宽度。这个二叉树与满二叉树(full binary tree)结构相同,但一些节点为空。
-
-每一层的宽度被定义为两个端点(该层最左和最右的非空节点,两端点间的null节点也计入长度)之间的长度。
-
-注意: 答案在32位有符号整数的表示范围内。
-
-
-
-## 解题思路
-
-
-- 给出一个二叉树,求这棵树最宽的部分。
-- 这一题可以用 BFS 也可以用 DFS,但是用 BFS 比较方便。按照层序遍历,依次算出每层最左边不为 `null` 的节点和最右边不为 `null` 的节点。这两个节点之间都是算宽度的。最终输出最大的宽度即可。此题的关键在于如何有效的找到每一层的左右边界。
-- 这一题可能有人会想着先补全满二叉树,然后每层分别找左右边界。这种方法提交以后会卡在 `104 / 108` 这组测试用例上,这组测试用例会使得最后某几层填充出现的满二叉树节点特别多,最终导致 `Memory Limit Exceeded` 了。
-- 由于此题要找每层的左右边界,实际上每个节点的 `Val` 值是我们不关心的,那么可以把这个值用来标号,标记成该节点在每层中的序号。父亲节点在上一层中的序号是 x,那么它的左孩子在下一层满二叉树中的序号是 `2*x`,它的右孩子在下一层满二叉树中的序号是 `2*x + 1`。将所有节点都标上号,用 BFS 层序遍历每一层,每一层都找到左右边界,相减拿到宽度,动态维护最大宽度,就是本题的最终答案。
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-func widthOfBinaryTree(root *TreeNode) int {
- if root == nil {
- return 0
- }
- if root.Left == nil && root.Right == nil {
- return 1
- }
-
- queue, res := []*TreeNode{}, 0
- queue = append(queue, &TreeNode{0, root.Left, root.Right})
-
- for len(queue) != 0 {
- var left, right *int
- // 这里需要注意,先保存 queue 的个数,相当于拿到此层的总个数
- qLen := len(queue)
- // 这里循环不要写 i < len(queue),因为每次循环 queue 的长度都在变小
- for i := 0; i < qLen; i++ {
- node := queue[0]
- queue = queue[1:]
- if node.Left != nil {
- // 根据满二叉树父子节点的关系,得到下一层节点在本层的编号
- newVal := node.Val * 2
- queue = append(queue, &TreeNode{newVal, node.Left.Left, node.Left.Right})
- if left == nil || *left > newVal {
- left = &newVal
- }
- if right == nil || *right < newVal {
- right = &newVal
- }
- }
- if node.Right != nil {
- // 根据满二叉树父子节点的关系,得到下一层节点在本层的编号
- newVal := node.Val*2 + 1
- queue = append(queue, &TreeNode{newVal, node.Right.Left, node.Right.Right})
- if left == nil || *left > newVal {
- left = &newVal
- }
- if right == nil || *right < newVal {
- right = &newVal
- }
- }
- }
- switch {
- // 某层只有一个点,那么此层宽度为 1
- case left != nil && right == nil, left == nil && right != nil:
- res = max(res, 1)
- // 某层只有两个点,那么此层宽度为两点之间的距离
- case left != nil && right != nil:
- res = max(res, *right-*left+1)
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0668.Kth-Smallest-Number-in-Multiplication-Table.md b/website/content/ChapterFour/0668.Kth-Smallest-Number-in-Multiplication-Table.md
deleted file mode 100755
index 491973cba..000000000
--- a/website/content/ChapterFour/0668.Kth-Smallest-Number-in-Multiplication-Table.md
+++ /dev/null
@@ -1,84 +0,0 @@
-# [668. Kth Smallest Number in Multiplication Table](https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/)
-
-
-## 题目
-
-Nearly every one have used the [Multiplication Table](https://en.wikipedia.org/wiki/Multiplication_table). But could you find out the `k-th` smallest number quickly from the multiplication table?
-
-Given the height `m` and the length `n` of a `m * n` Multiplication Table, and a positive integer `k`, you need to return the `k-th` smallest number in this table.
-
-**Example 1**:
-
- Input: m = 3, n = 3, k = 5
- Output:
- Explanation:
- The Multiplication Table:
- 1 2 3
- 2 4 6
- 3 6 9
-
- The 5-th smallest number is 3 (1, 2, 2, 3, 3).
-
-**Example 2**:
-
- Input: m = 2, n = 3, k = 6
- Output:
- Explanation:
- The Multiplication Table:
- 1 2 3
- 2 4 6
-
- The 6-th smallest number is 6 (1, 2, 2, 3, 4, 6).
-
-**Note**:
-
-1. The `m` and `n` will be in the range [1, 30000].
-2. The `k` will be in the range [1, m * n]
-
-
-## 题目大意
-
-几乎每一个人都用乘法表。但是你能在乘法表中快速找到第 k 小的数字吗?给定高度 m 、宽度 n 的一张 m * n 的乘法表,以及正整数 k,你需要返回表中第 k 小的数字。
-
-
-注意:
-
-- m 和 n 的范围在 [1, 30000] 之间。
-- k 的范围在 [1, m * n] 之间。
-
-## 解题思路
-
-- 给出 3 个数字,m,n,k。m 和 n 分别代表乘法口诀表的行和列。要求在这个乘法口诀表中找第 k 小的数字。
-- 这一题是第 378 题变种题。利用二分搜索,在 `[1,m*n]` 的区间内搜索第 `k` 小的数。每次二分统计 `≤ mid` 数字的个数。由于是在两数乘法构成的矩阵中计数,知道乘数,被乘数也就知道了,所以计数只需要一层循环。整体代码和第 378 题完全一致,只是计数的部分不同罢了。可以对比第 378 题一起练习。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math"
-
-func findKthNumber(m int, n int, k int) int {
- low, high := 1, m*n
- for low < high {
- mid := low + (high-low)>>1
- if counterKthNum(m, n, mid) >= k {
- high = mid
- } else {
- low = mid + 1
- }
- }
- return low
-}
-
-func counterKthNum(m, n, mid int) int {
- count := 0
- for i := 1; i <= m; i++ {
- count += int(math.Min(math.Floor(float64(mid)/float64(i)), float64(n)))
- }
- return count
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0676.Implement-Magic-Dictionary.md b/website/content/ChapterFour/0676.Implement-Magic-Dictionary.md
deleted file mode 100755
index 4ce7d05cd..000000000
--- a/website/content/ChapterFour/0676.Implement-Magic-Dictionary.md
+++ /dev/null
@@ -1,87 +0,0 @@
-# [676. Implement Magic Dictionary](https://leetcode.com/problems/implement-magic-dictionary/)
-
-
-## 题目
-
-Implement a magic directory with `buildDict`, and `search` methods.
-
-For the method `buildDict`, you'll be given a list of non-repetitive words to build a dictionary.
-
-For the method `search`, you'll be given a word, and judge whether if you modify **exactly** one character into **another**character in this word, the modified word is in the dictionary you just built.
-
-**Example 1**:
-
- Input: buildDict(["hello", "leetcode"]), Output: Null
- Input: search("hello"), Output: False
- Input: search("hhllo"), Output: True
- Input: search("hell"), Output: False
- Input: search("leetcoded"), Output: False
-
-**Note**:
-
-1. You may assume that all the inputs are consist of lowercase letters `a-z`.
-2. For contest purpose, the test data is rather small by now. You could think about highly efficient algorithm after the contest.
-3. Please remember to **RESET** your class variables declared in class MagicDictionary, as static/class variables are **persisted across multiple test cases**. Please see [here](https://leetcode.com/faq/#different-output) for more details.
-
-
-## 题目大意
-
-实现一个带有 buildDict, 以及 search 方法的魔法字典。对于 buildDict 方法,你将被给定一串不重复的单词来构建一个字典。对于 search 方法,你将被给定一个单词,并且判定能否只将这个单词中一个字母换成另一个字母,使得所形成的新单词存在于你构建的字典中。
-
-
-
-## 解题思路
-
-
-- 实现 `MagicDictionary` 的数据结构,这个数据结构内会存储一个字符串数组,当执行 `Search` 操作的时候要求判断传进来的字符串能否只改变一个字符(不能增加字符也不能删除字符)就能变成 `MagicDictionary` 中存储的字符串,如果可以,就输出 `true`,如果不能,就输出 `false`。
-- 这题的解题思路比较简单,用 Map 判断即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-type MagicDictionary struct {
- rdict map[int]string
-}
-
-/** Initialize your data structure here. */
-func Constructor676() MagicDictionary {
- return MagicDictionary{rdict: make(map[int]string)}
-}
-
-/** Build a dictionary through a list of words */
-func (this *MagicDictionary) BuildDict(dict []string) {
- for k, v := range dict {
- this.rdict[k] = v
- }
-}
-
-/** Returns if there is any word in the trie that equals to the given word after modifying exactly one character */
-func (this *MagicDictionary) Search(word string) bool {
- for _, v := range this.rdict {
- n := 0
- if len(word) == len(v) {
- for i := 0; i < len(v); i++ {
- if word[i] != v[i] {
- n += 1
- }
- }
- if n == 1 {
- return true
- }
- }
- }
- return false
-}
-
-/**
- * Your MagicDictionary object will be instantiated and called as such:
- * obj := Constructor();
- * obj.BuildDict(dict);
- * param_2 := obj.Search(word);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0682.Baseball-Game.md b/website/content/ChapterFour/0682.Baseball-Game.md
deleted file mode 100644
index 6f76fd353..000000000
--- a/website/content/ChapterFour/0682.Baseball-Game.md
+++ /dev/null
@@ -1,106 +0,0 @@
-# [682. Baseball Game](https://leetcode.com/problems/baseball-game/)
-
-## 题目
-
-You're now a baseball game point recorder.
-
-Given a list of strings, each string can be one of the 4 following types:
-
-1. Integer (one round's score): Directly represents the number of points you get in this round.
-2. "+" (one round's score): Represents that the points you get in this round are the sum of the last two valid round's points.
-3. "D" (one round's score): Represents that the points you get in this round are the doubled data of the last valid round's points.
-4. "C" (an operation, which isn't a round's score): Represents the last valid round's points you get were invalid and should be removed.
-Each round's operation is permanent and could have an impact on the round before and the round after.
-
-You need to return the sum of the points you could get in all the rounds.
-
-**Example 1**:
-
-```
-
-Input: ["5","2","C","D","+"]
-Output: 30
-Explanation:
-Round 1: You could get 5 points. The sum is: 5.
-Round 2: You could get 2 points. The sum is: 7.
-Operation 1: The round 2's data was invalid. The sum is: 5.
-Round 3: You could get 10 points (the round 2's data has been removed). The sum is: 15.
-Round 4: You could get 5 + 10 = 15 points. The sum is: 30.
-
-```
-
-**Example 2**:
-
-```
-
-Input: ["5","-2","4","C","D","9","+","+"]
-Output: 27
-Explanation:
-Round 1: You could get 5 points. The sum is: 5.
-Round 2: You could get -2 points. The sum is: 3.
-Round 3: You could get 4 points. The sum is: 7.
-Operation 1: The round 3's data is invalid. The sum is: 3.
-Round 4: You could get -4 points (the round 3's data has been removed). The sum is: -1.
-Round 5: You could get 9 points. The sum is: 8.
-Round 6: You could get -4 + 9 = 5 points. The sum is 13.
-Round 7: You could get 9 + 5 = 14 points. The sum is 27.
-
-```
-
-**Note**:
-
-- The size of the input list will be between 1 and 1000.
-- Every integer represented in the list will be between -30000 and 30000.
-
-## 题目大意
-
-这道题是模拟题,给一串数字和操作符。出现数字就直接累加,出现 "C" 就代表栈推出一个元素,相应的总和要减去栈顶的元素。出现 "D" 就代表把前一个元素乘以 2,就得到当前的元素值。再累加。出现 "+" 就代表把前 2 个值求和,得到当前元素的值,再累积。
-
-## 解题思路
-
-这道题用栈模拟即可。
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strconv"
-
-func calPoints(ops []string) int {
- stack := make([]int, len(ops))
- top := 0
-
- for i := 0; i < len(ops); i++ {
- op := ops[i]
- switch op {
- case "+":
- last1 := stack[top-1]
- last2 := stack[top-2]
- stack[top] = last1 + last2
- top++
- case "D":
- last1 := stack[top-1]
- stack[top] = last1 * 2
- top++
- case "C":
- top--
- default:
- stack[top], _ = strconv.Atoi(op)
- top++
- }
- }
-
- points := 0
- for i := 0; i < top; i++ {
- points += stack[i]
- }
- return points
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0684.Redundant-Connection.md b/website/content/ChapterFour/0684.Redundant-Connection.md
deleted file mode 100755
index 527d61bee..000000000
--- a/website/content/ChapterFour/0684.Redundant-Connection.md
+++ /dev/null
@@ -1,85 +0,0 @@
-# [684. Redundant Connection](https://leetcode.com/problems/redundant-connection/)
-
-
-## 题目
-
-In this problem, a tree is an **undirected** graph that is connected and has no cycles.
-
-The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, ..., N), with one additional edge added. The added edge has two different vertices chosen from 1 to N, and was not an edge that already existed.
-
-The resulting graph is given as a 2D-array of `edges`. Each element of `edges` is a pair `[u, v]` with `u < v`, that represents an **undirected** edge connecting nodes `u` and `v`.
-
-Return an edge that can be removed so that the resulting graph is a tree of N nodes. If there are multiple answers, return the answer that occurs last in the given 2D-array. The answer edge `[u, v]` should be in the same format, with `u < v`.
-
-**Example 1**:
-
- Input: [[1,2], [1,3], [2,3]]
- Output: [2,3]
- Explanation: The given undirected graph will be like this:
- 1
- / \
- 2 - 3
-
-**Example 2**:
-
- Input: [[1,2], [2,3], [3,4], [1,4], [1,5]]
- Output: [1,4]
- Explanation: The given undirected graph will be like this:
- 5 - 1 - 2
- | |
- 4 - 3
-
-**Note**:
-
-- The size of the input 2D-array will be between 3 and 1000.
-- Every integer represented in the 2D-array will be between 1 and N, where N is the size of the input array.
-
-**Update (2017-09-26)**: We have overhauled the problem description + test cases and specified clearly the graph is an **undirected** graph. For the **directed** graph follow up please see **[Redundant Connection II](https://leetcode.com/problems/redundant-connection-ii/description/)**). We apologize for any inconvenience caused.
-
-
-## 题目大意
-
-在本问题中, 树指的是一个连通且无环的无向图。输入一个图,该图由一个有着N个节点 (节点值不重复1, 2, ..., N) 的树及一条附加的边构成。附加的边的两个顶点包含在1到N中间,这条附加的边不属于树中已存在的边。结果图是一个以边组成的二维数组。每一个边的元素是一对[u, v] ,满足 u < v,表示连接顶点u 和v的无向图的边。
-
-返回一条可以删去的边,使得结果图是一个有着N个节点的树。如果有多个答案,则返回二维数组中最后出现的边。答案边 [u, v] 应满足相同的格式 u < v。
-
-注意:
-
-- 输入的二维数组大小在 3 到 1000。
-- 二维数组中的整数在 1 到 N 之间,其中 N 是输入数组的大小。
-
-
-## 解题思路
-
-- 给出一个连通无环无向图和一些连通的边,要求在这些边中删除一条边以后,图中的 N 个节点依旧是连通的。如果有多条边,输出最后一条。
-- 这一题可以用并查集直接秒杀。依次扫描所有的边,把边的两端点都合并 `union()` 到一起。如果遇到一条边的两端点已经在一个集合里面了,就说明是多余边,删除。最后输出这些边即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func findRedundantConnection(edges [][]int) []int {
- if len(edges) == 0 {
- return []int{}
- }
- uf, res := template.UnionFind{}, []int{}
- uf.Init(len(edges) + 1)
- for i := 0; i < len(edges); i++ {
- if uf.Find(edges[i][0]) != uf.Find(edges[i][1]) {
- uf.Union(edges[i][0], edges[i][1])
- } else {
- res = append(res, edges[i][0])
- res = append(res, edges[i][1])
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0685.Redundant-Connection-II.md b/website/content/ChapterFour/0685.Redundant-Connection-II.md
deleted file mode 100755
index d6436f4ba..000000000
--- a/website/content/ChapterFour/0685.Redundant-Connection-II.md
+++ /dev/null
@@ -1,110 +0,0 @@
-# [685. Redundant Connection II](https://leetcode.com/problems/redundant-connection-ii/)
-
-
-## 题目
-
-In this problem, a rooted tree is a **directed** graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root node which has no parents.
-
-The given input is a directed graph that started as a rooted tree with N nodes (with distinct values 1, 2, ..., N), with one additional directed edge added. The added edge has two different vertices chosen from 1 to N, and was not an edge that already existed.
-
-The resulting graph is given as a 2D-array of `edges`. Each element of `edges` is a pair `[u, v]` that represents a **directed** edge connecting nodes `u` and `v`, where `u` is a parent of child `v`.
-
-Return an edge that can be removed so that the resulting graph is a rooted tree of N nodes. If there are multiple answers, return the answer that occurs last in the given 2D-array.
-
-**Example 1**:
-
- Input: [[1,2], [1,3], [2,3]]
- Output: [2,3]
- Explanation: The given directed graph will be like this:
- 1
- / \
- v v
- 2-->3
-
-**Example 2**:
-
- Input: [[1,2], [2,3], [3,4], [4,1], [1,5]]
- Output: [4,1]
- Explanation: The given directed graph will be like this:
- 5 <- 1 -> 2
- ^ |
- | v
- 4 <- 3
-
-**Note**:
-
-- The size of the input 2D-array will be between 3 and 1000.
-- Every integer represented in the 2D-array will be between 1 and N, where N is the size of the input array.
-
-
-## 题目大意
-
-
-在本问题中,有根树指满足以下条件的有向图。该树只有一个根节点,所有其他节点都是该根节点的后继。每一个节点只有一个父节点,除了根节点没有父节点。输入一个有向图,该图由一个有着 N 个节点 (节点值不重复1, 2, ..., N) 的树及一条附加的边构成。附加的边的两个顶点包含在1到N中间,这条附加的边不属于树中已存在的边。结果图是一个以边组成的二维数组。 每一个边的元素是一对 [u, v],用以表示有向图中连接顶点 u and v 和顶点的边,其中父节点 u 是子节点 v 的一个父节点。返回一条能删除的边,使得剩下的图是有 N 个节点的有根树。若有多个答案,返回最后出现在给定二维数组的答案。
-
-注意:
-
-- 二维数组大小的在 3 到 1000 范围内。
-- 二维数组中的每个整数在 1 到 N 之间,其中 N 是二维数组的大小。
-
-
-## 解题思路
-
-- 这一题是第 684 题的加强版。第 684 题中的图是无向图,这一题中的图是有向图。
-- 这一题的解法也是用并查集,不过需要灵活一点,不要用模板,因为在模板中,存在路径压缩和 `rank()` 优化,这些优化会改变有向边原始的方向。所以并查集只需要记录 `parent()` 就够用了。
-
-
-
-- 经过分析,可以得到上面这 3 种情况,红色的边是我们实际应该删除的。先来看情况 2 和情况 3 。当不断 `union()` 时,加入一条边以后,会使一个节点的入度变成 2,那么记录下这两条边为 `candidate1` 和 `candidate2`。将后加入的 `candidate2` 这条边先放在一边,继续往下 `union()`。如果 `candidate2` 是红色的边,那么合并到最后,也不会出现任何异常,那么 `candidate2` 就是红色的边,即找到了要删除的边了。如果合并到最后出现了环的问题了,那说明 `candidate2` 是黑色的边,`candidate1` 才是红色的边,那么 `candidate1` 是要删除的边。
-- 再来看看情况 1。如果一路合并到结束也没有发现出现入度为 2 的情况,那么说明遇到了情况 1 。情况 1 会出现环的情况。题目中说如果要删除边,就删除最后出现的那条边。**具体实现见代码注释**。
-
-## 代码
-
-```go
-
-package leetcode
-
-func findRedundantDirectedConnection(edges [][]int) []int {
- if len(edges) == 0 {
- return []int{}
- }
- parent, candidate1, candidate2 := make([]int, len(edges)+1), []int{}, []int{}
- for _, edge := range edges {
- if parent[edge[1]] == 0 {
- parent[edge[1]] = edge[0]
- } else { // 如果一个节点已经有父亲节点了,说明入度已经有 1 了,再来一条边,入度为 2 ,那么跳过新来的这条边 candidate2,并记录下和这条边冲突的边 candidate1
- candidate1 = append(candidate1, parent[edge[1]])
- candidate1 = append(candidate1, edge[1])
- candidate2 = append(candidate2, edge[0])
- candidate2 = append(candidate2, edge[1])
- edge[1] = 0 // 做标记,后面再扫到这条边以后可以直接跳过
- }
- }
- for i := 1; i <= len(edges); i++ {
- parent[i] = i
- }
- for _, edge := range edges {
- if edge[1] == 0 { // 跳过 candidate2 这条边
- continue
- }
- u, v := edge[0], edge[1]
- pu := findRoot(&parent, u)
- if pu == v { // 发现有环
- if len(candidate1) == 0 { // 如果没有出现入度为 2 的情况,那么对应情况 1,就删除这条边
- return edge
- }
- return candidate1 // 出现环并且有入度为 2 的情况,说明 candidate1 是答案
- }
- parent[v] = pu // 没有发现环,继续合并
- }
- return candidate2 // 当最后什么都没有发生,则 candidate2 是答案
-}
-
-func findRoot(parent *[]int, k int) int {
- if (*parent)[k] != k {
- (*parent)[k] = findRoot(parent, (*parent)[k])
- }
- return (*parent)[k]
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md b/website/content/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md
deleted file mode 100755
index 290e2cda6..000000000
--- a/website/content/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md
+++ /dev/null
@@ -1,80 +0,0 @@
-# [693. Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits/)
-
-## 题目
-
-Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
-
-**Example 1**:
-
- Input: 5
- Output: True
- Explanation:
- The binary representation of 5 is: 101
-
-**Example 2**:
-
- Input: 7
- Output: False
- Explanation:
- The binary representation of 7 is: 111.
-
-**Example 3**:
-
- Input: 11
- Output: False
- Explanation:
- The binary representation of 11 is: 1011.
-
-**Example 4**:
-
- Input: 10
- Output: True
- Explanation:
- The binary representation of 10 is: 1010.
-
-
-## 题目大意
-
-给定一个正整数,检查他是否为交替位二进制数:换句话说,就是他的二进制数相邻的两个位数永不相等。
-
-## 解题思路
-
-
-- 判断一个数的二进制位相邻两个数是不相等的,即 `0101` 交叉间隔的,如果是,输出 true。这一题有多种做法,最简单的方法就是直接模拟。比较巧妙的方法是通过位运算,合理构造特殊数据进行位运算到达目的。`010101` 构造出 `101010` 两者相互 `&` 位运算以后就为 0,因为都“插空”了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一
-func hasAlternatingBits(n int) bool {
- /*
- n = 1 0 1 0 1 0 1 0
- n >> 1 0 1 0 1 0 1 0 1
- n ^ n>>1 1 1 1 1 1 1 1 1
- n 1 1 1 1 1 1 1 1
- n + 1 1 0 0 0 0 0 0 0 0
- n & (n+1) 0 0 0 0 0 0 0 0
- */
- n = n ^ (n >> 1)
- return (n & (n + 1)) == 0
-}
-
-// 解法二
-func hasAlternatingBits1(n int) bool {
- last, current := 0, 0
- for n > 0 {
- last = n & 1
- n = n / 2
- current = n & 1
- if last == current {
- return false
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0695.Max-Area-of-Island.md b/website/content/ChapterFour/0695.Max-Area-of-Island.md
deleted file mode 100644
index 2419d561e..000000000
--- a/website/content/ChapterFour/0695.Max-Area-of-Island.md
+++ /dev/null
@@ -1,77 +0,0 @@
-# [695. Max Area of Island](https://leetcode.com/problems/max-area-of-island/)
-
-
-
-## 题目
-
-Given a non-empty 2D array `grid` of 0's and 1's, an **island** is a group of `1`'s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
-
-Find the maximum area of an island in the given 2D array. (If there is no island, the maximum area is 0.)
-
-**Example 1**:
-
-```
-[[0,0,1,0,0,0,0,1,0,0,0,0,0],
- [0,0,0,0,0,0,0,1,1,1,0,0,0],
- [0,1,1,0,1,0,0,0,0,0,0,0,0],
- [0,1,0,0,1,1,0,0,1,0,1,0,0],
- [0,1,0,0,1,1,0,0,1,1,1,0,0],
- [0,0,0,0,0,0,0,0,0,0,1,0,0],
- [0,0,0,0,0,0,0,1,1,1,0,0,0],
- [0,0,0,0,0,0,0,1,1,0,0,0,0]]
-```
-
-Given the above grid, return`6`. Note the answer is not 11, because the island must be connected 4-directionally.
-
-**Example 2**:
-
-```
-[[0,0,0,0,0,0,0,0]]
-```
-
-Given the above grid, return`0`.
-
-**Note**: The length of each dimension in the given `grid` does not exceed 50.
-
-## 题目大意
-
-给定一个包含了一些 0 和 1 的非空二维数组 grid 。一个 岛屿 是由一些相邻的 1 (代表土地) 构成的组合,这里的「相邻」要求两个 1 必须在水平或者竖直方向上相邻。你可以假设 grid 的四个边缘都被 0(代表水)包围着。找到给定的二维数组中最大的岛屿面积。(如果没有岛屿,则返回面积为 0 。)
-
-## 解题思路
-
-- 给出一个地图,要求计算上面岛屿的面积。注意岛屿的定义是四周都是海(为 0 的点),如果土地(为 1 的点)靠在地图边缘,不能算是岛屿。
-- 这一题和第 200 题,第 1254 题解题思路是一致的。DPS 深搜。这不过这一题需要多处理 2 件事情,一个是注意靠边缘的岛屿不能计算在内,二是动态维护岛屿的最大面积。
-
-## 代码
-
-```go
-func maxAreaOfIsland(grid [][]int) int {
- res := 0
- for i, row := range grid {
- for j, col := range row {
- if col == 0 {
- continue
- }
- area := areaOfIsland(grid, i, j)
- if area > res {
- res = area
- }
- }
- }
- return res
-}
-
-func areaOfIsland(grid [][]int, x, y int) int {
- if !isInGrid(grid, x, y) || grid[x][y] == 0 {
- return 0
- }
- grid[x][y] = 0
- total := 1
- for i := 0; i < 4; i++ {
- nx := x + dir[i][0]
- ny := y + dir[i][1]
- total += areaOfIsland(grid, nx, ny)
- }
- return total
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0697.Degree-of-an-Array.md b/website/content/ChapterFour/0697.Degree-of-an-Array.md
deleted file mode 100644
index ab032f5c5..000000000
--- a/website/content/ChapterFour/0697.Degree-of-an-Array.md
+++ /dev/null
@@ -1,80 +0,0 @@
-# [697. Degree of an Array](https://leetcode.com/problems/degree-of-an-array/)
-
-
-## 题目
-
-Given a non-empty array of non-negative integers `nums`, the **degree** of this array is defined as the maximum frequency of any one of its elements.
-
-Your task is to find the smallest possible length of a (contiguous) subarray of `nums`, that has the same degree as `nums`.
-
-**Example 1**:
-
-```
-Input: [1, 2, 2, 3, 1]
-Output: 2
-Explanation:
-The input array has a degree of 2 because both elements 1 and 2 appear twice.
-Of the subarrays that have the same degree:
-[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]
-The shortest length is 2. So return 2.
-
-```
-
-**Example 2**:
-
-```
-Input: [1,2,2,3,1,4,2]
-Output: 6
-```
-
-**Note**:
-
-- `nums.length` will be between 1 and 50,000.
-- `nums[i]` will be an integer between 0 and 49,999.
-
-
-## 题目大意
-
-给定一个非空且只包含非负数的整数数组 nums, 数组的度的定义是指数组里任一元素出现频数的最大值。你的任务是找到与 nums 拥有相同大小的度的最短连续子数组,返回其长度。
-
-注意:
-
-- nums.length 在 1 到 50,000 区间范围内。
-- nums[i] 是一个在 0 到 49,999 范围内的整数。
-
-
-## 解题思路
-
-- 找一个与给定数组相同度的最短连续子数组,输出其长度。数组的度的定义是任一元素出现频数的最大值。
-- 简单题。先统计各个元素的频次,并且动态维护最大频次和子数组的起始和终点位置。这里最短连续子数组有点“迷惑人”。这个最短子数组其实处理起来很简单。只需从前往后扫一遍,记录各个元素第一次出现的位置和最后一次出现的位置即是最短的连续子数组。然后在频次字典里面寻找和最大频次相同的所有解,有可能有多个子数组能满足题意,取出最短的输出即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func findShortestSubArray(nums []int) int {
- frequency, maxFreq, smallest := map[int][]int{}, 0, len(nums)
- for i, num := range nums {
- if _, found := frequency[num]; !found {
- frequency[num] = []int{1, i, i}
- } else {
- frequency[num][0]++
- frequency[num][2] = i
- }
- if maxFreq < frequency[num][0] {
- maxFreq = frequency[num][0]
- }
- }
- for _, indices := range frequency {
- if indices[0] == maxFreq {
- if smallest > indices[2]-indices[1]+1 {
- smallest = indices[2] - indices[1] + 1
- }
- }
- }
- return smallest
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0699.Falling-Squares.md b/website/content/ChapterFour/0699.Falling-Squares.md
deleted file mode 100755
index a3228a87e..000000000
--- a/website/content/ChapterFour/0699.Falling-Squares.md
+++ /dev/null
@@ -1,145 +0,0 @@
-# [699. Falling Squares](https://leetcode.com/problems/falling-squares/)
-
-
-## 题目
-
-On an infinite number line (x-axis), we drop given squares in the order they are given.
-
-The `i`-th square dropped (`positions[i] = (left, side_length)`) is a square with the left-most point being `positions[i][0]` and sidelength `positions[i][1]`.
-
-The square is dropped with the bottom edge parallel to the number line, and from a higher height than all currently landed squares. We wait for each square to stick before dropping the next.
-
-The squares are infinitely sticky on their bottom edge, and will remain fixed to any positive length surface they touch (either the number line or another square). Squares dropped adjacent to each other will not stick together prematurely.
-
-Return a list `ans` of heights. Each height `ans[i]` represents the current highest height of any square we have dropped, after dropping squares represented by `positions[0], positions[1], ..., positions[i]`.
-
-**Example 1**:
-
- Input: [[1, 2], [2, 3], [6, 1]]
- Output: [2, 5, 5]
- Explanation:
-
-After the first drop of `positions[0] = [1, 2]: _aa _aa -------` The maximum height of any square is 2.
-
-After the second drop of `positions[1] = [2, 3]: __aaa __aaa __aaa _aa__ _aa__ --------------` The maximum height of any square is 5. The larger square stays on top of the smaller square despite where its center of gravity is, because squares are infinitely sticky on their bottom edge.
-
-After the third drop of `positions[1] = [6, 1]: __aaa __aaa __aaa _aa _aa___a --------------` The maximum height of any square is still 5. Thus, we return an answer of `[2, 5, 5]`.
-
-**Example 2**:
-
- Input: [[100, 100], [200, 100]]
- Output: [100, 100]
- Explanation: Adjacent squares don't get stuck prematurely - only their bottom edge can stick to surfaces.
-
-**Note**:
-
-- `1 <= positions.length <= 1000`.
-- `1 <= positions[i][0] <= 10^8`.
-- `1 <= positions[i][1] <= 10^6`.
-
-
-## 题目大意
-
-在无限长的数轴(即 x 轴)上,我们根据给定的顺序放置对应的正方形方块。第 i 个掉落的方块(positions[i] = (left, side\_length))是正方形,其中 left 表示该方块最左边的点位置(positions[i][0]),side\_length 表示该方块的边长(positions[i][1])。
-
-每个方块的底部边缘平行于数轴(即 x 轴),并且从一个比目前所有的落地方块更高的高度掉落而下。在上一个方块结束掉落,并保持静止后,才开始掉落新方块。方块的底边具有非常大的粘性,并将保持固定在它们所接触的任何长度表面上(无论是数轴还是其他方块)。邻接掉落的边不会过早地粘合在一起,因为只有底边才具有粘性。
-
-返回一个堆叠高度列表 ans 。每一个堆叠高度 ans[i] 表示在通过 positions[0], positions[1], ..., positions[i] 表示的方块掉落结束后,目前所有已经落稳的方块堆叠的最高高度。
-
-示例 1:
-
-```c
-输入: [[1, 2], [2, 3], [6, 1]]
-输出: [2, 5, 5]
-解释:
-
-第一个方块 positions[0] = [1, 2] 掉落:
-_aa
-_aa
--------
-方块最大高度为 2 。
-
-第二个方块 positions[1] = [2, 3] 掉落:
-__aaa
-__aaa
-__aaa
-_aa__
-_aa__
---------------
-方块最大高度为5。
-大的方块保持在较小的方块的顶部,不论它的重心在哪里,因为方块的底部边缘有非常大的粘性。
-
-第三个方块 positions[1] = [6, 1] 掉落:
-__aaa
-__aaa
-__aaa
-_aa
-_aa___a
---------------
-方块最大高度为5。
-
-因此,我们返回结果[2, 5, 5]。
-
-```
-
-注意:
-
-- 1 <= positions.length <= 1000.
-- 1 <= positions[i][0] <= 10^8.
-- 1 <= positions[i][1] <= 10^6.
-
-
-
-## 解题思路
-
-- 给出一个二维数组,每个一维数组中只有 2 个值,分别代表的是正方形砖块所在 x 轴的坐标起始点,和边长。要求输出每次砖块落下以后,当前最大的高度。正方形砖块落下如同俄罗斯方块,落下的过程中如果遇到了砖块会落在砖块的上面。如果砖块摞起来了以后,下方有空间,是不可能再把砖块挪进去的,因为此题砖块只会垂直落下,不会水平移动(这一点和俄罗斯方块不同)。
-- 这一题可以用线段树解答。由于方块在 x 轴上的坐标范围特别大,如果不离散化,这一题就会 MTE。所以首先去重 - 排序 - 离散化。先把每个砖块所在区间都算出来,每个正方形的方块所在区间是 `[pos[0] , pos[0]+pos[1]-1]` ,为什么右边界要减一呢?因为每个方块占据的区间其实应该是左闭右开的,即 `[pos[0] , pos[0]+pos[1])`,如果右边是开的,那么这个边界会被 2 个区间查询共用,从而导致错误结果。例如 [2,3],[3,4],这两个区间的砖块实际是不会摞在一起的。但是如果右边都是闭区间,用线段树 query 查询的时候,会都找到 [3,3],从而导致这两个区间都会判断 3 这一点的情况。正确的做法应该是 [2,3),[3,4)这样就避免了上述可能导致错误的情况了。离散化以后,所有的坐标区间都在 0~n 之间了。
-- 遍历每个砖块所在区间,先查询这个区间内的值,再加上当前砖块的高度,即为这个区间的最新高度。并更新该区间的值。更新区间的值用到懒惰更新。然后和动态维护的当前最大高度进行比较,将最大值放入最终输出的数组中。
-- 类似的题目有:第 715 题,第 218 题,第 732 题。第 715 题是区间更新定值(**不是增减**),第 218 题可以用扫描线,第 732 题和本题类似,也是俄罗斯方块的题目,但是第 732 题的俄罗斯方块的方块会“断裂”。
-- leetcode 上也有线段树的讲解:[Get Solutions to Interview Questions](https://leetcode.com/articles/a-recursive-approach-to-segment-trees-range-sum-queries-lazy-propagation/)
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func fallingSquares(positions [][]int) []int {
- st, ans, posMap, maxHeight := template.SegmentTree{}, make([]int, 0, len(positions)), discretization(positions), 0
- tmp := make([]int, len(posMap))
- st.Init(tmp, func(i, j int) int {
- return max(i, j)
- })
- for _, p := range positions {
- h := st.QueryLazy(posMap[p[0]], posMap[p[0]+p[1]-1]) + p[1]
- st.UpdateLazy(posMap[p[0]], posMap[p[0]+p[1]-1], h)
- maxHeight = max(maxHeight, h)
- ans = append(ans, maxHeight)
- }
- return ans
-}
-
-func discretization(positions [][]int) map[int]int {
- tmpMap, posArray, posMap := map[int]int{}, []int{}, map[int]int{}
- for _, pos := range positions {
- tmpMap[pos[0]]++
- tmpMap[pos[0]+pos[1]-1]++
- }
- for k := range tmpMap {
- posArray = append(posArray, k)
- }
- sort.Ints(posArray)
- for i, pos := range posArray {
- posMap[pos] = i
- }
- return posMap
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0704.Binary-Search.md b/website/content/ChapterFour/0704.Binary-Search.md
deleted file mode 100755
index b10293d9a..000000000
--- a/website/content/ChapterFour/0704.Binary-Search.md
+++ /dev/null
@@ -1,67 +0,0 @@
-# [704. Binary Search](https://leetcode.com/problems/binary-search/)
-
-
-## 题目
-
-Given a **sorted** (in ascending order) integer array `nums` of `n` elements and a `target` value, write a function to search `target` in `nums`. If `target` exists, then return its index, otherwise return `-1`.
-
-**Example 1**:
-
- Input: nums = [-1,0,3,5,9,12], target = 9
- Output: 4
- Explanation: 9 exists in nums and its index is 4
-
-**Example 2**:
-
- Input: nums = [-1,0,3,5,9,12], target = 2
- Output: -1
- Explanation: 2 does not exist in nums so return -1
-
-**Note**:
-
-1. You may assume that all elements in `nums` are unique.
-2. `n` will be in the range `[1, 10000]`.
-3. The value of each element in `nums` will be in the range `[-9999, 9999]`.
-
-
-## 题目大意
-
-
-给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。
-
-提示:
-
-- 你可以假设 nums 中的所有元素是不重复的。
-- n 将在 [1, 10000]之间。
-- nums 的每个元素都将在 [-9999, 9999]之间。
-
-
-## 解题思路
-
-
-- 给出一个数组,要求在数组中搜索等于 target 的元素的下标。如果找到就输出下标,如果找不到输出 -1 。
-- 简单题,二分搜索的裸题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func search704(nums []int, target int) int {
- low, high := 0, len(nums)-1
- for low <= high {
- mid := low + (high-low)>>1
- if nums[mid] == target {
- return mid
- } else if nums[mid] > target {
- high = mid - 1
- } else {
- low = mid + 1
- }
- }
- return -1
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0705.Design-HashSet.md b/website/content/ChapterFour/0705.Design-HashSet.md
deleted file mode 100755
index d4d241f7a..000000000
--- a/website/content/ChapterFour/0705.Design-HashSet.md
+++ /dev/null
@@ -1,94 +0,0 @@
-# [705. Design HashSet](https://leetcode.com/problems/design-hashset/)
-
-
-## 题目
-
-Design a HashSet without using any built-in hash table libraries.
-
-To be specific, your design should include these functions:
-
-- `add(value)`: Insert a value into the HashSet.
-- `contains(value)` : Return whether the value exists in the HashSet or not.
-- `remove(value)`: Remove a value in the HashSet. If the value does not exist in the HashSet, do nothing.
-
-**Example**:
-
- MyHashSet hashSet = new MyHashSet();
- hashSet.add(1);
- hashSet.add(2);
- hashSet.contains(1); // returns true
- hashSet.contains(3); // returns false (not found)
- hashSet.add(2);
- hashSet.contains(2); // returns true
- hashSet.remove(2);
- hashSet.contains(2); // returns false (already removed)
-
-**Note**:
-
-- All values will be in the range of `[0, 1000000]`.
-- The number of operations will be in the range of `[1, 10000]`.
-- Please do not use the built-in HashSet library.
-
-
-## 题目大意
-
-不使用任何内建的哈希表库设计一个哈希集合具体地说,你的设计应该包含以下的功能:
-
-- add(value):向哈希集合中插入一个值。
-- contains(value) :返回哈希集合中是否存在这个值。
-- remove(value):将给定值从哈希集合中删除。如果哈希集合中没有这个值,什么也不做。
-
-
-注意:
-
-- 所有的值都在 [1, 1000000] 的范围内。
-- 操作的总数目在 [1, 10000] 范围内。
-- 不要使用内建的哈希集合库。
-
-
-
-## 解题思路
-
-
-- 简单题,设计一个 hashset 的数据结构,要求有 `add(value)`,`contains(value)`,`remove(value)`,这 3 个方法。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-type MyHashSet struct {
- data []bool
-}
-
-/** Initialize your data structure here. */
-func Constructor705() MyHashSet {
- return MyHashSet{
- data: make([]bool, 1000001),
- }
-}
-
-func (this *MyHashSet) Add(key int) {
- this.data[key] = true
-}
-
-func (this *MyHashSet) Remove(key int) {
- this.data[key] = false
-}
-
-/** Returns true if this set contains the specified element */
-func (this *MyHashSet) Contains(key int) bool {
- return this.data[key]
-}
-
-/**
- * Your MyHashSet object will be instantiated and called as such:
- * obj := Constructor();
- * obj.Add(key);
- * obj.Remove(key);
- * param_3 := obj.Contains(key);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0706.Design-HashMap.md b/website/content/ChapterFour/0706.Design-HashMap.md
deleted file mode 100755
index 801460984..000000000
--- a/website/content/ChapterFour/0706.Design-HashMap.md
+++ /dev/null
@@ -1,151 +0,0 @@
-# [706. Design HashMap](https://leetcode.com/problems/design-hashmap/)
-
-
-## 题目
-
-Design a HashMap without using any built-in hash table libraries.
-
-To be specific, your design should include these functions:
-
-- `put(key, value)` : Insert a (key, value) pair into the HashMap. If the value already exists in the HashMap, update the value.
-- `get(key)`: Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key.
-- `remove(key)` : Remove the mapping for the value key if this map contains the mapping for the key.
-
-**Example**:
-
- MyHashMap hashMap = new MyHashMap();
- hashMap.put(1, 1);
- hashMap.put(2, 2);
- hashMap.get(1); // returns 1
- hashMap.get(3); // returns -1 (not found)
- hashMap.put(2, 1); // update the existing value
- hashMap.get(2); // returns 1
- hashMap.remove(2); // remove the mapping for 2
- hashMap.get(2); // returns -1 (not found)
-
-**Note**:
-
-- All keys and values will be in the range of `[0, 1000000]`.
-- The number of operations will be in the range of `[1, 10000]`.
-- Please do not use the built-in HashMap library.
-
-
-## 题目大意
-
-不使用任何内建的哈希表库设计一个哈希映射具体地说,你的设计应该包含以下的功能:
-
-- put(key, value):向哈希映射中插入(键,值)的数值对。如果键对应的值已经存在,更新这个值。
-- get(key):返回给定的键所对应的值,如果映射中不包含这个键,返回 -1。
-- remove(key):如果映射中存在这个键,删除这个数值对。
-
-注意:
-
-- 所有的值都在 [1, 1000000] 的范围内。
-- 操作的总数目在 [1, 10000] 范围内。
-- 不要使用内建的哈希库。
-
-
-## 解题思路
-
-
-- 简单题,设计一个 hashmap 的数据结构,要求有 `put(key, value)`,`get(key)`,`remove(key)`,这 3 个方法。设计一个 map 主要需要处理哈希冲突,一般都是链表法解决冲突。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-const Len int = 100000
-
-type MyHashMap struct {
- content [Len]*HashNode
-}
-
-type HashNode struct {
- key int
- val int
- next *HashNode
-}
-
-func (N *HashNode) Put(key int, value int) {
- if N.key == key {
- N.val = value
- return
- }
- if N.next == nil {
- N.next = &HashNode{key, value, nil}
- return
- }
- N.next.Put(key, value)
-}
-
-func (N *HashNode) Get(key int) int {
- if N.key == key {
- return N.val
- }
- if N.next == nil {
- return -1
- }
- return N.next.Get(key)
-}
-
-func (N *HashNode) Remove(key int) *HashNode {
- if N.key == key {
- p := N.next
- N.next = nil
- return p
- }
- if N.next != nil {
- return N.next.Remove(key)
- }
- return nil
-}
-
-/** Initialize your data structure here. */
-func Constructor706() MyHashMap {
- return MyHashMap{}
-}
-
-/** value will always be non-negative. */
-func (this *MyHashMap) Put(key int, value int) {
- node := this.content[this.Hash(key)]
- if node == nil {
- this.content[this.Hash(key)] = &HashNode{key: key, val: value, next: nil}
- return
- }
- node.Put(key, value)
-}
-
-/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
-func (this *MyHashMap) Get(key int) int {
- HashNode := this.content[this.Hash(key)]
- if HashNode == nil {
- return -1
- }
- return HashNode.Get(key)
-}
-
-/** Removes the mapping of the specified value key if this map contains a mapping for the key */
-func (this *MyHashMap) Remove(key int) {
- HashNode := this.content[this.Hash(key)]
- if HashNode == nil {
- return
- }
- this.content[this.Hash(key)] = HashNode.Remove(key)
-}
-
-func (this *MyHashMap) Hash(value int) int {
- return value % Len
-}
-
-/**
- * Your MyHashMap object will be instantiated and called as such:
- * obj := Constructor();
- * obj.Put(key,value);
- * param_2 := obj.Get(key);
- * obj.Remove(key);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0707.Design-Linked-List.md b/website/content/ChapterFour/0707.Design-Linked-List.md
deleted file mode 100644
index c014e9e6b..000000000
--- a/website/content/ChapterFour/0707.Design-Linked-List.md
+++ /dev/null
@@ -1,140 +0,0 @@
-# [707. Design Linked List](https://leetcode.com/problems/design-linked-list/)
-
-## 题目
-
-Design your implementation of the linked list. You can choose to use the singly linked list or the doubly linked list. A node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer/reference to the next node. If you want to use the doubly linked list, you will need one more attribute prev to indicate the previous node in the linked list. Assume all nodes in the linked list are 0-indexed.
-
-Implement these functions in your linked list class:
-
-- get(index) : Get the value of the index-th node in the linked list. If the index is invalid, return -1.
-- addAtHead(val) : Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
-- addAtTail(val) : Append a node of value val to the last element of the linked list.
-- addAtIndex(index, val) : Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.
-- deleteAtIndex(index) : Delete the index-th node in the linked list, if the index is valid.
-
-**Example**:
-
-```
-
-MyLinkedList linkedList = new MyLinkedList();
-linkedList.addAtHead(1);
-linkedList.addAtTail(3);
-linkedList.addAtIndex(1, 2); // linked list becomes 1->2->3
-linkedList.get(1); // returns 2
-linkedList.deleteAtIndex(1); // now the linked list is 1->3
-linkedList.get(1); // returns 3
-
-```
-
-**Note**:
-
-- All values will be in the range of [1, 1000].
-- The number of operations will be in the range of [1, 1000].
-- Please do not use the built-in LinkedList library.
-
-## 题目大意
-
-这道题比较简单,设计一个链表,实现相关操作即可。
-
-## 解题思路
-
-这题有一个地方比较坑,题目中 Note 里面写的数值取值范围是 [1, 1000],笔者把 0 当做无效值。结果 case 里面出现了 0 是有效值。case 和题意不符。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-type MyLinkedList struct {
- Val int
- Next *MyLinkedList
-}
-
-/** Initialize your data structure here. */
-func Constructor() MyLinkedList {
- return MyLinkedList{Val: -999, Next: nil}
-}
-
-/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */
-func (this *MyLinkedList) Get(index int) int {
- cur := this
- for i := 0; cur != nil; i++ {
- if i == index {
- if cur.Val == -999 {
- return -1
- } else {
- return cur.Val
- }
- }
- cur = cur.Next
- }
- return -1
-}
-
-/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */
-func (this *MyLinkedList) AddAtHead(val int) {
- if this.Val == -999 {
- this.Val = val
- } else {
- tmp := &MyLinkedList{Val: this.Val, Next: this.Next}
- this.Val = val
- this.Next = tmp
- }
-}
-
-/** Append a node of value val to the last element of the linked list. */
-func (this *MyLinkedList) AddAtTail(val int) {
- cur := this
- for cur.Next != nil {
- cur = cur.Next
- }
- tmp := &MyLinkedList{Val: val, Next: nil}
- cur.Next = tmp
-}
-
-/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */
-func (this *MyLinkedList) AddAtIndex(index int, val int) {
- cur := this
- if index == 0 {
- this.AddAtHead(val)
- return
- }
- for i := 0; cur != nil; i++ {
- if i == index-1 {
- break
- }
- cur = cur.Next
- }
- if cur != nil && cur.Val != -999 {
- tmp := &MyLinkedList{Val: val, Next: cur.Next}
- cur.Next = tmp
- }
-}
-
-/** Delete the index-th node in the linked list, if the index is valid. */
-func (this *MyLinkedList) DeleteAtIndex(index int) {
- cur := this
- for i := 0; cur != nil; i++ {
- if i == index-1 {
- break
- }
- cur = cur.Next
- }
- if cur != nil && cur.Next != nil {
- cur.Next = cur.Next.Next
- }
-}
-
-/**
- * Your MyLinkedList object will be instantiated and called as such:
- * obj := Constructor();
- * param_1 := obj.Get(index);
- * obj.AddAtHead(val);
- * obj.AddAtTail(val);
- * obj.AddAtIndex(index,val);
- * obj.DeleteAtIndex(index);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0710.Random-Pick-with-Blacklist.md b/website/content/ChapterFour/0710.Random-Pick-with-Blacklist.md
deleted file mode 100644
index d796e1e7e..000000000
--- a/website/content/ChapterFour/0710.Random-Pick-with-Blacklist.md
+++ /dev/null
@@ -1,145 +0,0 @@
-# [710. Random Pick with Blacklist](https://leetcode.com/problems/random-pick-with-blacklist/)
-
-## 题目
-
-Given a blacklist B containing unique integers from [0, N), write a function to return a uniform random integer from [0, N) which is NOT in B.
-
-Optimize it such that it minimizes the call to system’s Math.random().
-
-**Note**:
-
-1. 1 <= N <= 1000000000
-2. 0 <= B.length < min(100000, N)
-3. [0, N) does NOT include N. See interval notation.
-
-
-**Example 1**:
-
-```
-
-Input:
-["Solution","pick","pick","pick"]
-[[1,[]],[],[],[]]
-Output: [null,0,0,0]
-
-```
-
-**Example 2**:
-
-```
-
-Input:
-["Solution","pick","pick","pick"]
-[[2,[]],[],[],[]]
-Output: [null,1,1,1]
-
-```
-
-**Example 3**:
-
-```
-
-Input:
-["Solution","pick","pick","pick"]
-[[3,[1]],[],[],[]]
-Output: [null,0,0,2]
-
-```
-
-**Example 4**:
-
-```
-
-Input:
-["Solution","pick","pick","pick"]
-[[4,[2]],[],[],[]]
-Output: [null,1,3,1]
-
-```
-
-
-Explanation of Input Syntax:
-
-The input is two lists: the subroutines called and their arguments. Solution's constructor has two arguments, N and the blacklist B. pick has no arguments. Arguments are always wrapped with a list, even if there aren't any.
-
-
-## 题目大意
-
-给一个数字 N,再给一个黑名单 B,要求在 [0,N) 区间内随机输出一个数字,这个是不在黑名单 B 中的任意一个数字。
-
-## 解题思路
-
-这道题的 N 的范围特别大,最大是 10 亿。如果利用桶计数,开不出来这么大的数组。考虑到题目要求我们输出的数字是随机的,所以不需要存下所有的白名单的数字。
-
-假设 N=10, blacklist=[3, 5, 8, 9]
-
-
-
-
-这一题有点类似 hash 冲突的意思。如果随机访问一个数,这个数正好在黑名单之内,那么就 hash 冲突了,我们就把它映射到另外一个不在黑名单里面的数中。如上图,我们可以将 3,5 重新映射到 7,6 的位置。这样末尾开始的几个数要么是黑名单里面的数,要么就是映射的数字。
-
-hash 表总长度应该为 M = N - len(backlist),然后在 M 的长度中扫描是否有在黑名单中的数,如果有,就代表 hash 冲突了。冲突就把这个数字映射到 (M,N) 这个区间范围内。为了提高效率,可以选择这个区间的头部或者尾部开始映射,我选择的是末尾开始映射。从 (M,N) 这个区间的末尾开始往前找,找黑名单不存在的数,找到了就把 [0,M] 区间内冲突的数字映射到这里来。最后 pick 的时候,只需要查看 map 中是否存在映射关系,如果存在就输出 map 中映射之后的值,如果没有就代表没有冲突,直接输出那个 index 即可。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math/rand"
-
-type Solution struct {
- M int
- BlackMap map[int]int
-}
-
-func Constructor710(N int, blacklist []int) Solution {
- blackMap := map[int]int{}
- for i := 0; i < len(blacklist); i++ {
- blackMap[blacklist[i]] = 1
- }
- M := N - len(blacklist)
- for _, value := range blacklist {
- if value < M {
- for {
- if _, ok := blackMap[N-1]; ok {
- N--
- } else {
- break
- }
- }
- blackMap[value] = N - 1
- N--
- }
- }
- return Solution{BlackMap: blackMap, M: M}
-}
-
-func (this *Solution) Pick() int {
- idx := rand.Intn(this.M)
- if _, ok := this.BlackMap[idx]; ok {
- return this.BlackMap[idx]
- }
- return idx
-}
-
-/**
- * Your Solution object will be instantiated and called as such:
- * obj := Constructor(N, blacklist);
- * param_1 := obj.Pick();
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0713.Subarray-Product-Less-Than-K.md b/website/content/ChapterFour/0713.Subarray-Product-Less-Than-K.md
deleted file mode 100644
index f5afc7d1a..000000000
--- a/website/content/ChapterFour/0713.Subarray-Product-Less-Than-K.md
+++ /dev/null
@@ -1,65 +0,0 @@
-# [713. Subarray Product Less Than K](https://leetcode.com/problems/subarray-product-less-than-k/)
-
-## 题目
-
-Your are given an array of positive integers nums.
-
-Count and print the number of (contiguous) subarrays where the product of all the elements in the subarray is less than k.
-
-**Example 1**:
-
-```
-
-Input: nums = [10, 5, 2, 6], k = 100
-Output: 8
-Explanation: The 8 subarrays that have product less than 100 are: [10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6].
-Note that [10, 5, 2] is not included as the product of 100 is not strictly less than k.
-
-```
-
-
-**Note**:
-
-- 0 < nums.length <= 50000.
-- 0 < nums[i] < 1000.
-- 0 <= k < 10^6.
-
-## 题目大意
-
-给出一个数组,要求在输出符合条件的窗口数,条件是,窗口中所有数字乘积小于 K 。
-
-## 解题思路
-
-这道题也是滑动窗口的题目,在窗口滑动的过程中不断累乘,直到乘积大于 k,大于 k 的时候就缩小左窗口。有一种情况还需要单独处理一下,即类似 [100] 这种情况。这种情况窗口内乘积等于 k,不小于 k,左边窗口等于右窗口,这个时候需要左窗口和右窗口同时右移。
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func numSubarrayProductLessThanK(nums []int, k int) int {
- if len(nums) == 0 {
- return 0
- }
- res, left, right, prod := 0, 0, 0, 1
- for left < len(nums) {
- if right < len(nums) && prod*nums[right] < k {
- prod = prod * nums[right]
- right++
- } else if left == right {
- left++
- right++
- } else {
- res += right - left
- prod = prod / nums[left]
- left++
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md b/website/content/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md
deleted file mode 100755
index 7bf23833c..000000000
--- a/website/content/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md
+++ /dev/null
@@ -1,80 +0,0 @@
-# [714. Best Time to Buy and Sell Stock with Transaction Fee](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/)
-
-
-## 题目
-
-Your are given an array of integers `prices`, for which the `i`-th element is the price of a given stock on day `i`; and a non-negative integer `fee` representing a transaction fee.
-
-You may complete as many transactions as you like, but you need to pay the transaction fee for each transaction. You may not buy more than 1 share of a stock at a time (ie. you must sell the stock share before you buy again.)
-
-Return the maximum profit you can make.
-
-**Example 1**:
-
- Input: prices = [1, 3, 2, 8, 4, 9], fee = 2
- Output: 8
- Explanation: The maximum profit can be achieved by:
- Buying at prices[0] = 1
- Selling at prices[3] = 8
- Buying at prices[4] = 4
- Selling at prices[5] = 9
- The total profit is ((8 - 1) - 2) + ((9 - 4) - 2) = 8.
-
-**Note**:
-
-- `0 < prices.length <= 50000`.
-- `0 < prices[i] < 50000`.
-- `0 <= fee < 50000`.
-
-
-## 题目大意
-
-给定一个整数数组 prices,其中第 i 个元素代表了第 i 天的股票价格 ;非负整数 fee 代表了交易股票的手续费用。你可以无限次地完成交易,但是你每次交易都需要付手续费。如果你已经购买了一个股票,在卖出它之前你就不能再继续购买股票了。要求返回获得利润的最大值。
-
-
-
-## 解题思路
-
-- 给定一个数组,表示一支股票在每一天的价格。设计一个交易算法,在这些天进行自动交易,要求:每一天只能进行一次操作;在买完股票后,必须卖了股票,才能再次买入;每次卖了股票以后,需要缴纳一部分的手续费。问如何交易,能让利润最大?
-- 这一题是第 121 题、第 122 题、第 309 题的变种题。
-- 这一题的解题思路是 DP,需要维护买和卖的两种状态。`buy[i]` 代表第 `i` 天买入的最大收益,`sell[i]` 代表第 `i` 天卖出的最大收益,状态转移方程是 `buy[i] = max(buy[i-1], sell[i-1]-prices[i])`,`sell[i] = max(sell[i-1], buy[i-1]+prices[i]-fee)`。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
-)
-
-// 解法一 模拟 DP
-func maxProfit714(prices []int, fee int) int {
- if len(prices) <= 1 {
- return 0
- }
- buy, sell := make([]int, len(prices)), make([]int, len(prices))
- for i := range buy {
- buy[i] = math.MinInt64
- }
- buy[0] = -prices[0]
- for i := 1; i < len(prices); i++ {
- buy[i] = max(buy[i-1], sell[i-1]-prices[i])
- sell[i] = max(sell[i-1], buy[i-1]+prices[i]-fee)
- }
- return sell[len(sell)-1]
-}
-
-// 解法二 优化辅助空间的 DP
-func maxProfit714_1(prices []int, fee int) int {
- sell, buy := 0, -prices[0]
- for i := 1; i < len(prices); i++ {
- sell = max(sell, buy+prices[i]-fee)
- buy = max(buy, sell-prices[i])
- }
- return sell
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0715.Range-Module.md b/website/content/ChapterFour/0715.Range-Module.md
deleted file mode 100755
index acd403646..000000000
--- a/website/content/ChapterFour/0715.Range-Module.md
+++ /dev/null
@@ -1,270 +0,0 @@
-# [715. Range Module](https://leetcode.com/problems/range-module/)
-
-
-## 题目
-
-A Range Module is a module that tracks ranges of numbers. Your task is to design and implement the following interfaces in an efficient manner.
-
-- `addRange(int left, int right)` Adds the half-open interval `[left, right)`, tracking every real number in that interval. Adding an interval that partially overlaps with currently tracked numbers should add any numbers in the interval `[left, right)` that are not already tracked.
-- `queryRange(int left, int right)` Returns true if and only if every real number in the interval `[left, right)` is currently being tracked.
-- `removeRange(int left, int right)` Stops tracking every real number currently being tracked in the interval `[left, right)`.
-
-**Example 1**:
-
- addRange(10, 20): null
- removeRange(14, 16): null
- queryRange(10, 14): true (Every number in [10, 14) is being tracked)
- queryRange(13, 15): false (Numbers like 14, 14.03, 14.17 in [13, 15) are not being tracked)
- queryRange(16, 17): true (The number 16 in [16, 17) is still being tracked, despite the remove operation)
-
-**Note**:
-
-- A half open interval `[left, right)` denotes all real numbers `left <= x < right`.
-- `0 < left < right < 10^9` in all calls to `addRange, queryRange, removeRange`.
-- The total number of calls to `addRange` in a single test case is at most `1000`.
-- The total number of calls to `queryRange` in a single test case is at most `5000`.
-- The total number of calls to `removeRange` in a single test case is at most `1000`.
-
-## 题目大意
-
-Range 模块是跟踪数字范围的模块。你的任务是以一种有效的方式设计和实现以下接口。
-
-- addRange(int left, int right) 添加半开区间 [left, right),跟踪该区间中的每个实数。添加与当前跟踪的数字部分重叠的区间时,应当添加在区间 [left, right) 中尚未跟踪的任何数字到该区间中。
-- queryRange(int left, int right) 只有在当前正在跟踪区间 [left, right) 中的每一个实数时,才返回 true。
-- removeRange(int left, int right) 停止跟踪区间 [left, right) 中当前正在跟踪的每个实数。
-
-
-示例:
-
-```
-addRange(10, 20): null
-removeRange(14, 16): null
-queryRange(10, 14): true (区间 [10, 14) 中的每个数都正在被跟踪)
-queryRange(13, 15): false (未跟踪区间 [13, 15) 中像 14, 14.03, 14.17 这样的数字)
-queryRange(16, 17): true (尽管执行了删除操作,区间 [16, 17) 中的数字 16 仍然会被跟踪)
-```
-
-提示:
-
-- 半开区间 [left, right) 表示所有满足 left <= x < right 的实数。
-- 对 addRange, queryRange, removeRange 的所有调用中 0 < left < right < 10^9。
-- 在单个测试用例中,对 addRange 的调用总数不超过 1000 次。
-- 在单个测试用例中,对 queryRange 的调用总数不超过 5000 次。
-- 在单个测试用例中,对 removeRange 的调用总数不超过 1000 次。
-
-
-## 解题思路
-
-- 设计一个数据结构,能完成添加区间 `addRange`,查询区间 `queryRange`,移除区间 `removeRange` 三种操作。查询区间的操作需要更加高效一点。
-- 这一题可以用线段树来解答,但是时间复杂度不高,最优解是用二叉排序树 BST 来解答。先来看线段树。这一题是更新区间内的值,所以需要用到懒惰更新。添加区间可以把区间内的值都赋值为 1 。由于题目中未预先确定区间范围,选用树的形式实现线段树比数组实现更加节约空间(当然用数组也可以,区间最大是 1000,点至多有 2000 个)。移除区间的时候就是把区间内的值都赋值标记为 0 。
-- 类似的题目有:第 699 题,第 218 题,第 732 题。第 715 题是区间更新定值(**不是增减**),第 218 题可以用扫描线,第 732 题和第 699 题类似,也是俄罗斯方块的题目,但是第 732 题的俄罗斯方块的方块会“断裂”。
-
-## 代码
-
-```go
-
-package leetcode
-
-// RangeModule define
-type RangeModule struct {
- Root *SegmentTreeNode
-}
-
-// SegmentTreeNode define
-type SegmentTreeNode struct {
- Start, End int
- Tracked bool
- Lazy int
- Left, Right *SegmentTreeNode
-}
-
-// Constructor715 define
-func Constructor715() RangeModule {
- return RangeModule{&SegmentTreeNode{0, 1e9, false, 0, nil, nil}}
-}
-
-// AddRange define
-func (rm *RangeModule) AddRange(left int, right int) {
- update(rm.Root, left, right-1, true)
-}
-
-// QueryRange define
-func (rm *RangeModule) QueryRange(left int, right int) bool {
- return query(rm.Root, left, right-1)
-}
-
-// RemoveRange define
-func (rm *RangeModule) RemoveRange(left int, right int) {
- update(rm.Root, left, right-1, false)
-}
-
-func lazyUpdate(node *SegmentTreeNode) {
- if node.Lazy != 0 {
- node.Tracked = node.Lazy == 2
- }
- if node.Start != node.End {
- if node.Left == nil || node.Right == nil {
- m := node.Start + (node.End-node.Start)/2
- node.Left = &SegmentTreeNode{node.Start, m, node.Tracked, 0, nil, nil}
- node.Right = &SegmentTreeNode{m + 1, node.End, node.Tracked, 0, nil, nil}
- } else if node.Lazy != 0 {
- node.Left.Lazy = node.Lazy
- node.Right.Lazy = node.Lazy
- }
- }
- node.Lazy = 0
-}
-
-func update(node *SegmentTreeNode, start, end int, track bool) {
- lazyUpdate(node)
- if start > end || node == nil || end < node.Start || node.End < start {
- return
- }
- if start <= node.Start && node.End <= end {
- // segment completely covered by the update range
- node.Tracked = track
- if node.Start != node.End {
- if track {
- node.Left.Lazy = 2
- node.Right.Lazy = 2
- } else {
- node.Left.Lazy = 1
- node.Right.Lazy = 1
- }
- }
- return
- }
- update(node.Left, start, end, track)
- update(node.Right, start, end, track)
- node.Tracked = node.Left.Tracked && node.Right.Tracked
-}
-
-func query(node *SegmentTreeNode, start, end int) bool {
- lazyUpdate(node)
- if start > end || node == nil || end < node.Start || node.End < start {
- return true
- }
- if start <= node.Start && node.End <= end {
- // segment completely covered by the update range
- return node.Tracked
- }
- return query(node.Left, start, end) && query(node.Right, start, end)
-}
-
-// 解法二 BST
-// type RangeModule struct {
-// Root *BSTNode
-// }
-
-// type BSTNode struct {
-// Interval []int
-// Left, Right *BSTNode
-// }
-
-// func Constructor715() RangeModule {
-// return RangeModule{}
-// }
-
-// func (this *RangeModule) AddRange(left int, right int) {
-// interval := []int{left, right - 1}
-// this.Root = insert(this.Root, interval)
-// }
-
-// func (this *RangeModule) RemoveRange(left int, right int) {
-// interval := []int{left, right - 1}
-// this.Root = delete(this.Root, interval)
-// }
-
-// func (this *RangeModule) QueryRange(left int, right int) bool {
-// return query(this.Root, []int{left, right - 1})
-// }
-
-// func (this *RangeModule) insert(root *BSTNode, interval []int) *BSTNode {
-// if root == nil {
-// return &BSTNode{interval, nil, nil}
-// }
-// if root.Interval[0] <= interval[0] && interval[1] <= root.Interval[1] {
-// return root
-// }
-// if interval[0] < root.Interval[0] {
-// root.Left = insert(root.Left, []int{interval[0], min(interval[1], root.Interval[0]-1)})
-// }
-// if root.Interval[1] < interval[1] {
-// root.Right = insert(root.Right, []int{max(interval[0], root.Interval[1]+1), interval[1]})
-// }
-// return root
-// }
-
-// func (this *RangeModule) delete(root *BSTNode, interval []int) *BSTNode {
-// if root == nil {
-// return nil
-// }
-// if interval[0] < root.Interval[0] {
-// root.Left = delete(root.Left, []int{interval[0], min(interval[1], root.Interval[0]-1)})
-// }
-// if root.Interval[1] < interval[1] {
-// root.Right = delete(root.Right, []int{max(interval[0], root.Interval[1]+1), interval[1]})
-// }
-// if interval[1] < root.Interval[0] || root.Interval[1] < interval[0] {
-// return root
-// }
-// if interval[0] <= root.Interval[0] && root.Interval[1] <= interval[1] {
-// if root.Left == nil {
-// return root.Right
-// } else if root.Right == nil {
-// return root.Left
-// } else {
-// pred := root.Left
-// for pred.Right != nil {
-// pred = pred.Right
-// }
-// root.Interval = pred.Interval
-// root.Left = delete(root.Left, pred.Interval)
-// return root
-// }
-// }
-// if root.Interval[0] < interval[0] && interval[1] < root.Interval[1] {
-// left := &BSTNode{[]int{root.Interval[0], interval[0] - 1}, root.Left, nil}
-// right := &BSTNode{[]int{interval[1] + 1, root.Interval[1]}, nil, root.Right}
-// left.Right = right
-// return left
-// }
-// if interval[0] <= root.Interval[0] {
-// root.Interval[0] = interval[1] + 1
-// }
-// if root.Interval[1] <= interval[1] {
-// root.Interval[1] = interval[0] - 1
-// }
-// return root
-// }
-
-// func (this *RangeModule) query(root *BSTNode, interval []int) bool {
-// if root == nil {
-// return false
-// }
-// if interval[1] < root.Interval[0] {
-// return query(root.Left, interval)
-// }
-// if root.Interval[1] < interval[0] {
-// return query(root.Right, interval)
-// }
-// left := true
-// if interval[0] < root.Interval[0] {
-// left = query(root.Left, []int{interval[0], root.Interval[0] - 1})
-// }
-// right := true
-// if root.Interval[1] < interval[1] {
-// right = query(root.Right, []int{root.Interval[1] + 1, interval[1]})
-// }
-// return left && right
-// }
-
-/**
- * Your RangeModule object will be instantiated and called as such:
- * obj := Constructor();
- * obj.AddRange(left,right);
- * param_2 := obj.QueryRange(left,right);
- * obj.RemoveRange(left,right);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0717.1-bit-and-2-bit-Characters.md b/website/content/ChapterFour/0717.1-bit-and-2-bit-Characters.md
deleted file mode 100755
index 499889244..000000000
--- a/website/content/ChapterFour/0717.1-bit-and-2-bit-Characters.md
+++ /dev/null
@@ -1,65 +0,0 @@
-# [717. 1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters/)
-
-
-## 题目:
-
-We have two special characters. The first character can be represented by one bit `0`. The second character can be represented by two bits (`10` or `11`).
-
-Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero.
-
-**Example 1**:
-
- Input:
- bits = [1, 0, 0]
- Output: True
- Explanation:
- The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.
-
-**Example 2**:
-
- Input:
- bits = [1, 1, 1, 0]
- Output: False
- Explanation:
- The only way to decode it is two-bit character and two-bit character. So the last character is NOT one-bit character.
-
-**Note**:
-
-- `1 <= len(bits) <= 1000`.
-- `bits[i]` is always `0` or `1`.
-
-## 题目大意
-
-有两种特殊字符。第一种字符可以用一比特0来表示。第二种字符可以用两比特(10 或 11)来表示。
-
-现给一个由若干比特组成的字符串。问最后一个字符是否必定为一个一比特字符。给定的字符串总是由0结束。
-
-注意:
-
-- 1 <= len(bits) <= 1000.
-- bits[i] 总是0 或 1.
-
-
-## 解题思路
-
-- 给出一个数组,数组里面的元素只有 0 和 1,并且数组的最后一个元素一定是 0。有 2 种特殊的字符,第一类字符是 "0",第二类字符是 "11" 和 "10",请判断这个数组最后一个元素是否一定是属于第一类字符?
-- 依题意, 0 的来源有 2 处,可以是第一类字符,也可以是第二类字符,1 的来源只有 1 处,一定出自第二类字符。最后一个 0 当前仅当为第一类字符的情况有 2 种,第一种情况,前面出现有 0,但是 0 和 1 配对形成了第二类字符。第二种情况,前面没有出现 0 。这两种情况的共同点是除去最后一个元素,数组中前面所有的1 都“结对子”。所以利用第二类字符的特征,"1X",遍历整个数组,如果遇到 "1",就跳 2 步,因为 1 后面出现什么数字( 0 或者 1 )并不需要关心。如果 `i` 能在 `len(bits) - 1` 的地方`(数组最后一个元素)`停下,那么对应的是情况一或者情况二,前面的 0 都和 1 匹配上了,最后一个 0 一定是第一类字符。如果 `i` 在 `len(bit)` 的位置`(超出数组下标)`停下,说明 `bits[len(bits) - 1] == 1`,这个时候最后一个 0 一定属于第二类字符。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func isOneBitCharacter(bits []int) bool {
- var i int
- for i = 0; i < len(bits)-1; i++ {
- if bits[i] == 1 {
- i++
- }
- }
- return i == len(bits)-1
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md b/website/content/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md
deleted file mode 100755
index eec248fe6..000000000
--- a/website/content/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md
+++ /dev/null
@@ -1,123 +0,0 @@
-# [718. Maximum Length of Repeated Subarray](https://leetcode.com/problems/maximum-length-of-repeated-subarray/)
-
-
-## 题目
-
-Given two integer arrays `A` and `B`, return the maximum length of an subarray that appears in both arrays.
-
-**Example 1**:
-
- Input:
- A: [1,2,3,2,1]
- B: [3,2,1,4,7]
- Output: 3
- Explanation:
- The repeated subarray with maximum length is [3, 2, 1].
-
-**Note**:
-
-1. 1 <= len(A), len(B) <= 1000
-2. 0 <= A[i], B[i] < 100
-
-
-## 题目大意
-
-给两个整数数组 A 和 B ,返回两个数组中公共的、长度最长的子数组的长度。
-
-
-
-## 解题思路
-
-- 给出两个数组,求这两个数组中最长相同子串的长度。
-- 这一题最容易想到的是 DP 动态规划的解法。`dp[i][j]` 代表在 A 数组中以 `i` 下标开始的子串与 B 数组中以 `j` 下标开始的子串最长相同子串的长度,状态转移方程为 `dp[i][j] = dp[i+1][j+1] + 1` (当 `A[i] == B[j]`)。这种解法的时间复杂度是 O(n^2),空间复杂度 O(n^2)。
-- 这一题最佳解法是二分搜索 + `Rabin-Karp`。比较相同子串耗时的地方在于,需要一层循环,遍历子串所有字符。但是如果比较两个数字就很快,`O(1)` 的时间复杂度。所以有人就想到了,能不能把字符串也映射成数字呢?这样比较起来就非常快。这个算法就是 `Rabin-Karp` 算法。字符串映射成一个数字不能随意映射,还要求能根据字符串前缀动态增加,比较下一个字符串的时候,可以利用已比较过的前缀,加速之后的字符串比较。在 Rabin-Karp 算法中有一个“码点”的概念。类似于10进制中的进制。具体的算法讲解可以见这篇:
-
- [基础知识 - Rabin-Karp 算法](https://www.cnblogs.com/golove/p/3234673.html)
-
- “码点”一般取值为一个素数。在 go 的 `strings` 包里面取值是 16777619。所以这一题也可以直接取这个值。由于这一次要求我们找最长长度,所以把最长长度作为二分搜索的目标。先将数组 A 和数组 B 中的数字都按照二分出来的长度,进行 `Rabin-Karp` hash。对 A 中的 hash 与下标做映射关系,存到 map 中,方便后面快速查找。然后遍历 B 中的 hash,当 hash 一致的时候,再匹配下标。如果下标存在,且拥有相同的前缀,那么就算找到了相同的子串了。最后就是不断的二分,找到最长的结果即可。这个解法的时间复杂度 O(n * log n),空间复杂度 O(n)。
-
-## 代码
-
-```go
-
-package leetcode
-
-const primeRK = 16777619
-
-// 解法一 二分搜索 + Rabin-Karp
-func findLength(A []int, B []int) int {
- low, high := 0, min(len(A), len(B))
- for low < high {
- mid := (low + high + 1) >> 1
- if hasRepeated(A, B, mid) {
- low = mid
- } else {
- high = mid - 1
- }
- }
- return low
-}
-
-func hashSlice(arr []int, length int) []int {
- // hash 数组里面记录 arr 比 length 长出去部分的 hash 值
- hash, pl, h := make([]int, len(arr)-length+1), 1, 0
- for i := 0; i < length-1; i++ {
- pl *= primeRK
- }
- for i, v := range arr {
- h = h*primeRK + v
- if i >= length-1 {
- hash[i-length+1] = h
- h -= pl * arr[i-length+1]
- }
- }
- return hash
-}
-
-func hasSamePrefix(A, B []int, length int) bool {
- for i := 0; i < length; i++ {
- if A[i] != B[i] {
- return false
- }
- }
- return true
-}
-
-func hasRepeated(A, B []int, length int) bool {
- hs := hashSlice(A, length)
- hashToOffset := make(map[int][]int, len(hs))
- for i, h := range hs {
- hashToOffset[h] = append(hashToOffset[h], i)
- }
- for i, h := range hashSlice(B, length) {
- if offsets, ok := hashToOffset[h]; ok {
- for _, offset := range offsets {
- if hasSamePrefix(A[offset:], B[i:], length) {
- return true
- }
- }
- }
- }
- return false
-}
-
-// 解法二 DP 动态规划
-func findLength1(A []int, B []int) int {
- res, dp := 0, make([][]int, len(A)+1)
- for i := range dp {
- dp[i] = make([]int, len(B)+1)
- }
- for i := len(A) - 1; i >= 0; i-- {
- for j := len(B) - 1; j >= 0; j-- {
- if A[i] == B[j] {
- dp[i][j] = dp[i+1][j+1] + 1
- if dp[i][j] > res {
- res = dp[i][j]
- }
- }
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0719.Find-K-th-Smallest-Pair-Distance.md b/website/content/ChapterFour/0719.Find-K-th-Smallest-Pair-Distance.md
deleted file mode 100755
index 836b8922a..000000000
--- a/website/content/ChapterFour/0719.Find-K-th-Smallest-Pair-Distance.md
+++ /dev/null
@@ -1,97 +0,0 @@
-# [719. Find K-th Smallest Pair Distance](https://leetcode.com/problems/find-k-th-smallest-pair-distance/)
-
-
-## 题目
-
-Given an integer array, return the k-th smallest **distance** among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B.
-
-**Example 1**:
-
- Input:
- nums = [1,3,1]
- k = 1
- Output: 0
- Explanation:
- Here are all the pairs:
- (1,3) -> 2
- (1,1) -> 0
- (3,1) -> 2
- Then the 1st smallest distance pair is (1,1), and its distance is 0.
-
-**Note**:
-
-1. `2 <= len(nums) <= 10000`.
-2. `0 <= nums[i] < 1000000`.
-3. `1 <= k <= len(nums) * (len(nums) - 1) / 2`.
-
-
-## 题目大意
-
-给定一个整数数组,返回所有数对之间的第 k 个最小距离。一对 (A, B) 的距离被定义为 A 和 B 之间的绝对差值。
-
-提示:
-
-1. 2 <= len(nums) <= 10000.
-2. 0 <= nums[i] < 1000000.
-3. 1 <= k <= len(nums) * (len(nums) - 1) / 2.
-
-
-
-## 解题思路
-
-- 给出一个数组,要求找出第 k 小两两元素之差的值。两两元素之差可能重复,重复的元素之差算多个,不去重。
-- 这一题可以用二分搜索来解答。先把原数组排序,那么最大的差值就是 `nums[len(nums)-1] - nums[0]` ,最小的差值是 0,即在 `[0, nums[len(nums)-1] - nums[0]]` 区间内搜索最终答案。针对每个 `mid`,判断小于等于 `mid` 的差值有多少个。题意就转化为,在数组中找到这样一个数,使得满足 `nums[i] - nums[j] ≤ mid` 条件的组合数等于 `k`。那么如何计算满足两两数的差值小于 mid 的组合总数是本题的关键。
-- 最暴力的方法就是 2 重循环,暴力计数。这个方法效率不高,耗时很长。原因是没有利用数组有序这一条件。实际上数组有序对计算满足条件的组合数有帮助。利用双指针滑动即可计算出组合总数。见解法一。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-func smallestDistancePair(nums []int, k int) int {
- sort.Ints(nums)
- low, high := 0, nums[len(nums)-1]-nums[0]
- for low < high {
- mid := low + (high-low)>>1
- tmp := findDistanceCount(nums, mid)
- if tmp >= k {
- high = mid
- } else {
- low = mid + 1
- }
- }
- return low
-}
-
-// 解法一 双指针
-func findDistanceCount(nums []int, num int) int {
- count, i := 0, 0
- for j := 1; j < len(nums); j++ {
- for nums[j]-nums[i] > num && i < j {
- i++
- }
- count += (j - i)
- }
- return count
-}
-
-// 解法二 暴力查找
-func findDistanceCount1(nums []int, num int) int {
- count := 0
- for i := 0; i < len(nums); i++ {
- for j := i + 1; j < len(nums); j++ {
- if nums[j]-nums[i] <= num {
- count++
- }
- }
- }
- return count
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0720.Longest-Word-in-Dictionary.md b/website/content/ChapterFour/0720.Longest-Word-in-Dictionary.md
deleted file mode 100755
index 8a70177f3..000000000
--- a/website/content/ChapterFour/0720.Longest-Word-in-Dictionary.md
+++ /dev/null
@@ -1,72 +0,0 @@
-# [720. Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary/)
-
-
-## 题目
-
-Given a list of strings `words` representing an English Dictionary, find the longest word in `words` that can be built one character at a time by other words in `words`. If there is more than one possible answer, return the longest word with the smallest lexicographical order.
-
-If there is no answer, return the empty string.
-
-**Example 1**:
-
- Input:
- words = ["w","wo","wor","worl", "world"]
- Output: "world"
- Explanation:
- The word "world" can be built one character at a time by "w", "wo", "wor", and "worl".
-
-**Example 2**:
-
- Input:
- words = ["a", "banana", "app", "appl", "ap", "apply", "apple"]
- Output: "apple"
- Explanation:
- Both "apply" and "apple" can be built from other words in the dictionary. However, "apple" is lexicographically smaller than "apply".
-
-**Note**:
-
-- All the strings in the input will only contain lowercase letters.
-- The length of `words` will be in the range `[1, 1000]`.
-- The length of `words[i]` will be in the range `[1, 30]`.
-
-
-## 题目大意
-
-给出一个字符串数组 words 组成的一本英语词典。从中找出最长的一个单词,该单词是由 words 词典中其他单词逐步添加一个字母组成。若其中有多个可行的答案,则返回答案中字典序最小的单词。若无答案,则返回空字符串。
-
-
-
-## 解题思路
-
-
-- 给出一个字符串数组,要求找到长度最长的,并且可以由字符串数组里面其他字符串拼接一个字符组成的字符串。如果存在多个这样的最长的字符串,则输出字典序较小的那个字符串,如果找不到这样的字符串,输出空字符串。
-- 这道题解题思路是先排序,排序完成以后就是字典序从小到大了。之后再用 map 辅助记录即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-func longestWord(words []string) string {
- sort.Strings(words)
- mp := make(map[string]bool)
- var res string
- for _, word := range words {
- size := len(word)
- if size == 1 || mp[word[:size-1]] {
- if size > len(res) {
- res = word
- }
- mp[word] = true
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0721.Accounts-Merge.md b/website/content/ChapterFour/0721.Accounts-Merge.md
deleted file mode 100755
index 352343d96..000000000
--- a/website/content/ChapterFour/0721.Accounts-Merge.md
+++ /dev/null
@@ -1,149 +0,0 @@
-# [721. Accounts Merge](https://leetcode.com/problems/accounts-merge/)
-
-
-## 题目
-
-Given a list `accounts`, each element `accounts[i]` is a list of strings, where the first element `accounts[i][0]` is a name, and the rest of the elements are emailsrepresenting emails of the account.
-
-Now, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some email that is common to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.
-
-After merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails **in sorted order**. The accounts themselves can be returned in any order.
-
-**Example 1**:
-
- Input:
- accounts = [["John", "johnsmith@mail.com", "john00@mail.com"], ["John", "johnnybravo@mail.com"], ["John", "johnsmith@mail.com", "john_newyork@mail.com"], ["Mary", "mary@mail.com"]]
- Output: [["John", 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com'], ["John", "johnnybravo@mail.com"], ["Mary", "mary@mail.com"]]
- Explanation:
- The first and third John's are the same person as they have the common email "johnsmith@mail.com".
- The second John and Mary are different people as none of their email addresses are used by other accounts.
- We could return these lists in any order, for example the answer [['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com'],
- ['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com']] would still be accepted.
-
-**Note**:
-
-- The length of `accounts` will be in the range `[1, 1000]`.
-- The length of `accounts[i]` will be in the range `[1, 10]`.
-- The length of `accounts[i][j]` will be in the range `[1, 30]`.
-
-
-## 题目大意
-
-
-给定一个列表 accounts,每个元素 accounts[i] 是一个字符串列表,其中第一个元素 accounts[i][0] 是 名称 (name),其余元素是 emails 表示该帐户的邮箱地址。现在,我们想合并这些帐户。如果两个帐户都有一些共同的邮件地址,则两个帐户必定属于同一个人。请注意,即使两个帐户具有相同的名称,它们也可能属于不同的人,因为人们可能具有相同的名称。一个人最初可以拥有任意数量的帐户,但其所有帐户都具有相同的名称。合并帐户后,按以下格式返回帐户:每个帐户的第一个元素是名称,其余元素是按顺序排列的邮箱地址。accounts 本身可以以任意顺序返回。
-
-
-注意:
-
-- accounts 的长度将在 [1,1000] 的范围内。
-- accounts[i] 的长度将在 [1,10] 的范围内。
-- accounts[i][j] 的长度将在 [1,30] 的范围内。
-
-
-
-## 解题思路
-
-
-- 给出一堆账户和对应的邮箱。要求合并同一个人的多个邮箱账户。如果判断是同一个人呢?如果这个人名和所属的其中之一的邮箱是相同的,就判定这是同一个人的邮箱,那么就合并这些邮箱。
-- 这题的解题思路是并查集。不过如果用暴力合并的方法,时间复杂度非常差。优化方法是先把每组数据都进行编号,人编号,每个邮箱都进行编号。这个映射关系用 `map` 记录起来。如果利用并查集的 `union()` 操作,把这些编号都进行合并。最后把人的编号和对应邮箱的编号拼接起来。
-- 这一题有 2 处比较“坑”的是,不需要合并的用户的邮箱列表也是需要排序和去重的,同一个人的所有邮箱集合都要合并到一起。具体见测试用例。不过题目中也提到了这些点,也不能算题目坑,只能归自己没注意这些边界情况。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-// 解法一 并查集优化搜索解法
-func accountsMerge(accounts [][]string) (r [][]string) {
- uf := template.UnionFind{}
- uf.Init(len(accounts))
- // emailToID 将所有的 email 邮箱都拆开,拆开与 id(数组下标) 对应
- // idToName 将 id(数组下标) 与 name 对应
- // idToEmails 将 id(数组下标) 与整理好去重以后的 email 组对应
- emailToID, idToName, idToEmails, res := make(map[string]int), make(map[int]string), make(map[int][]string), [][]string{}
- for id, acc := range accounts {
- idToName[id] = acc[0]
- for i := 1; i < len(acc); i++ {
- pid, ok := emailToID[acc[i]]
- if ok {
- uf.Union(id, pid)
- }
- emailToID[acc[i]] = id
- }
- }
- for email, id := range emailToID {
- pid := uf.Find(id)
- idToEmails[pid] = append(idToEmails[pid], email)
- }
- for id, emails := range idToEmails {
- name := idToName[id]
- sort.Strings(emails)
- res = append(res, append([]string{name}, emails...))
- }
- return res
-}
-
-// 解法二 并查集暴力解法
-func accountsMerge1(accounts [][]string) [][]string {
- if len(accounts) == 0 {
- return [][]string{}
- }
- uf, res, visited := template.UnionFind{}, [][]string{}, map[int]bool{}
- uf.Init(len(accounts))
- for i := 0; i < len(accounts); i++ {
- for j := i + 1; j < len(accounts); j++ {
- if accounts[i][0] == accounts[j][0] {
- tmpA, tmpB, flag := accounts[i][1:], accounts[j][1:], false
- for j := 0; j < len(tmpA); j++ {
- for k := 0; k < len(tmpB); k++ {
- if tmpA[j] == tmpB[k] {
- flag = true
- break
- }
- }
- if flag {
- break
- }
- }
- if flag {
- uf.Union(i, j)
- }
- }
- }
- }
- for i := 0; i < len(accounts); i++ {
- if visited[i] {
- continue
- }
- emails, account, tmpMap := accounts[i][1:], []string{accounts[i][0]}, map[string]string{}
- for j := i + 1; j < len(accounts); j++ {
- if uf.Find(j) == uf.Find(i) {
- visited[j] = true
- for _, v := range accounts[j][1:] {
- tmpMap[v] = v
- }
- }
- }
- for _, v := range emails {
- tmpMap[v] = v
- }
- emails = []string{}
- for key := range tmpMap {
- emails = append(emails, key)
- }
- sort.Strings(emails)
- account = append(account, emails...)
- res = append(res, account)
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0724.Find-Pivot-Index.md b/website/content/ChapterFour/0724.Find-Pivot-Index.md
deleted file mode 100644
index 1e93cf475..000000000
--- a/website/content/ChapterFour/0724.Find-Pivot-Index.md
+++ /dev/null
@@ -1,74 +0,0 @@
-# [724. Find Pivot Index](https://leetcode.com/problems/find-pivot-index/)
-
-
-## 题目
-
-Given an array of integers nums, write a method that returns the "pivot" index of this array.
-
-We define the pivot index as the index where the sum of all the numbers to the left of the index is equal to the sum of all the numbers to the right of the index.
-
-If no such index exists, we should return -1. If there are multiple pivot indexes, you should return the left-most pivot index.
-
-
-
-**Example 1**:
-
- Input: nums = [1,7,3,6,5,6]
- Output: 3
- Explanation:
- The sum of the numbers to the left of index 3 (nums[3] = 6) is equal to the sum of numbers to the right of index 3.
- Also, 3 is the first index where this occurs.
-
-**Example 2**:
-
- Input: nums = [1,2,3]
- Output: -1
- Explanation:
- There is no index that satisfies the conditions in the problem statement.
-
-**Constraints**:
-
-- The length of nums will be in the range [0, 10000].
-- Each element nums[i] will be an integer in the range [-1000, 1000].
-
-
-
-## 题目大意
-
-给定一个整数类型的数组 nums,请编写一个能够返回数组 “中心索引” 的方法。我们是这样定义数组 中心索引 的:数组中心索引的左侧所有元素相加的和等于右侧所有元素相加的和。如果数组不存在中心索引,那么我们应该返回 -1。如果数组有多个中心索引,那么我们应该返回最靠近左边的那一个。
-
-
-
-## 解题思路
-
-- 在数组中,找到一个数,使得它左边的数之和等于它的右边的数之和,如果存在,则返回这个数的下标索引,否作返回 -1。
-- 这里面存在一个等式,只需要满足这个等式即可满足条件:leftSum + num[i] = sum - leftSum => 2 * leftSum + num[i] = sum。
-- 题目提到如果存在多个索引,则返回最左边那个,因此从左开始求和,而不是从右边。
-
-## 代码
-
-```go
-
-package leetcode
-
-// 2 * leftSum + num[i] = sum
-// 时间: O(n)
-// 空间: O(1)
-func pivotIndex(nums []int) int {
- if len(nums) <= 0 {
- return -1
- }
- var sum, leftSum int
- for _, num := range nums {
- sum += num
- }
- for index, num := range nums {
- if leftSum*2+num == sum {
- return index
- }
- leftSum += num
- }
- return -1
-}
-
-```
diff --git a/website/content/ChapterFour/0726.Number-of-Atoms.md b/website/content/ChapterFour/0726.Number-of-Atoms.md
deleted file mode 100755
index a9d3cf4a7..000000000
--- a/website/content/ChapterFour/0726.Number-of-Atoms.md
+++ /dev/null
@@ -1,186 +0,0 @@
-# [726. Number of Atoms](https://leetcode.com/problems/number-of-atoms/)
-
-
-## 题目
-
-Given a chemical `formula` (given as a string), return the count of each atom.
-
-An atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.
-
-1 or more digits representing the count of that element may follow if the count is greater than 1. If the count is 1, no digits will follow. For example, H2O and H2O2 are possible, but H1O2 is impossible.
-
-Two formulas concatenated together produce another formula. For example, H2O2He3Mg4 is also a formula.
-
-A formula placed in parentheses, and a count (optionally added) is also a formula. For example, (H2O2) and (H2O2)3 are formulas.
-
-Given a formula, output the count of all elements as a string in the following form: the first name (in sorted order), followed by its count (if that count is more than 1), followed by the second name (in sorted order), followed by its count (if that count is more than 1), and so on.
-
-**Example 1**:
-
- Input:
- formula = "H2O"
- Output: "H2O"
- Explanation:
- The count of elements are {'H': 2, 'O': 1}.
-
-**Example 2**:
-
- Input:
- formula = "Mg(OH)2"
- Output: "H2MgO2"
- Explanation:
- The count of elements are {'H': 2, 'Mg': 1, 'O': 2}.
-
-**Example 3**:
-
- Input:
- formula = "K4(ON(SO3)2)2"
- Output: "K4N2O14S4"
- Explanation:
- The count of elements are {'K': 4, 'N': 2, 'O': 14, 'S': 4}.
-
-**Note**:
-
-- All atom names consist of lowercase letters, except for the first character which is uppercase.
-- The length of `formula` will be in the range `[1, 1000]`.
-- `formula` will only consist of letters, digits, and round parentheses, and is a valid formula as defined in the problem.
-
-
-## 题目大意
-
-给定一个化学式,输出所有原子的数量。格式为:第一个(按字典序)原子的名子,跟着它的数量(如果数量大于 1),然后是第二个原子的名字(按字典序),跟着它的数量(如果数量大于 1),以此类推。
-
-原子总是以一个大写字母开始,接着跟随0个或任意个小写字母,表示原子的名字。如果数量大于 1,原子后会跟着数字表示原子的数量。如果数量等于 1 则不会跟数字。例如,H2O 和 H2O2 是可行的,但 H1O2 这个表达是不可行的。两个化学式连在一起是新的化学式。例如 H2O2He3Mg4 也是化学式。一个括号中的化学式和数字(可选择性添加)也是化学式。例如 (H2O2) 和 (H2O2)3 是化学式。
-
-
-
-## 解题思路
-
-
-- 利用栈处理每个化学元素,用 map 记录每个化学元素的个数,最终排序以后输出即可
-- 注意化学元素有些并不是单一字母,比如镁元素是 Mg,所以需要考虑字母的大小写问题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
- "strconv"
- "strings"
-)
-
-type atom struct {
- name string
- cnt int
-}
-
-type atoms []atom
-
-func (this atoms) Len() int { return len(this) }
-func (this atoms) Less(i, j int) bool { return strings.Compare(this[i].name, this[j].name) < 0 }
-func (this atoms) Swap(i, j int) { this[i], this[j] = this[j], this[i] }
-func (this atoms) String() string {
- s := ""
- for _, a := range this {
- s += a.name
- if a.cnt > 1 {
- s += strconv.Itoa(a.cnt)
- }
- }
- return s
-}
-
-func countOfAtoms(s string) string {
- n := len(s)
- if n == 0 {
- return ""
- }
-
- stack := make([]string, 0)
- for i := 0; i < n; i++ {
- c := s[i]
- if c == '(' || c == ')' {
- stack = append(stack, string(c))
- } else if isUpperLetter(c) {
- j := i + 1
- for ; j < n; j++ {
- if !isLowerLetter(s[j]) {
- break
- }
- }
- stack = append(stack, s[i:j])
- i = j - 1
- } else if isDigital(c) {
- j := i + 1
- for ; j < n; j++ {
- if !isDigital(s[j]) {
- break
- }
- }
- stack = append(stack, s[i:j])
- i = j - 1
- }
- }
-
- cnt, deep := make([]map[string]int, 100), 0
- for i := 0; i < 100; i++ {
- cnt[i] = make(map[string]int)
- }
- for i := 0; i < len(stack); i++ {
- t := stack[i]
- if isUpperLetter(t[0]) {
- num := 1
- if i+1 < len(stack) && isDigital(stack[i+1][0]) {
- num, _ = strconv.Atoi(stack[i+1])
- i++
- }
- cnt[deep][t] += num
- } else if t == "(" {
- deep++
- } else if t == ")" {
- num := 1
- if i+1 < len(stack) && isDigital(stack[i+1][0]) {
- num, _ = strconv.Atoi(stack[i+1])
- i++
- }
- for k, v := range cnt[deep] {
- cnt[deep-1][k] += v * num
- }
- cnt[deep] = make(map[string]int)
- deep--
- }
- }
- as := atoms{}
- for k, v := range cnt[0] {
- as = append(as, atom{name: k, cnt: v})
- }
- sort.Sort(as)
- return as.String()
-}
-
-func isDigital(v byte) bool {
- if v >= '0' && v <= '9' {
- return true
- }
- return false
-}
-
-func isUpperLetter(v byte) bool {
- if v >= 'A' && v <= 'Z' {
- return true
- }
- return false
-}
-
-func isLowerLetter(v byte) bool {
- if v >= 'a' && v <= 'z' {
- return true
- }
- return false
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0729.My-Calendar-I.md b/website/content/ChapterFour/0729.My-Calendar-I.md
deleted file mode 100755
index bc957abac..000000000
--- a/website/content/ChapterFour/0729.My-Calendar-I.md
+++ /dev/null
@@ -1,180 +0,0 @@
-# [729. My Calendar I](https://leetcode.com/problems/my-calendar-i/)
-
-
-## 题目
-
-Implement a `MyCalendar` class to store your events. A new event can be added if adding the event will not cause a double booking.
-
-Your class will have the method, `book(int start, int end)`. Formally, this represents a booking on the half open interval `[start, end)`, the range of real numbers `x` such that `start <= x < end`.
-
-A double booking happens when two events have some non-empty intersection (ie., there is some time that is common to both events.)
-
-For each call to the method `MyCalendar.book`, return `true` if the event can be added to the calendar successfully without causing a double booking. Otherwise, return `false` and do not add the event to the calendar.
-
-Your class will be called like this:
-
-`MyCalendar cal = new MyCalendar();`
-
-`MyCalendar.book(start, end)`
-
-**Example 1**:
-
- MyCalendar();
- MyCalendar.book(10, 20); // returns true
- MyCalendar.book(15, 25); // returns false
- MyCalendar.book(20, 30); // returns true
- Explanation:
- The first event can be booked. The second can't because time 15 is already booked by another event.
- The third event can be booked, as the first event takes every time less than 20, but not including 20.
-
-**Note**:
-
-- The number of calls to `MyCalendar.book` per test case will be at most `1000`.
-- In calls to `MyCalendar.book(start, end)`, `start` and `end` are integers in the range `[0, 10^9]`.
-
-
-
-## 题目大意
-
-实现一个 MyCalendar 类来存放你的日程安排。如果要添加的时间内没有其他安排,则可以存储这个新的日程安排。
-
-MyCalendar 有一个 book(int start, int end) 方法。它意味着在 start 到 end 时间内增加一个日程安排,注意,这里的时间是半开区间,即 [start, end), 实数 x 的范围为, start <= x < end。
-
-当两个日程安排有一些时间上的交叉时(例如两个日程安排都在同一时间内),就会产生重复预订。
-
-每次调用 MyCalendar.book 方法时,如果可以将日程安排成功添加到日历中而不会导致重复预订,返回 true。否则,返回 false 并且不要将该日程安排添加到日历中。
-
-请按照以下步骤调用 MyCalendar 类: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)
-
-说明:
-
-- 每个测试用例,调用 MyCalendar.book 函数最多不超过 100次。
-- 调用函数 MyCalendar.book(start, end) 时, start 和 end 的取值范围为 [0, 10^9]。
-
-
-## 解题思路
-
-
-- 要求实现一个日程安排的功能,如果有日程安排冲突了,就返回 false,如果不冲突则返回 ture
-- 这一题有多种解法,第一种解法可以用类似第 34 题的解法。先排序每个区间,然后再这个集合中用二分搜索找到最后一个区间的左值比当前要比较的区间左值小的,如果找到,再判断能否插入进去(判断右区间是否比下一个区间的左区间小),此方法时间复杂度 O(n log n)
-- 第二种解法是用生成一个 BST 树。在插入树中先排除不能插入的情况,例如区间有重合。然后以区间左值为依据,递归插入,每次插入依次会继续判断区间是否重合。直到不能插入,则返回 fasle。整个查找的时间复杂度是 O(log n)。
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 二叉排序树
-// Event define
-type Event struct {
- start, end int
- left, right *Event
-}
-
-// Insert define
-func (e *Event) Insert(curr *Event) bool {
- if e.end > curr.start && curr.end > e.start {
- return false
- }
- if curr.start < e.start {
- if e.left == nil {
- e.left = curr
- } else {
- return e.left.Insert(curr)
- }
- } else {
- if e.right == nil {
- e.right = curr
- } else {
- return e.right.Insert(curr)
- }
- }
- return true
-}
-
-// MyCalendar define
-type MyCalendar struct {
- root *Event
-}
-
-// Constructor729 define
-func Constructor729() MyCalendar {
- return MyCalendar{
- root: nil,
- }
-}
-
-// Book define
-func (this *MyCalendar) Book(start int, end int) bool {
- curr := &Event{start: start, end: end, left: nil, right: nil}
- if this.root == nil {
- this.root = curr
- return true
- }
- return this.root.Insert(curr)
-}
-
-// 解法二 快排 + 二分
-// MyCalendar define
-// type MyCalendar struct {
-// calendar []Interval
-// }
-
-// // Constructor729 define
-// func Constructor729() MyCalendar {
-// calendar := []Interval{}
-// return MyCalendar{calendar: calendar}
-// }
-
-// // Book define
-// func (this *MyCalendar) Book(start int, end int) bool {
-// if len(this.calendar) == 0 {
-// this.calendar = append(this.calendar, Interval{Start: start, End: end})
-// return true
-// }
-// // 快排
-// quickSort(this.calendar, 0, len(this.calendar)-1)
-// // 二分
-// pos := searchLastLessInterval(this.calendar, start, end)
-// // 如果找到最后一个元素,需要判断 end
-// if pos == len(this.calendar)-1 && this.calendar[pos].End <= start {
-// this.calendar = append(this.calendar, Interval{Start: start, End: end})
-// return true
-// }
-// // 如果不是开头和结尾的元素,还需要判断这个区间是否能插入到原数组中(要看起点和终点是否都能插入)
-// if pos != len(this.calendar)-1 && pos != -1 && this.calendar[pos].End <= start && this.calendar[pos+1].Start >= end {
-// this.calendar = append(this.calendar, Interval{Start: start, End: end})
-// return true
-// }
-// // 如果元素比开头的元素还要小,要插入到开头
-// if this.calendar[0].Start >= end {
-// this.calendar = append(this.calendar, Interval{Start: start, End: end})
-// return true
-// }
-// return false
-// }
-
-// func searchLastLessInterval(intervals []Interval, start, end int) int {
-// low, high := 0, len(intervals)-1
-// for low <= high {
-// mid := low + ((high - low) >> 1)
-// if intervals[mid].Start <= start {
-// if (mid == len(intervals)-1) || (intervals[mid+1].Start > start) { // 找到最后一个小于等于 target 的元素
-// return mid
-// }
-// low = mid + 1
-// } else {
-// high = mid - 1
-// }
-// }
-// return -1
-// }
-
-/**
- * Your MyCalendar object will be instantiated and called as such:
- * obj := Constructor();
- * param_1 := obj.Book(start,end);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0732.My-Calendar-III.md b/website/content/ChapterFour/0732.My-Calendar-III.md
deleted file mode 100755
index 5b953911a..000000000
--- a/website/content/ChapterFour/0732.My-Calendar-III.md
+++ /dev/null
@@ -1,142 +0,0 @@
-# [732. My Calendar III](https://leetcode.com/problems/my-calendar-iii/)
-
-
-## 题目
-
-Implement a `MyCalendarThree` class to store your events. A new event can **always** be added.
-
-Your class will have one method, `book(int start, int end)`. Formally, this represents a booking on the half open interval `[start, end)`, the range of real numbers `x` such that `start <= x < end`.
-
-A K-booking happens when **K** events have some non-empty intersection (ie., there is some time that is common to all K events.)
-
-For each call to the method `MyCalendar.book`, return an integer `K` representing the largest integer such that there exists a `K`-booking in the calendar.
-
-Your class will be called like this:
-
-`MyCalendarThree cal = new MyCalendarThree();`
-
-`MyCalendarThree.book(start, end)`
-
-**Example 1**:
-
- MyCalendarThree();
- MyCalendarThree.book(10, 20); // returns 1
- MyCalendarThree.book(50, 60); // returns 1
- MyCalendarThree.book(10, 40); // returns 2
- MyCalendarThree.book(5, 15); // returns 3
- MyCalendarThree.book(5, 10); // returns 3
- MyCalendarThree.book(25, 55); // returns 3
- Explanation:
- The first two events can be booked and are disjoint, so the maximum K-booking is a 1-booking.
- The third event [10, 40) intersects the first event, and the maximum K-booking is a 2-booking.
- The remaining events cause the maximum K-booking to be only a 3-booking.
- Note that the last event locally causes a 2-booking, but the answer is still 3 because
- eg. [10, 20), [10, 40), and [5, 15) are still triple booked.
-
-**Note**:
-
-- The number of calls to `MyCalendarThree.book` per test case will be at most `400`.
-- In calls to `MyCalendarThree.book(start, end)`, `start` and `end` are integers in the range `[0, 10^9]`.
-
-
-## 题目大意
-
-实现一个 MyCalendar 类来存放你的日程安排,你可以一直添加新的日程安排。
-
-MyCalendar 有一个 book(int start, int end)方法。它意味着在start到end时间内增加一个日程安排,注意,这里的时间是半开区间,即 [start, end), 实数 x 的范围为, start <= x < end。当 K 个日程安排有一些时间上的交叉时(例如K个日程安排都在同一时间内),就会产生 K 次预订。每次调用 MyCalendar.book方法时,返回一个整数 K ,表示最大的 K 次预订。
-
-请按照以下步骤调用MyCalendar 类: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)
-
-说明:
-
-- 每个测试用例,调用 MyCalendar.book 函数最多不超过 400 次。
-- 调用函数 MyCalendar.book(start, end)时, start 和 end 的取值范围为 [0, 10^9]。
-
-
-
-
-## 解题思路
-
-- 设计一个日程类,每添加一个日程,实时显示出当前排期中累计日程最多的个数,例如在一段时间内,排了 3 个日程,其他时间内都只有 0,1,2 个日程,则输出 3 。
-- 拿到这个题目以后会立即想到线段树。由于题目中只有增加日程,所以这一题难度不大。这一题和第 699 题也类似,但是有区别,第 699 题中,俄罗斯方块会依次摞起来,而这一题中,俄罗斯方块也就摞起来,但是方块下面如果是空挡,方块会断掉。举个例子:依次增加区间 [10,20],[10,40],[5,15],[5,10],如果是第 699 题的规则,这 [5,10] 的这块砖块会落在 [5,15] 上,从而使得高度为 4,但是这一题是日程,日程不一样,[5,15] 这个区间内有 3 个日程,但是其他部分都没有 3 个日程,所以第三块砖块 [5,15] 中的 [5,10] 会“断裂”,掉下去,第四块砖块还是 [5,10],落在第三块砖块断落下去的位置,它们俩落在一起的高度是 2 。
-- 构造一颗线段树,这里用树来构造,如果用数组需要开辟很大的空间。当区间左右边界和查询边界完全相同的时候再累加技术,否则不加,继续划分区间。以区间的左边界作为划分区间的标准,因为区间左边界是开区间,右边是闭区间。一个区间的计数值以区间左边界的计数为准。还是上面的例子,[5,10) 计数以 5 为标准,count = 2,[10,15) 计数以 10 为标准,count = 3 。还需要再动态维护一个最大值。这个线段树的实现比较简单。
-- 类似的题目有:第 715 题,第 218 题,第 699 题。第 715 题是区间更新定值(**不是增减**),第 218 题可以用扫描线,第 732 题和第 699 题类似,也是俄罗斯方块的题目,但是第 732 题的俄罗斯方块的方块会“断裂”。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// SegmentTree732 define
-type SegmentTree732 struct {
- start, end, count int
- left, right *SegmentTree732
-}
-
-// MyCalendarThree define
-type MyCalendarThree struct {
- st *SegmentTree732
- maxHeight int
-}
-
-// Constructor732 define
-func Constructor732() MyCalendarThree {
- st := &SegmentTree732{
- start: 0,
- end: 1e9,
- }
- return MyCalendarThree{
- st: st,
- }
-}
-
-// Book define
-func (mct *MyCalendarThree) Book(start int, end int) int {
- mct.st.book(start, end, &mct.maxHeight)
- return mct.maxHeight
-}
-
-func (st *SegmentTree732) book(start, end int, maxHeight *int) {
- if start == end {
- return
- }
- if start == st.start && st.end == end {
- st.count++
- if st.count > *maxHeight {
- *maxHeight = st.count
- }
- if st.left == nil {
- return
- }
- }
- if st.left == nil {
- if start == st.start {
- st.left = &SegmentTree732{start: start, end: end, count: st.count}
- st.right = &SegmentTree732{start: end, end: st.end, count: st.count}
- st.left.book(start, end, maxHeight)
- return
- }
- st.left = &SegmentTree732{start: st.start, end: start, count: st.count}
- st.right = &SegmentTree732{start: start, end: st.end, count: st.count}
- st.right.book(start, end, maxHeight)
- return
- }
- if start >= st.right.start {
- st.right.book(start, end, maxHeight)
- } else if end <= st.left.end {
- st.left.book(start, end, maxHeight)
- } else {
- st.left.book(start, st.left.end, maxHeight)
- st.right.book(st.right.start, end, maxHeight)
- }
-}
-
-/**
- * Your MyCalendarThree object will be instantiated and called as such:
- * obj := Constructor();
- * param_1 := obj.Book(start,end);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0733.Flood-Fill.md b/website/content/ChapterFour/0733.Flood-Fill.md
deleted file mode 100755
index 8fd2bba3f..000000000
--- a/website/content/ChapterFour/0733.Flood-Fill.md
+++ /dev/null
@@ -1,81 +0,0 @@
-# [733. Flood Fill](https://leetcode.com/problems/flood-fill/)
-
-
-## 题目
-
-An `image` is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).
-
-Given a coordinate `(sr, sc)` representing the starting pixel (row and column) of the flood fill, and a pixel value `newColor`, "flood fill" the image.
-
-To perform a "flood fill", consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color as the starting pixel), and so on. Replace the color of all of the aforementioned pixels with the newColor.
-
-At the end, return the modified image.
-
-**Example 1**:
-
- Input:
- image = [[1,1,1],[1,1,0],[1,0,1]]
- sr = 1, sc = 1, newColor = 2
- Output: [[2,2,2],[2,2,0],[2,0,1]]
- Explanation:
- From the center of the image (with position (sr, sc) = (1, 1)), all pixels connected
- by a path of the same color as the starting pixel are colored with the new color.
- Note the bottom corner is not colored 2, because it is not 4-directionally connected
- to the starting pixel.
-
-**Note**:
-
-- The length of `image` and `image[0]` will be in the range `[1, 50]`.
-- The given starting pixel will satisfy `0 <= sr < image.length` and `0 <= sc < image[0].length`.
-- The value of each color in `image[i][j]` and `newColor` will be an integer in `[0, 65535]`.
-
-
-## 题目大意
-
-有一幅以二维整数数组表示的图画,每一个整数表示该图画的像素值大小,数值在 0 到 65535 之间。给你一个坐标 (sr, sc) 表示图像渲染开始的像素值(行 ,列)和一个新的颜色值 newColor,让你重新上色这幅图像。
-
-为了完成上色工作,从初始坐标开始,记录初始坐标的上下左右四个方向上像素值与初始坐标相同的相连像素点,接着再记录这四个方向上符合条件的像素点与他们对应四个方向上像素值与初始坐标相同的相连像素点,……,重复该过程。将所有有记录的像素点的颜色值改为新的颜色值。最后返回经过上色渲染后的图像。
-
-注意:
-
-- image 和 image[0] 的长度在范围 [1, 50] 内。
-- 给出的初始点将满足 0 <= sr < image.length 和 0 <= sc < image[0].length。
-- image[i][j] 和 newColor 表示的颜色值在范围 [0, 65535]内。
-
-
-## 解题思路
-
-
-- 给出一个二维的图片点阵,每个点阵都有一个数字。给出一个起点坐标,要求从这个起点坐标开始,把所有与这个起点连通的点都染色成 newColor。
-- 这一题是标准的 Flood Fill 算法。可以用 DFS 也可以用 BFS 。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func floodFill(image [][]int, sr int, sc int, newColor int) [][]int {
- color := image[sr][sc]
- if newColor == color {
- return image
- }
- dfs733(image, sr, sc, newColor)
- return image
-}
-
-func dfs733(image [][]int, x, y int, newColor int) {
- if image[x][y] == newColor {
- return
- }
- oldColor := image[x][y]
- image[x][y] = newColor
- for i := 0; i < 4; i++ {
- if (x+dir[i][0] >= 0 && x+dir[i][0] < len(image)) && (y+dir[i][1] >= 0 && y+dir[i][1] < len(image[0])) && image[x+dir[i][0]][y+dir[i][1]] == oldColor {
- dfs733(image, x+dir[i][0], y+dir[i][1], newColor)
- }
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0735.Asteroid-Collision.md b/website/content/ChapterFour/0735.Asteroid-Collision.md
deleted file mode 100644
index 2db714471..000000000
--- a/website/content/ChapterFour/0735.Asteroid-Collision.md
+++ /dev/null
@@ -1,105 +0,0 @@
-# [735. Asteroid Collision](https://leetcode.com/problems/asteroid-collision/)
-
-## 题目
-
-We are given an array asteroids of integers representing asteroids in a row.
-
-For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.
-
-Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.
-
-**Example 1**:
-
-```
-
-Input:
-asteroids = [5, 10, -5]
-Output: [5, 10]
-Explanation:
-The 10 and -5 collide resulting in 10. The 5 and 10 never collide.
-
-```
-
-**Example 2**:
-
-```
-
-Input:
-asteroids = [8, -8]
-Output: []
-Explanation:
-The 8 and -8 collide exploding each other.
-
-```
-
-**Example 3**:
-
-```
-
-Input:
-asteroids = [10, 2, -5]
-Output: [10]
-Explanation:
-The 2 and -5 collide resulting in -5. The 10 and -5 collide resulting in 10.
-
-```
-
-**Example 4**:
-
-```
-
-Input:
-asteroids = [-2, -1, 1, 2]
-Output: [-2, -1, 1, 2]
-Explanation:
-The -2 and -1 are moving left, while the 1 and 2 are moving right.
-Asteroids moving the same direction never meet, so no asteroids will meet each other.
-
-```
-
-**Note**:
-
-- The length of asteroids will be at most 10000.
-- Each asteroid will be a non-zero integer in the range [-1000, 1000]..
-
-## 题目大意
-
-给定一个整数数组 asteroids,表示在同一行的行星。对于数组中的每一个元素,其绝对值表示行星的大小,正负表示行星的移动方向(正表示向右移动,负表示向左移动)。每一颗行星以相同的速度移动。找出碰撞后剩下的所有行星。碰撞规则:两个行星相互碰撞,较小的行星会爆炸。如果两颗行星大小相同,则两颗行星都会爆炸。两颗移动方向相同的行星,永远不会发生碰撞。
-
-## 解题思路
-
-这一题类似第 1047 题。这也是一个类似“对对碰”的游戏,不过这里的碰撞,大行星和小行星碰撞以后,大行星会胜出,小行星直接消失。按照题意的规则来,用栈模拟即可。考虑最终结果:
-
-1. 所有向左飞的行星都向左,所有向右飞的行星都向右。
-2. 向左飞的行星,如果飞行中没有向右飞行的行星,那么它将安全穿过。
-3. 跟踪所有向右移动到右侧的行星,最右边的一个将是第一个面对向左飞行行星碰撞的。
-4. 如果它幸存下来,继续前进,否则,任何之前的向右的行星都会被逐一被暴露出来碰撞。
-
-所以先处理这种情况,一层循环把所有能碰撞的向右飞行的行星都碰撞完。碰撞完以后,如果栈顶行星向左飞,新来的行星向右飞,直接添加进来即可。否则栈顶行星向右飞,大小和向左飞的行星一样大小,两者都撞毁灭,弹出栈顶元素。
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func asteroidCollision(asteroids []int) []int {
- res := []int{}
- for _, v := range asteroids {
- for len(res) != 0 && res[len(res)-1] > 0 && res[len(res)-1] < -v {
- res = res[:len(res)-1]
- }
- if len(res) == 0 || v > 0 || res[len(res)-1] < 0 {
- res = append(res, v)
- } else if v < 0 && res[len(res)-1] == -v {
- res = res[:len(res)-1]
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0739.Daily-Temperatures.md b/website/content/ChapterFour/0739.Daily-Temperatures.md
deleted file mode 100644
index 9fef4be8f..000000000
--- a/website/content/ChapterFour/0739.Daily-Temperatures.md
+++ /dev/null
@@ -1,59 +0,0 @@
-# [739. Daily Temperatures](https://leetcode.com/problems/daily-temperatures/)
-
-## 题目
-
-
-Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.
-
-For example, given the list of temperatures T = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0].
-
-**Note**: The length of temperatures will be in the range [1, 30000]. Each temperature will be an integer in the range [30, 100].
-
-
-## 题目大意
-
-给出一个温度数组,要求输出比当天温度高的在未来的哪一天,输出未来第几天的天数。例如比 73 度高的在未来第 1 天出现,比 75 度高的在未来第 4 天出现。
-
-## 解题思路
-
-这道题根据题意正常处理就可以了。2 层循环。另外一种做法是单调栈,维护一个单调递减的单调栈即可。
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 普通做法
-func dailyTemperatures(T []int) []int {
- res, j := make([]int, len(T)), 0
- for i := 0; i < len(T); i++ {
- for j = i + 1; j < len(T); j++ {
- if T[j] > T[i] {
- res[i] = j - i
- break
- }
- }
- }
- return res
-}
-
-// 解法二 单调栈
-func dailyTemperatures1(T []int) []int {
- res := make([]int, len(T))
- var toCheck []int
- for i, t := range T {
- for len(toCheck) > 0 && T[toCheck[len(toCheck)-1]] < t {
- idx := toCheck[len(toCheck)-1]
- res[idx] = i - idx
- toCheck = toCheck[:len(toCheck)-1]
- }
- toCheck = append(toCheck, i)
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0744.Find-Smallest-Letter-Greater-Than-Target.md b/website/content/ChapterFour/0744.Find-Smallest-Letter-Greater-Than-Target.md
deleted file mode 100755
index fc6e62086..000000000
--- a/website/content/ChapterFour/0744.Find-Smallest-Letter-Greater-Than-Target.md
+++ /dev/null
@@ -1,92 +0,0 @@
-# [744. Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target/)
-
-
-## 题目
-
-Given a list of sorted characters `letters` containing only lowercase letters, and given a target letter `target`, find the smallest element in the list that is larger than the given target.
-
-Letters also wrap around. For example, if the target is `target = 'z'` and `letters = ['a', 'b']`, the answer is `'a'`.
-
-**Examples**:
-
- Input:
- letters = ["c", "f", "j"]
- target = "a"
- Output: "c"
-
- Input:
- letters = ["c", "f", "j"]
- target = "c"
- Output: "f"
-
- Input:
- letters = ["c", "f", "j"]
- target = "d"
- Output: "f"
-
- Input:
- letters = ["c", "f", "j"]
- target = "g"
- Output: "j"
-
- Input:
- letters = ["c", "f", "j"]
- target = "j"
- Output: "c"
-
- Input:
- letters = ["c", "f", "j"]
- target = "k"
- Output: "c"
-
-**Note**:
-
-1. `letters` has a length in range `[2, 10000]`.
-2. `letters` consists of lowercase letters, and contains at least 2 unique letters.
-3. `target` is a lowercase letter.
-
-
-## 题目大意
-
-给定一个只包含小写字母的有序数组letters 和一个目标字母 target,寻找有序数组里面比目标字母大的最小字母。
-
-数组里字母的顺序是循环的。举个例子,如果目标字母target = 'z' 并且有序数组为 letters = ['a', 'b'],则答案返回 'a'。
-
-注:
-
-1. letters长度范围在[2, 10000]区间内。
-2. letters 仅由小写字母组成,最少包含两个不同的字母。
-3. 目标字母target 是一个小写字母。
-
-
-
-## 解题思路
-
-- 给出一个字节数组,在这个字节数组中查找在 target 后面的第一个字母。数组是环形的。
-- 这一题也是二分搜索的题目,先在数组里面查找 target,如果找到了,取这个字母的后一个字母。如果没有找到,就取 low 下标的那个字母。注意数组是环形的,所以最后结果需要对下标取余。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func nextGreatestLetter(letters []byte, target byte) byte {
- low, high := 0, len(letters)-1
- for low <= high {
- mid := low + (high-low)>>1
- if letters[mid] > target {
- high = mid - 1
- } else {
- low = mid + 1
- }
- }
- find := letters[low%len(letters)]
- if find <= target {
- return letters[0]
- }
- return find
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0745.Prefix-and-Suffix-Search.md b/website/content/ChapterFour/0745.Prefix-and-Suffix-Search.md
deleted file mode 100755
index 705aa2171..000000000
--- a/website/content/ChapterFour/0745.Prefix-and-Suffix-Search.md
+++ /dev/null
@@ -1,98 +0,0 @@
-# [745. Prefix and Suffix Search](https://leetcode.com/problems/prefix-and-suffix-search/)
-
-
-## 题目
-
-Given many `words`, `words[i]` has weight `i`.
-
-Design a class `WordFilter` that supports one function, `WordFilter.f(String prefix, String suffix)`. It will return the word with given `prefix` and `suffix` with maximum weight. If no word exists, return -1.
-
-**Examples**:
-
- Input:
- WordFilter(["apple"])
- WordFilter.f("a", "e") // returns 0
- WordFilter.f("b", "") // returns -1
-
-**Note**:
-
-1. `words` has length in range `[1, 15000]`.
-2. For each test case, up to `words.length` queries `WordFilter.f` may be made.
-3. `words[i]` has length in range `[1, 10]`.
-4. `prefix, suffix` have lengths in range `[0, 10]`.
-5. `words[i]` and `prefix, suffix` queries consist of lowercase letters only.
-
-
-## 题目大意
-
-给定多个 words,words[i] 的权重为 i 。设计一个类 WordFilter 实现函数WordFilter.f(String prefix, String suffix)。这个函数将返回具有前缀 prefix 和后缀suffix 的词的最大权重。如果没有这样的词,返回 -1。
-
-
-
-## 解题思路
-
-
-- 要求实现一个 `WordFilter` ,它具有字符串匹配的功能,可以匹配出前缀和后缀都满足条件的字符串下标,如果找得到,返回下标,如果找不到,则返回 -1 。
-- 这一题有 2 种解题思路。第一种是先把这个 `WordFilter` 结构里面的字符串全部预处理一遍,将它的前缀,后缀的所有组合都枚举出来放在 map 中,之后匹配的时候只需要按照自己定义的规则查找 key 就可以了。初始化时间复杂度 `O(N * L^2)`,查找时间复杂度 `O(1)`,空间复杂度 `O(N * L^2)`。其中 `N` 是输入的字符串数组的长度,`L` 是输入字符串数组中字符串的最大长度。第二种思路是直接遍历字符串每个下标,依次用字符串的前缀匹配方法和后缀匹配方法,依次匹配。初始化时间复杂度 `O(1)`,查找时间复杂度 `O(N * L)`,空间复杂度 `O(1)`。其中 `N` 是输入的字符串数组的长度,`L` 是输入字符串数组中字符串的最大长度。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strings"
-
-// 解法一 查找时间复杂度 O(1)
-type WordFilter struct {
- words map[string]int
-}
-
-func Constructor745(words []string) WordFilter {
- wordsMap := make(map[string]int, len(words)*5)
- for k := 0; k < len(words); k++ {
- for i := 0; i <= 10 && i <= len(words[k]); i++ {
- for j := len(words[k]); 0 <= j && len(words[k])-10 <= j; j-- {
- ps := words[k][:i] + "#" + words[k][j:]
- wordsMap[ps] = k
- }
- }
- }
- return WordFilter{words: wordsMap}
-}
-
-func (this *WordFilter) F(prefix string, suffix string) int {
- ps := prefix + "#" + suffix
- if index, ok := this.words[ps]; ok {
- return index
- }
- return -1
-}
-
-// 解法二 查找时间复杂度 O(N * L)
-type WordFilter_ struct {
- input []string
-}
-
-func Constructor_745_(words []string) WordFilter_ {
- return WordFilter_{input: words}
-}
-
-func (this *WordFilter_) F_(prefix string, suffix string) int {
- for i := len(this.input) - 1; i >= 0; i-- {
- if strings.HasPrefix(this.input[i], prefix) && strings.HasSuffix(this.input[i], suffix) {
- return i
- }
- }
- return -1
-}
-
-/**
- * Your WordFilter object will be instantiated and called as such:
- * obj := Constructor(words);
- * param_1 := obj.F(prefix,suffix);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0746.Min-Cost-Climbing-Stairs.md b/website/content/ChapterFour/0746.Min-Cost-Climbing-Stairs.md
deleted file mode 100755
index 2abd334b8..000000000
--- a/website/content/ChapterFour/0746.Min-Cost-Climbing-Stairs.md
+++ /dev/null
@@ -1,71 +0,0 @@
-# [746. Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs/)
-
-
-## 题目
-
-On a staircase, the `i`-th step has some non-negative cost `cost[i]` assigned (0 indexed).
-
-Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.
-
-**Example 1**:
-
- Input: cost = [10, 15, 20]
- Output: 15
- Explanation: Cheapest is start on cost[1], pay that cost and go to the top.
-
-**Example 2**:
-
- Input: cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
- Output: 6
- Explanation: Cheapest is start on cost[0], and only step on 1s, skipping cost[3].
-
-**Note**:
-
-1. `cost` will have a length in the range `[2, 1000]`.
-2. Every `cost[i]` will be an integer in the range `[0, 999]`.
-
-
-## 题目大意
-
-数组的每个索引做为一个阶梯,第 i 个阶梯对应着一个非负数的体力花费值 cost\[i\] (索引从 0 开始)。每当你爬上一个阶梯你都要花费对应的体力花费值,然后你可以选择继续爬一个阶梯或者爬两个阶梯。您需要找到达到楼层顶部的最低花费。在开始时,你可以选择从索引为 0 或 1 的元素作为初始阶梯。
-
-
-## 解题思路
-
-
-- 这一题算是第 70 题的加强版。依旧是爬楼梯的问题,解题思路也是 DP。在爬楼梯的基础上增加了一个新的条件,每层楼梯都有一个 cost 花费,问上到最终楼层,花费最小值是多少。
-- `dp[i]` 代表上到第 n 层的最小花费,状态转移方程是 `dp[i] = cost[i] + min(dp[i-2], dp[i-1])`,最终第 n 层的最小花费是 `min(dp[n-2], dp[n-1])` 。
-- 由于每层的花费只和前两层有关系,所以每次 DP 迭代的时候只需要 2 个临时变量即可。可以用这种方式来优化辅助空间。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 DP
-func minCostClimbingStairs(cost []int) int {
- dp := make([]int, len(cost))
- dp[0], dp[1] = cost[0], cost[1]
- for i := 2; i < len(cost); i++ {
- dp[i] = cost[i] + min(dp[i-2], dp[i-1])
- }
- return min(dp[len(cost)-2], dp[len(cost)-1])
-}
-
-// 解法二 DP 优化辅助空间
-func minCostClimbingStairs1(cost []int) int {
- var cur, last int
- for i := 2; i < len(cost)+1; i++ {
- if last+cost[i-1] > cur+cost[i-2] {
- cur, last = last, cur+cost[i-2]
- } else {
- cur, last = last, last+cost[i-1]
- }
- }
- return last
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0748.Shortest-Completing-Word.md b/website/content/ChapterFour/0748.Shortest-Completing-Word.md
deleted file mode 100755
index ec0267e33..000000000
--- a/website/content/ChapterFour/0748.Shortest-Completing-Word.md
+++ /dev/null
@@ -1,102 +0,0 @@
-# [748. Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word/)
-
-
-## 题目
-
-Find the minimum length word from a given dictionary `words`, which has all the letters from the string `licensePlate`. Such a word is said to complete the given string `licensePlate`
-
-Here, for letters we ignore case. For example, `"P"` on the `licensePlate` still matches `"p"` on the word.
-
-It is guaranteed an answer exists. If there are multiple answers, return the one that occurs first in the array.
-
-The license plate might have the same letter occurring multiple times. For example, given a `licensePlate` of `"PP"`, the word `"pair"` does not complete the `licensePlate`, but the word `"supper"` does.
-
-**Example 1**:
-
- Input: licensePlate = "1s3 PSt", words = ["step", "steps", "stripe", "stepple"]
- Output: "steps"
- Explanation: The smallest length word that contains the letters "S", "P", "S", and "T".
- Note that the answer is not "step", because the letter "s" must occur in the word twice.
- Also note that we ignored case for the purposes of comparing whether a letter exists in the word.
-
-**Example 2**:
-
- Input: licensePlate = "1s3 456", words = ["looks", "pest", "stew", "show"]
- Output: "pest"
- Explanation: There are 3 smallest length words that contains the letters "s".
- We return the one that occurred first.
-
-**Note**:
-
-1. `licensePlate` will be a string with length in range `[1, 7]`.
-2. `licensePlate` will contain digits, spaces, or letters (uppercase or lowercase).
-3. `words` will have a length in the range `[10, 1000]`.
-4. Every `words[i]` will consist of lowercase letters, and have length in range `[1, 15]`.
-
-
-## 题目大意
-
-如果单词列表(words)中的一个单词包含牌照(licensePlate)中所有的字母,那么我们称之为完整词。在所有完整词中,最短的单词我们称之为最短完整词。
-
-单词在匹配牌照中的字母时不区分大小写,比如牌照中的 "P" 依然可以匹配单词中的 "p" 字母。我们保证一定存在一个最短完整词。当有多个单词都符合最短完整词的匹配条件时取单词列表中最靠前的一个。牌照中可能包含多个相同的字符,比如说:对于牌照 "PP",单词 "pair" 无法匹配,但是 "supper" 可以匹配。
-
-注意:
-
-- 牌照(licensePlate)的长度在区域[1, 7]中。
-- 牌照(licensePlate)将会包含数字、空格、或者字母(大写和小写)。
-- 单词列表(words)长度在区间 [10, 1000] 中。
-- 每一个单词 words[i] 都是小写,并且长度在区间 [1, 15] 中。
-
-
-
-## 解题思路
-
-
-- 给出一个数组,要求找出能包含 `licensePlate` 字符串中所有字符的最短长度的字符串。如果最短长度的字符串有多个,输出 word 下标小的那个。这一题也是简单题,不过有 2 个需要注意的点,第一点,`licensePlate` 中可能包含 `Unicode` 任意的字符,所以要先把字母的字符筛选出来,第二点是题目中保证了一定存在一个最短的单词能满足题意,并且忽略大小写。具体做法按照题意模拟即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "unicode"
-
-func shortestCompletingWord(licensePlate string, words []string) string {
- lp := genCnter(licensePlate)
- var ret string
- for _, w := range words {
- if match(lp, w) {
- if len(w) < len(ret) || ret == "" {
- ret = w
- }
- }
- }
- return ret
-}
-
-func genCnter(lp string) [26]int {
- cnter := [26]int{}
- for _, ch := range lp {
- if unicode.IsLetter(ch) {
- cnter[unicode.ToLower(ch)-'a']++
- }
- }
- return cnter
-}
-
-func match(lp [26]int, w string) bool {
- m := [26]int{}
- for _, ch := range w {
- m[ch-'a']++
- }
- for k, v := range lp {
- if m[k] < v {
- return false
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0753.Cracking-the-Safe.md b/website/content/ChapterFour/0753.Cracking-the-Safe.md
deleted file mode 100644
index 39c79a48d..000000000
--- a/website/content/ChapterFour/0753.Cracking-the-Safe.md
+++ /dev/null
@@ -1,92 +0,0 @@
-# [753. Cracking the Safe](https://leetcode.com/problems/cracking-the-safe/)
-
-
-
-## 题目
-
-There is a box protected by a password. The password is a sequence of `n` digits where each digit can be one of the first `k` digits `0, 1, ..., k-1`.
-
-While entering a password, the last `n` digits entered will automatically be matched against the correct password.
-
-For example, assuming the correct password is `"345"`, if you type `"012345"`, the box will open because the correct password matches the suffix of the entered password.
-
-Return any password of **minimum length** that is guaranteed to open the box at some point of entering it.
-
-**Example 1**:
-
-```
-Input: n = 1, k = 2
-Output: "01"
-Note: "10" will be accepted too.
-```
-
-**Example 2**:
-
-```
-Input: n = 2, k = 2
-Output: "00110"
-Note: "01100", "10011", "11001" will be accepted too.
-```
-
-**Note**:
-
-1. `n` will be in the range `[1, 4]`.
-2. `k` will be in the range `[1, 10]`.
-3. `k^n` will be at most `4096`.
-
-
-## 题目大意
-
-有一个需要密码才能打开的保险箱。密码是 n 位数, 密码的每一位是 k 位序列 0, 1, ..., k-1 中的一个 。你可以随意输入密码,保险箱会自动记住最后 n 位输入,如果匹配,则能够打开保险箱。举个例子,假设密码是 "345",你可以输入 "012345" 来打开它,只是你输入了 6 个字符.请返回一个能打开保险箱的最短字符串。
-
-提示:
-
-- n 的范围是 [1, 4]。
-- k 的范围是 [1, 10]。
-- k^n 最大可能为 4096。
-
-
-## 解题思路
-
-- 给出 2 个数字 n 和 k,n 代表密码是 n 位数,k 代表密码是 k 位。保险箱会记住最后 n 位输入。返回一个能打开保险箱的最短字符串。
-- 看到题目中的数据范围,数据范围很小,所以可以考虑用 DFS。想解开保险箱,当然是暴力破解,枚举所有可能。题目要求我们输出一个最短的字符串,这里是本题的关键,为何有最短呢?这里有贪心的思想。如果下一次递归可以利用上一次的 n-1 位,那么最终输出的字符串肯定是最短的。(笔者这里就不证明了),例如,例子 2 中,最短的字符串是 00,01,11,10。每次尝试都利用前一次的 n-1 位。想通了这个问题,利用 DFS 暴力回溯即可。
-
-## 代码
-
-```go
-const number = "0123456789"
-
-func crackSafe(n int, k int) string {
- if n == 1 {
- return number[:k]
- }
- visit, total := map[string]bool{}, int(math.Pow(float64(k), float64(n)))
- str := make([]byte, 0, total+n-1)
- for i := 1; i != n; i++ {
- str = append(str, '0')
- }
- dfsCrackSafe(total, n, k, &str, &visit)
- return string(str)
-}
-
-func dfsCrackSafe(depth, n, k int, str *[]byte, visit *map[string]bool) bool {
- if depth == 0 {
- return true
- }
- for i := 0; i != k; i++ {
- *str = append(*str, byte('0'+i))
- cur := string((*str)[len(*str)-n:])
- if _, ok := (*visit)[cur]; ok != true {
- (*visit)[cur] = true
- if dfsCrackSafe(depth-1, n, k, str, visit) {
- // 只有这里不需要删除
- return true
- }
- delete(*visit, cur)
- }
- // 删除
- *str = (*str)[0 : len(*str)-1]
- }
- return false
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0756.Pyramid-Transition-Matrix.md b/website/content/ChapterFour/0756.Pyramid-Transition-Matrix.md
deleted file mode 100755
index 1b158131c..000000000
--- a/website/content/ChapterFour/0756.Pyramid-Transition-Matrix.md
+++ /dev/null
@@ -1,92 +0,0 @@
-# [756. Pyramid Transition Matrix](https://leetcode.com/problems/pyramid-transition-matrix/)
-
-
-## 题目
-
-We are stacking blocks to form a pyramid. Each block has a color which is a one letter string.
-
-We are allowed to place any color block `C` on top of two adjacent blocks of colors `A` and `B`, if and only if `ABC` is an allowed triple.
-
-We start with a bottom row of `bottom`, represented as a single string. We also start with a list of allowed triples `allowed`. Each allowed triple is represented as a string of length 3.
-
-Return true if we can build the pyramid all the way to the top, otherwise false.
-
-**Example 1**:
-
- Input: bottom = "BCD", allowed = ["BCG", "CDE", "GEA", "FFF"]
- Output: true
- Explanation:
- We can stack the pyramid like this:
- A
- / \
- G E
- / \ / \
- B C D
-
- We are allowed to place G on top of B and C because BCG is an allowed triple. Similarly, we can place E on top of C and D, then A on top of G and E.
-
-**Example 2**:
-
- Input: bottom = "AABA", allowed = ["AAA", "AAB", "ABA", "ABB", "BAC"]
- Output: false
- Explanation:
- We can't stack the pyramid to the top.
- Note that there could be allowed triples (A, B, C) and (A, B, D) with C != D.
-
-**Note**:
-
-1. `bottom` will be a string with length in range `[2, 8]`.
-2. `allowed` will have length in range `[0, 200]`.
-3. Letters in all strings will be chosen from the set `{'A', 'B', 'C', 'D', 'E', 'F', 'G'}`.
-
-
-## 题目大意
-
-现在,我们用一些方块来堆砌一个金字塔。 每个方块用仅包含一个字母的字符串表示,例如 “Z”。使用三元组表示金字塔的堆砌规则如下:
-
-(A, B, C) 表示,“C” 为顶层方块,方块 “A”、“B” 分别作为方块 “C” 下一层的的左、右子块。当且仅当(A, B, C)是被允许的三元组,我们才可以将其堆砌上。
-
-初始时,给定金字塔的基层 bottom,用一个字符串表示。一个允许的三元组列表 allowed,每个三元组用一个长度为 3 的字符串表示。如果可以由基层一直堆到塔尖返回 true,否则返回 false。
-
-
-
-## 解题思路
-
-- 这一题是一道 DFS 的题目。题目给出金字塔的底座字符串。然后还会给一个字符串数组,字符串数组里面代表的字符串的砖块。砖块是 3 个字符串组成的。前两个字符代表的是砖块的底边,后一个字符代表的是砖块的顶部。问给出的字符能拼成一个金字塔么?金字塔的特点是顶端就一个字符。
-
-- 这一题用 DFS 深搜每个砖块,从底层砖块开始逐渐往上层码。每递归一层,新一层底部的砖块都会变。当递归到了一层底部只有 2 个字符,顶部只有一个字符的时候,就到金字塔顶端了,就算是完成了。这一题为了挑选合适的砖块,需要把每个砖块底部的 2 个字符作为 key 放进 map 中,加速查找。题目中也给出了特殊情况,相同底部可能存在多种砖块,所以一个 key 可能对应多个 value 的情况,即可能存在多个顶部砖块的情况。这种情况在递归遍历中需要考虑。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func pyramidTransition(bottom string, allowed []string) bool {
- pyramid := make(map[string][]string)
- for _, v := range allowed {
- pyramid[v[:len(v)-1]] = append(pyramid[v[:len(v)-1]], string(v[len(v)-1]))
- }
- return dfsT(bottom, "", pyramid)
-}
-
-func dfsT(bottom, above string, pyramid map[string][]string) bool {
- if len(bottom) == 2 && len(above) == 1 {
- return true
- }
- if len(bottom) == len(above)+1 {
- return dfsT(above, "", pyramid)
- }
- base := bottom[len(above) : len(above)+2]
- if data, ok := pyramid[base]; ok {
- for _, key := range data {
- if dfsT(bottom, above+key, pyramid) {
- return true
- }
- }
- }
- return false
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md b/website/content/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md
deleted file mode 100755
index 8c01e90f6..000000000
--- a/website/content/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md
+++ /dev/null
@@ -1,78 +0,0 @@
-# [762. Prime Number of Set Bits in Binary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/)
-
-
-## 题目
-
-Given two integers `L` and `R`, find the count of numbers in the range `[L, R]` (inclusive) having a prime number of set bits in their binary representation.
-
-(Recall that the number of set bits an integer has is the number of `1`s present when written in binary. For example, `21` written in binary is `10101` which has 3 set bits. Also, 1 is not a prime.)
-
-**Example 1**:
-
- Input: L = 6, R = 10
- Output: 4
- Explanation:
- 6 -> 110 (2 set bits, 2 is prime)
- 7 -> 111 (3 set bits, 3 is prime)
- 9 -> 1001 (2 set bits , 2 is prime)
- 10->1010 (2 set bits , 2 is prime)
-
-**Example 2**:
-
- Input: L = 10, R = 15
- Output: 5
- Explanation:
- 10 -> 1010 (2 set bits, 2 is prime)
- 11 -> 1011 (3 set bits, 3 is prime)
- 12 -> 1100 (2 set bits, 2 is prime)
- 13 -> 1101 (3 set bits, 3 is prime)
- 14 -> 1110 (3 set bits, 3 is prime)
- 15 -> 1111 (4 set bits, 4 is not prime)
-
-**Note**:
-
-1. `L, R` will be integers `L <= R` in the range `[1, 10^6]`.
-2. `R - L` will be at most 10000.
-
-
-## 题目大意
-
-给定两个整数 L 和 R ,找到闭区间 [L, R] 范围内,计算置位位数为质数的整数个数。(注意,计算置位代表二进制表示中1的个数。例如 21 的二进制表示 10101 有 3 个计算置位。还有,1 不是质数。)
-
-
-注意:
-
-- L, R 是 L <= R 且在 [1, 10^6] 中的整数。
-- R - L 的最大值为 10000。
-
-
-
-## 解题思路
-
-
-- 题目给出 `[L, R]` 区间,在这个区间内的每个整数的二进制表示中 1 的个数如果是素数,那么最终结果就加一,问最终结果是多少?这一题是一个组合题,判断一个数的二进制位有多少位 1,是第 191 题。题目中限定了区间最大不超过 10^6 ,所以 1 的位数最大是 19 位,也就是说素数最大就是 19 。那么素数可以有限枚举出来。最后按照题目的意思累积结果就可以了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math/bits"
-
-func countPrimeSetBits(L int, R int) int {
- counter := 0
- for i := L; i <= R; i++ {
- if isPrime(bits.OnesCount(uint(i))) {
- counter++
- }
- }
- return counter
-}
-
-func isPrime(x int) bool {
- return x == 2 || x == 3 || x == 5 || x == 7 || x == 11 || x == 13 || x == 17 || x == 19
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0763.Partition-Labels.md b/website/content/ChapterFour/0763.Partition-Labels.md
deleted file mode 100644
index 76bf1b3f7..000000000
--- a/website/content/ChapterFour/0763.Partition-Labels.md
+++ /dev/null
@@ -1,92 +0,0 @@
-# [763. Partition Labels](https://leetcode.com/problems/partition-labels/)
-
-## 题目
-
-A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.
-
-
-
-**Example 1**:
-
-
-```
-
-Input: S = "ababcbacadefegdehijhklij"
-Output: [9,7,8]
-Explanation:
-The partition is "ababcbaca", "defegde", "hijhklij".
-This is a partition so that each letter appears in at most one part.
-A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits S into less parts.
-
-```
-
-**Note**:
-
-- S will have length in range [1, 500].
-- S will consist of lowercase letters ('a' to 'z') only.
-
-
-## 题目大意
-
-这道题考察的是滑动窗口的问题。
-
-给出一个字符串,要求输出满足条件窗口的长度,条件是在这个窗口内,字母中出现在这一个窗口内,不出现在其他窗口内。
-
-## 解题思路
-
-这一题有 2 种思路,第一种思路是先记录下每个字母的出现次数,然后对滑动窗口中的每个字母判断次数是否用尽为 0,如果这个窗口内的所有字母次数都为 0,这个窗口就是符合条件的窗口。时间复杂度为 O(n^2)
-
-另外一种思路是记录下每个字符最后一次出现的下标,这样就不用记录次数。在每个滑动窗口中,依次判断每个字母最后一次出现的位置,如果在一个下标内,所有字母的最后一次出现的位置都包含进来了,那么这个下标就是这个满足条件的窗口大小。时间复杂度为 O(n^2)
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一
-func partitionLabels(S string) []int {
- var lastIndexOf [26]int
- for i, v := range S {
- lastIndexOf[v-'a'] = i
- }
-
- var arr []int
- for start, end := 0, 0; start < len(S); start = end + 1 {
- end = lastIndexOf[S[start]-'a']
- for i := start; i < end; i++ {
- if end < lastIndexOf[S[i]-'a'] {
- end = lastIndexOf[S[i]-'a']
- }
- }
- arr = append(arr, end-start+1)
- }
- return arr
-}
-
-// 解法二
-func partitionLabels1(S string) []int {
- visit, counter, res, sum, lastLength := make([]int, 26), map[byte]int{}, []int{}, 0, 0
- for i := 0; i < len(S); i++ {
- counter[S[i]]++
- }
-
- for i := 0; i < len(S); i++ {
- counter[S[i]]--
- visit[S[i]-'a'] = 1
- sum = 0
- for j := 0; j < 26; j++ {
- if visit[j] == 1 {
- sum += counter[byte('a'+j)]
- }
- }
- if sum == 0 {
- res = append(res, i+1-lastLength)
- lastLength += i + 1 - lastLength
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0765.Couples-Holding-Hands.md b/website/content/ChapterFour/0765.Couples-Holding-Hands.md
deleted file mode 100755
index 035512fe7..000000000
--- a/website/content/ChapterFour/0765.Couples-Holding-Hands.md
+++ /dev/null
@@ -1,93 +0,0 @@
-# [765. Couples Holding Hands](https://leetcode.com/problems/couples-holding-hands/)
-
-
-## 题目
-
-N couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing **any** two people, then they stand up and switch seats.
-
-The people and seats are represented by an integer from `0` to `2N-1`, the couples are numbered in order, the first couple being `(0, 1)`, the second couple being `(2, 3)`, and so on with the last couple being `(2N-2, 2N-1)`.
-
-The couples' initial seating is given by `row[i]` being the value of the person who is initially sitting in the i-th seat.
-
-**Example 1**:
-
- Input: row = [0, 2, 1, 3]
- Output: 1
- Explanation: We only need to swap the second (row[1]) and third (row[2]) person.
-
-**Example 2**:
-
- Input: row = [3, 2, 0, 1]
- Output: 0
- Explanation: All couples are already seated side by side.
-
-**Note**:
-
-1. `len(row)` is even and in the range of `[4, 60]`.
-2. `row` is guaranteed to be a permutation of `0...len(row)-1`.
-
-
-## 题目大意
-
-N 对情侣坐在连续排列的 2N 个座位上,想要牵到对方的手。 计算最少交换座位的次数,以便每对情侣可以并肩坐在一起。 一次交换可选择任意两人,让他们站起来交换座位。人和座位用 0 到 2N-1 的整数表示,情侣们按顺序编号,第一对是 (0, 1),第二对是 (2, 3),以此类推,最后一对是 (2N-2, 2N-1)。这些情侣的初始座位 row[i] 是由最初始坐在第 i 个座位上的人决定的。
-
-说明:
-
-1. len(row) 是偶数且数值在 [4, 60]范围内。
-2. 可以保证 row 是序列 0...len(row)-1 的一个全排列。
-
-
-## 解题思路
-
-- 给出一个数组,数组里面两两相邻的元素代表一对情侣。情侣编号是从 0 开始的:0 和 1 是情侣,2 和 3 是情侣……这些情侣坐在一排,但是并非成对坐着一起的,问如何用最小的次数交换座位以后,情侣能两两坐在一起。
-- 这道题的突破口是如何找到最小的交换次数。乍一想可能没有思路。直觉告诉我们,这种难题,很可能最后推出来的结论,或者公式是一个很简单的式子。(事实此题确实是这种情况)先不考虑最小交换次数,用正常的方法来处理这道题。举个例子:【3 1 4 0 2 5】,从数组 0 下标开始往后扫。
-
- 初始状态
-
- 集合 0:0,1
- 集合 1:2,3
- 集合 2:4,5
-
- 3 和 1 不是情侣,将 3 和 1 所在集合 `union()` 起来。3 所在集合是 1 ,1 所在集合是 0,将 0 和 1 号集合 `union()` 起来。因为情侣 0 和情侣 1 是集合 0 ,情侣 2 和情侣 3 是集合 1,以此类推。
-
- 集合 0 和 1:0,1,2,3
- 集合 2:4,5
-
-- 继续往后扫,4 和 0 不在同一个集合,4 在集合 3,0 在集合 0,那么把它们 `union()` 起来。
-
- 集合 0 和 1 和 2:0,1,2,3,4,5
-
- 在上面集合合并的过程中,合并了 2 次。那么就代表最少需要交换 2 次。也可以通过 `len(row)/2 - uf.count` 来计算。`len(row)/2` 是初始集合总数,`uf.count` 是最后剩下的集合数,两者相减就是中间交换的次数。
-
-- 最后实现的代码非常简单。并查集先相邻的两两元素 `union()` 在一起。然后扫原数组,每次扫相邻的两个,通过这两个元素值所在集合,进行 `union()`。扫完以后就可以得到最后的答案。
-- 回过头来看这道题,为什么我们从数组开头往后依次调整每一对情侣,这样交换的次数是最少的呢?其实这个方法的思想是贪心思想。从头开始往后一对一对的调整,就是可以最终做到次数最少。(具体证明笔者不会)交换到最后,最后一对情侣一定是正确的,无须交换。(因为前面每一对都调整完了,最后一对一定是正确的)
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func minSwapsCouples(row []int) int {
- if len(row)&1 == 1 {
- return 0
- }
- uf := template.UnionFind{}
- uf.Init(len(row))
- for i := 0; i < len(row)-1; i = i + 2 {
- uf.Union(i, i+1)
- }
- for i := 0; i < len(row)-1; i = i + 2 {
- if uf.Find(row[i]) != uf.Find(row[i+1]) {
- uf.Union(row[i], row[i+1])
- }
- }
- return len(row)/2 - uf.TotalCount()
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0766.Toeplitz-Matrix.md b/website/content/ChapterFour/0766.Toeplitz-Matrix.md
deleted file mode 100755
index a595e632b..000000000
--- a/website/content/ChapterFour/0766.Toeplitz-Matrix.md
+++ /dev/null
@@ -1,79 +0,0 @@
-# [766. Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix/)
-
-
-## 题目
-
-A matrix is *Toeplitz* if every diagonal from top-left to bottom-right has the same element.
-
-Now given an `M x N` matrix, return `True` if and only if the matrix is *Toeplitz*.
-
-**Example 1**:
-
- Input:
- matrix = [
- [1,2,3,4],
- [5,1,2,3],
- [9,5,1,2]
- ]
- Output: True
- Explanation:
- In the above grid, the diagonals are:
- "[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".
- In each diagonal all elements are the same, so the answer is True.
-
-**Example 2**:
-
- Input:
- matrix = [
- [1,2],
- [2,2]
- ]
- Output: False
- Explanation:
- The diagonal "[1, 2]" has different elements.
-
-**Note**:
-
-1. `matrix` will be a 2D array of integers.
-2. `matrix` will have a number of rows and columns in range `[1, 20]`.
-3. `matrix[i][j]` will be integers in range `[0, 99]`.
-
-**Follow up**:
-
-1. What if the matrix is stored on disk, and the memory is limited such that you can only load at most one row of the matrix into the memory at once?
-2. What if the matrix is so large that you can only load up a partial row into the memory at once?
-
-
-## 题目大意
-
-如果一个矩阵的每一方向由左上到右下的对角线上具有相同元素,那么这个矩阵是托普利茨矩阵。给定一个 M x N 的矩阵,当且仅当它是托普利茨矩阵时返回 True。
-
-
-
-## 解题思路
-
-
-- 给出一个矩阵,要求判断矩阵所有对角斜线上的数字是否都是一个数字。
-- 水题,直接循环判断即可。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func isToeplitzMatrix(matrix [][]int) bool {
- rows, columns := len(matrix), len(matrix[0])
- for i := 1; i < rows; i++ {
- for j := 1; j < columns; j++ {
- if matrix[i-1][j-1] != matrix[i][j] {
- return false
- }
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0767.Reorganize-String.md b/website/content/ChapterFour/0767.Reorganize-String.md
deleted file mode 100644
index 45388be33..000000000
--- a/website/content/ChapterFour/0767.Reorganize-String.md
+++ /dev/null
@@ -1,149 +0,0 @@
-# [767. Reorganize String](https://leetcode.com/problems/reorganize-string/)
-
-## 题目
-
-Given a string S, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same.
-
-If possible, output any possible result. If not possible, return the empty string.
-
-**Example 1**:
-
-```
-
-Input: S = "aab"
-Output: "aba"
-
-```
-
-**Example 2**:
-
-```
-
-Input: S = "aaab"
-Output: ""
-
-```
-
-**Note**:
-
-S will consist of lowercase letters and have length in range [1, 500].
-
-
-## 题目大意
-
-给定一个字符串,要求重新排列字符串,让字符串两两字符不相同,如果可以实现,即输出最终的字符串,如果不能让两两不相同,则输出空字符串。
-
-## 解题思路
-
-这道题有 2 种做法。第一种做法是先统计每个字符的出现频率次数,按照频率次数从高往低排序。具体做法就是第 451 题了。如果有一个字母的频次次数超过了 (len(string)+1)/2 那么就返回空字符串。否则输出最终满足题意的字符串。按照频次排序以后,用 2 个指针,一个从 0 开始,另外一个从中间位置开始,依次取出一个字符拼接起来。
-
-第二种做法是用优先队列,结点是一个结构体,结构体有 2 个字段,一个字段记录是哪个字符,另一个字段记录是这个字符的频次。按照频次的多作为优先级高,用大根堆建立优先队列。注意,这样建立成功的优先队列,重复字母只有一个结点,频次记录在结构体的频次字段中。额外还需要一个辅助队列。优先队列每次都出队一个优先级最高的,然后频次减一,最终结果加上这个字符。然后将这个结点入队。入队的意义是检测这个结点的频次有没有减到 0,如果还不为 0 ,再插入优先队列中。
-
-```c
- string reorganizeString(string S) {
- vector mp(26);
- int n = S.size();
- for (char c: S)
- ++mp[c-'a'];
- priority_queue> pq;
- for (int i = 0; i < 26; ++i) {
- if (mp[i] > (n+1)/2) return "";
- if (mp[i]) pq.push({mp[i], i+'a'});
- }
- queue> myq;
- string ans;
- while (!pq.empty() || myq.size() > 1) {
- if (myq.size() > 1) { // 注意这里要大于 1,如果是等于 1 的话,频次大的元素一直在输出了,答案就不对了。
- auto cur = myq.front();
- myq.pop();
- if (cur.first != 0) pq.push(cur);
- }
- if (!pq.empty()) {
- auto cur = pq.top();
- pq.pop();
- ans += cur.second;
- cur.first--;
- myq.push(cur);
- }
- }
- return ans;
- }
-```
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-func reorganizeString(S string) string {
- fs := frequencySort767(S)
- if fs == "" {
- return ""
- }
- bs := []byte(fs)
- ans := ""
- j := (len(bs)-1)/2 + 1
- for i := 0; i <= (len(bs)-1)/2; i++ {
- ans += string(bs[i])
- if j < len(bs) {
- ans += string(bs[j])
- }
- j++
- }
- return ans
-}
-
-func frequencySort767(s string) string {
- if s == "" {
- return ""
- }
- sMap := map[byte]int{}
- cMap := map[int][]byte{}
- sb := []byte(s)
- for _, b := range sb {
- sMap[b]++
- if sMap[b] > (len(sb)+1)/2 {
- return ""
- }
- }
- for key, value := range sMap {
- cMap[value] = append(cMap[value], key)
- }
-
- var keys []int
- for k := range cMap {
- keys = append(keys, k)
- }
- sort.Sort(sort.Reverse(sort.IntSlice(keys)))
- res := make([]byte, 0)
- for _, k := range keys {
- for i := 0; i < len(cMap[k]); i++ {
- for j := 0; j < k; j++ {
- res = append(res, cMap[k][i])
- }
- }
- }
- return string(res)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0771.Jewels-and-Stones.md b/website/content/ChapterFour/0771.Jewels-and-Stones.md
deleted file mode 100755
index e5490bedd..000000000
--- a/website/content/ChapterFour/0771.Jewels-and-Stones.md
+++ /dev/null
@@ -1,74 +0,0 @@
-# [771. Jewels and Stones](https://leetcode.com/problems/jewels-and-stones/)
-
-
-
-## 题目
-
-You're given strings `J` representing the types of stones that are jewels, and `S` representing the stones you have. Each character in `S` is a type of stone you have. You want to know how many of the stones you have are also jewels.
-
-The letters in `J` are guaranteed distinct, and all characters in `J` and `S` are letters. Letters are case sensitive, so `"a"` is considered a different type of stone from `"A"`.
-
-**Example 1**:
-
- Input: J = "aA", S = "aAAbbbb"
- Output: 3
-
-**Example 2**:
-
- Input: J = "z", S = "ZZ"
- Output: 0
-
-**Note**:
-
-- `S` and `J` will consist of letters and have length at most 50.
-- The characters in `J` are distinct.
-
-
-## 题目大意
-
-给定字符串 J 代表石头中宝石的类型,和字符串 S 代表你拥有的石头。S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石。
-
-J 中的字母不重复,J 和 S 中的所有字符都是字母。字母区分大小写,因此 "a" 和 "A" 是不同类型的石头。
-
-
-
-## 解题思路
-
-
-- 给出 2 个字符串,要求在 S 字符串中找出在 J 字符串里面出现的字符个数。这是一道简单题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strings"
-
-// 解法一
-func numJewelsInStones(J string, S string) int {
- count := 0
- for i := range S {
- if strings.Contains(J, string(S[i])) {
- count++
- }
- }
- return count
-}
-
-// 解法二
-func numJewelsInStones1(J string, S string) int {
- cache, result := make(map[rune]bool), 0
- for _, r := range J {
- cache[r] = true
- }
- for _, r := range S {
- if _, ok := cache[r]; ok {
- result++
- }
- }
- return result
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0778.Swim-in-Rising-Water.md b/website/content/ChapterFour/0778.Swim-in-Rising-Water.md
deleted file mode 100755
index 7153069f3..000000000
--- a/website/content/ChapterFour/0778.Swim-in-Rising-Water.md
+++ /dev/null
@@ -1,132 +0,0 @@
-# [778. Swim in Rising Water](https://leetcode.com/problems/swim-in-rising-water/)
-
-
-## 题目
-
-On an N x N `grid`, each square `grid[i][j]` represents the elevation at that point `(i,j)`.
-
-Now rain starts to fall. At time `t`, the depth of the water everywhere is `t`. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most `t`. You can swim infinite distance in zero time. Of course, you must stay within the boundaries of the grid during your swim.
-
-You start at the top left square `(0, 0)`. What is the least time until you can reach the bottom right square `(N-1, N-1)`?
-
-**Example 1**:
-
- Input: [[0,2],[1,3]]
- Output: 3
- Explanation:
- At time 0, you are in grid location (0, 0).
- You cannot go anywhere else because 4-directionally adjacent neighbors have a higher elevation than t = 0.
-
- You cannot reach point (1, 1) until time 3.
- When the depth of water is 3, we can swim anywhere inside the grid.
-
-**Example 2**:
-
- Input: [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]
- Output: 16
- Explanation:
- 0 1 2 3 4
- 24 23 22 21 5
- 12 13 14 15 16
- 11 17 18 19 20
- 10 9 8 7 6
-
- The final route is marked in bold.
- We need to wait until time 16 so that (0, 0) and (4, 4) are connected.
-
-**Note**:
-
-1. `2 <= N <= 50`.
-2. grid[i][j] is a permutation of [0, ..., N*N - 1].
-
-## 题目大意
-
-
-在一个 N x N 的坐标方格 grid 中,每一个方格的值 grid[i][j] 表示在位置 (i,j) 的平台高度。现在开始下雨了。当时间为 t 时,此时雨水导致水池中任意位置的水位为 t 。你可以从一个平台游向四周相邻的任意一个平台,但是前提是此时水位必须同时淹没这两个平台。假定你可以瞬间移动无限距离,也就是默认在方格内部游动是不耗时的。当然,在你游泳的时候你必须待在坐标方格里面。
-
-你从坐标方格的左上平台 (0,0) 出发。最少耗时多久你才能到达坐标方格的右下平台 (N-1, N-1)?
-
-提示:
-
-- 2 <= N <= 50.
-- grid[i][j] 位于区间 [0, ..., N*N - 1] 内。
-
-
-## 解题思路
-
-- 给出一个 grid[i][j] 方格,每个格子里面表示游泳池里面平台的高度。t 时刻,游泳池中的水的高度是 t。只有水的高度到达了平台的高度以后才能游过去。问从 (0,0) 开始,最短多长时间能到达 (N-1, N-1) 。
-- 这一题有多种解法。第一种解题思路是利用 DFS + 二分。DFS 是用来遍历是否可达。利用时间(即当前水淹过的高度)来判断是否能到达终点 (N-1, N-1) 点。二分用来搜索最终结果的时间。为什么会考虑用二分加速呢?原因是:时间从 0 - max 依次递增。max 是游泳池最高的平台高度。当时间从 0 增加到 max 以后,肯定能到达终点 (N-1, N-1) 点,因为水比所有平台都要高了。想快速找到一个时间 t 能使得 (0,0) 点和 (N-1, N-1) 点之间连通,那么就想到用二分加速了。判断是否取中值的条件是 (0,0) 点和 (N-1, N-1) 点之间是否连通。
-- 第二种解题思路是并查集。只要是 (0,0) 点和 (N-1, N-1) 点没有连通,即不能游到终点,那么就开始 `union()` 操作,由于起点是 (0,0),所以向右边 `i + 1` 和向下边 `j + 1` 开始尝试。每尝试完一轮,时间会加 1 秒,即高度会加一。直到 (0,0) 点和 (N-1, N-1) 点刚好连通,那么这个时间点就是最终要求的。
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-// 解法一 DFS + 二分
-func swimInWater(grid [][]int) int {
- row, col, flags, minWait, maxWait := len(grid), len(grid[0]), make([][]int, len(grid)), 0, 0
- for i, row := range grid {
- flags[i] = make([]int, len(row))
- for j := 0; j < col; j++ {
- flags[i][j] = -1
- if row[j] > maxWait {
- maxWait = row[j]
- }
- }
- }
- for minWait < maxWait {
- midWait := (minWait + maxWait) / 2
- addFlags(grid, flags, midWait, 0, 0)
- if flags[row-1][col-1] == midWait {
- maxWait = midWait
- } else {
- minWait = midWait + 1
- }
- }
- return minWait
-}
-
-func addFlags(grid [][]int, flags [][]int, flag int, row int, col int) {
- if row < 0 || col < 0 || row >= len(grid) || col >= len(grid[0]) {
- return
- }
- if grid[row][col] > flag || flags[row][col] == flag {
- return
- }
- flags[row][col] = flag
- addFlags(grid, flags, flag, row-1, col)
- addFlags(grid, flags, flag, row+1, col)
- addFlags(grid, flags, flag, row, col-1)
- addFlags(grid, flags, flag, row, col+1)
-}
-
-// 解法二 并查集(并不是此题的最优解)
-func swimInWater1(grid [][]int) int {
- n, uf, res := len(grid), template.UnionFind{}, 0
- uf.Init(n * n)
- for uf.Find(0) != uf.Find(n*n-1) {
- for i := 0; i < n; i++ {
- for j := 0; j < n; j++ {
- if grid[i][j] > res {
- continue
- }
- if i < n-1 && grid[i+1][j] <= res {
- uf.Union(i*n+j, i*n+j+n)
- }
- if j < n-1 && grid[i][j+1] <= res {
- uf.Union(i*n+j, i*n+j+1)
- }
- }
- }
- res++
- }
- return res - 1
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0781.Rabbits-in-Forest.md b/website/content/ChapterFour/0781.Rabbits-in-Forest.md
deleted file mode 100755
index 61aa4555a..000000000
--- a/website/content/ChapterFour/0781.Rabbits-in-Forest.md
+++ /dev/null
@@ -1,69 +0,0 @@
-# [781. Rabbits in Forest](https://leetcode.com/problems/rabbits-in-forest/)
-
-
-## 题目
-
-In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how many other rabbits have the same color as them. Those `answers` are placed in an array.
-
-Return the minimum number of rabbits that could be in the forest.
-
-**Examples**:
-
- Input: answers = [1, 1, 2]
- Output: 5
- Explanation:
- The two rabbits that answered "1" could both be the same color, say red.
- The rabbit than answered "2" can't be red or the answers would be inconsistent.
- Say the rabbit that answered "2" was blue.
- Then there should be 2 other blue rabbits in the forest that didn't answer into the array.
- The smallest possible number of rabbits in the forest is therefore 5: 3 that answered plus 2 that didn't.
-
- Input: answers = [10, 10, 10]
- Output: 11
-
- Input: answers = []
- Output: 0
-
-**Note**:
-
-1. `answers` will have length at most `1000`.
-2. Each `answers[i]` will be an integer in the range `[0, 999]`.
-
-
-## 题目大意
-
-森林中,每个兔子都有颜色。其中一些兔子(可能是全部)告诉你还有多少其他的兔子和自己有相同的颜色。我们将这些回答放在 answers 数组里。返回森林中兔子的最少数量。
-
-说明:
-
-- answers 的长度最大为1000。
-- answers[i] 是在 [0, 999] 范围内的整数。
-
-
-## 解题思路
-
-
-- 给出一个数组,数组里面代表的是每个兔子说自己同类还有多少个。要求输出总共有多少只兔子。数字中可能兔子汇报的人数小于总兔子数。
-- 这一题关键在于如何划分不同种类的兔子,有可能相同种类的兔子的个数是一样的,比如 `[2,2,2,2,2,2]`,这其实是 3 个种类,总共 6 只兔子。用 map 去重相同种类的兔子,不断的减少,当有种类的兔子为 0 以后,还有该种类的兔子报数,需要当做另外一个种类的兔子来看待。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func numRabbits(ans []int) int {
- total, m := 0, make(map[int]int)
- for _, v := range ans {
- if m[v] == 0 {
- m[v] += v
- total += v + 1
- } else {
- m[v]--
- }
- }
- return total
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0784.Letter-Case-Permutation.md b/website/content/ChapterFour/0784.Letter-Case-Permutation.md
deleted file mode 100755
index 323b4e63e..000000000
--- a/website/content/ChapterFour/0784.Letter-Case-Permutation.md
+++ /dev/null
@@ -1,120 +0,0 @@
-# [784. Letter Case Permutation](https://leetcode.com/problems/letter-case-permutation/)
-
-
-## 题目
-
-Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create.
-
-**Examples**:
-
- Input: S = "a1b2"
- Output: ["a1b2", "a1B2", "A1b2", "A1B2"]
-
- Input: S = "3z4"
- Output: ["3z4", "3Z4"]
-
- Input: S = "12345"
- Output: ["12345"]
-
-**Note**:
-
-- `S` will be a string with length between `1` and `12`.
-- `S` will consist only of letters or digits.
-
-
-## 题目大意
-
-
-给定一个字符串 S,通过将字符串 S 中的每个字母转变大小写,我们可以获得一个新的字符串。返回所有可能得到的字符串集合。
-
-## 解题思路
-
-
-- 输出一个字符串中字母变大写,小写的所有组合。
-- DFS 深搜或者 BFS 广搜都可以。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "strings"
-)
-
-// 解法一,DFS 深搜
-func letterCasePermutation(S string) []string {
- if len(S) == 0 {
- return []string{}
- }
- res, pos, c := []string{}, []int{}, []int{}
- SS := strings.ToLower(S)
- for i := 0; i < len(SS); i++ {
- if isLowerLetter(SS[i]) {
- pos = append(pos, i)
- }
- }
- for i := 0; i <= len(pos); i++ {
- findLetterCasePermutation(SS, pos, i, 0, c, &res)
- }
- return res
-}
-
-func findLetterCasePermutation(s string, pos []int, target, index int, c []int, res *[]string) {
- if len(c) == target {
- b := []byte(s)
- for _, v := range c {
- b[pos[v]] -= 'a' - 'A'
- }
- *res = append(*res, string(b))
- return
- }
- for i := index; i < len(pos)-(target-len(c))+1; i++ {
- c = append(c, i)
- findLetterCasePermutation(s, pos, target, i+1, c, res)
- c = c[:len(c)-1]
- }
-}
-
-// 解法二,先讲第一个字母变大写,然后依次把后面的字母变大写。最终的解数组中答案是翻倍增长的
-// 第一步:
-// [mqe] -> [mqe, Mqe]
-// 第二步:
-// [mqe, Mqe] -> [mqe Mqe mQe MQe]
-// 第二步:
-// [mqe Mqe mQe MQe] -> [mqe Mqe mQe MQe mqE MqE mQE MQE]
-
-func letterCasePermutation1(S string) []string {
- res := make([]string, 0, 1<= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
-}
-
-func toUpper(s string, i int) string {
- b := []byte(s)
- b[i] -= 'a' - 'A'
- return string(b)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0786.K-th-Smallest-Prime-Fraction.md b/website/content/ChapterFour/0786.K-th-Smallest-Prime-Fraction.md
deleted file mode 100755
index 9646d5af7..000000000
--- a/website/content/ChapterFour/0786.K-th-Smallest-Prime-Fraction.md
+++ /dev/null
@@ -1,119 +0,0 @@
-# [786. K-th Smallest Prime Fraction](https://leetcode.com/problems/k-th-smallest-prime-fraction/)
-
-
-## 题目
-
-A sorted list `A` contains 1, plus some number of primes. Then, for every p < q in the list, we consider the fraction p/q.
-
-What is the `K`-th smallest fraction considered? Return your answer as an array of ints, where `answer[0] = p` and `answer[1] = q`.
-
-**Examples**:
-
- Input: A = [1, 2, 3, 5], K = 3
- Output: [2, 5]
- Explanation:
- The fractions to be considered in sorted order are:
- 1/5, 1/3, 2/5, 1/2, 3/5, 2/3.
- The third fraction is 2/5.
-
- Input: A = [1, 7], K = 1
- Output: [1, 7]
-
-**Note**:
-
-- `A` will have length between `2` and `2000`.
-- Each `A[i]` will be between `1` and `30000`.
-- `K` will be between `1` and `A.length * (A.length - 1) / 2`.
-
-
-## 题目大意
-
-一个已排序好的表 A,其包含 1 和其他一些素数. 当列表中的每一个 p float64(mid)*float64(A[j]) {
- j++
- }
- count += n - j
- if j < n && q*A[i] > p*A[j] {
- p = A[i]
- q = A[j]
- }
- }
- if count == K {
- return []int{p, q}
- } else if count < K {
- low = mid
- } else {
- high = mid
- }
- }
-}
-
-// 解法二 暴力解法,时间复杂度 O(n^2)
-func kthSmallestPrimeFraction1(A []int, K int) []int {
- if len(A) == 0 || (len(A)*(len(A)-1))/2 < K {
- return []int{}
- }
- fractions := []Fraction{}
- for i := 0; i < len(A); i++ {
- for j := i + 1; j < len(A); j++ {
- fractions = append(fractions, Fraction{molecule: A[i], denominator: A[j]})
- }
- }
- sort.Sort(SortByFraction(fractions))
- return []int{fractions[K-1].molecule, fractions[K-1].denominator}
-}
-
-// Fraction define
-type Fraction struct {
- molecule int
- denominator int
-}
-
-// SortByFraction define
-type SortByFraction []Fraction
-
-func (a SortByFraction) Len() int { return len(a) }
-func (a SortByFraction) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-func (a SortByFraction) Less(i, j int) bool {
- return a[i].molecule*a[j].denominator < a[j].molecule*a[i].denominator
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0793.Preimage-Size-of-Factorial-Zeroes-Function.md b/website/content/ChapterFour/0793.Preimage-Size-of-Factorial-Zeroes-Function.md
deleted file mode 100755
index b784e0465..000000000
--- a/website/content/ChapterFour/0793.Preimage-Size-of-Factorial-Zeroes-Function.md
+++ /dev/null
@@ -1,106 +0,0 @@
-# [793. Preimage Size of Factorial Zeroes Function](https://leetcode.com/problems/preimage-size-of-factorial-zeroes-function/)
-
-
-## 题目
-
-Let `f(x)` be the number of zeroes at the end of `x!`. (Recall that `x! = 1 * 2 * 3 * ... * x`, and by convention, `0! = 1`.)
-
-For example, `f(3) = 0` because 3! = 6 has no zeroes at the end, while `f(11) = 2` because 11! = 39916800 has 2 zeroes at the end. Given `K`, find how many non-negative integers `x` have the property that `f(x) = K`.
-
-**Example 1**:
-
- Input: K = 0
- Output: 5
- Explanation: 0!, 1!, 2!, 3!, and 4! end with K = 0 zeroes.
-
-**Example 2**:
-
- Input: K = 5
- Output: 0
- Explanation: There is no x such that x! ends in K = 5 zeroes.
-
-**Note**:
-
-- `K` will be an integer in the range `[0, 10^9]`.
-
-
-## 题目大意
-
-
-f(x) 是 x! 末尾是0的数量。(回想一下 x! = 1 * 2 * 3 * ... * x,且0! = 1)
-
-例如, f(3) = 0 ,因为3! = 6的末尾没有0;而 f(11) = 2 ,因为11!= 39916800末端有2个0。给定 K,找出多少个非负整数x ,有 f(x) = K 的性质。
-
-注意:
-
-- K 是范围在 [0, 10^9] 的整数。
-
-
-## 解题思路
-
-- 给出一个数 K,要求有多少个 n 能使得 n!末尾 0 的个数等于 K。
-- 这一题是基于第 172 题的逆过程加强版。第 172 题是给出 `n`,求得末尾 0 的个数。由第 172 题可以知道,`n!`末尾 0 的个数取决于因子 5 的个数。末尾可能有 `K` 个 0,那么 `n` 最多可以等于 `5 * K`,在 `[0, 5* K]` 区间内二分搜索,判断 `mid` 末尾 0 的个数,如果能找到 `K`,那么就范围 5,如果找不到这个 `K`,返回 0 。为什么答案取值只有 0 和 5 呢?因为当 `n` 增加 5 以后,因子 5 的个数又加一了,末尾又可以多 1 个或者多个 0(如果加 5 以后,有多个 5 的因子,例如 25,125,就有可能末尾增加多个 0)。所以有效的 `K` 值对应的 `n` 的范围区间就是 5 。反过来,无效的 `K` 值对应的 `n` 是 0。`K` 在 `5^n` 的分界线处会发生跳变,所有有些值取不到。例如,`n` 在 `[0,5)` 内取值,`K = 0`;`n` 在 `[5,10)` 内取值,`K = 1`;`n` 在 `[10,15)` 内取值,`K = 2`;`n` 在 `[15,20)` 内取值,`K = 3`;`n` 在 `[20,25)` 内取值,`K = 4`;`n` 在 `[25,30)` 内取值,`K = 6`,因为 25 提供了 2 个 5,也就提供了 2 个 0,所以 `K` 永远无法取值等于 5,即当 `K = 5` 时,找不到任何的 `n` 与之对应。
-- 这一题也可以用数学的方法解题。见解法二。这个解法的灵感来自于:n!末尾 0 的个数等于 [1,n] 所有数的因子 5 的个数总和。其次此题的结果一定只有 0 和 5 (分析见上一种解法)。有了这两个结论以后,就可以用数学的方法推导了。首先 n 可以表示为 5 进制的形式
-
-
-
- 上面式子中,所有有因子 5 的个数为:
-
-
-
-
- 这个总数就即是 K。针对不同的 n,an 的通项公式不同,所以表示的 K 的系数也不同。cn 的通项公式呢?
-
-
-
-
-
-
-
- 由上面这个递推还能推出通项公式(不过这题不适用通项公式,是用递推公式更方便):
-
-
-
- 判断 K 是否能表示成两个数列的表示形式,等价于判断 K 是否能转化为以 Cn 为基的变进制数。到此,转化成类似第 483 题了。代码实现不难,见解法二。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 二分搜索
-func preimageSizeFZF(K int) int {
- low, high := 0, 5*K
- for low <= high {
- mid := low + (high-low)>>1
- k := trailingZeroes(mid)
- if k == K {
- return 5
- } else if k > K {
- high = mid - 1
- } else {
- low = mid + 1
- }
- }
- return 0
-}
-
-// 解法二 数学方法
-func preimageSizeFZF1(K int) int {
- base := 0
- for base < K {
- base = base*5 + 1
- }
- for K > 0 {
- base = (base - 1) / 5
- if K/base == 5 {
- return 0
- }
- K %= base
- }
- return 5
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0802.Find-Eventual-Safe-States.md b/website/content/ChapterFour/0802.Find-Eventual-Safe-States.md
deleted file mode 100644
index f6879f300..000000000
--- a/website/content/ChapterFour/0802.Find-Eventual-Safe-States.md
+++ /dev/null
@@ -1,73 +0,0 @@
-# [802. Find Eventual Safe States](https://leetcode.com/problems/find-eventual-safe-states/)
-
-
-
-## 题目
-
-In a directed graph, we start at some node and every turn, walk along a directed edge of the graph. If we reach a node that is terminal (that is, it has no outgoing directed edges), we stop.
-
-Now, say our starting node is *eventually safe* if and only if we must eventually walk to a terminal node. More specifically, there exists a natural number `K` so that for any choice of where to walk, we must have stopped at a terminal node in less than `K` steps.
-
-Which nodes are eventually safe? Return them as an array in sorted order.
-
-The directed graph has `N` nodes with labels `0, 1, ..., N-1`, where `N` is the length of `graph`. The graph is given in the following form: `graph[i]` is a list of labels `j` such that `(i, j)` is a directed edge of the graph.
-
-```
-Example:
-Input: graph = [[1,2],[2,3],[5],[0],[5],[],[]]
-Output: [2,4,5,6]
-Here is a diagram of the above graph.
-```
-
-
-
-**Note**:
-
-- `graph` will have length at most `10000`.
-- The number of edges in the graph will not exceed `32000`.
-- Each `graph[i]` will be a sorted list of different integers, chosen within the range `[0, graph.length - 1]`.
-
-## 题目大意
-
-在有向图中, 我们从某个节点和每个转向处开始, 沿着图的有向边走。 如果我们到达的节点是终点 (即它没有连出的有向边), 我们停止。现在, 如果我们最后能走到终点,那么我们的起始节点是最终安全的。 更具体地说, 存在一个自然数 K, 无论选择从哪里开始行走, 我们走了不到 K 步后必能停止在一个终点。哪些节点最终是安全的? 结果返回一个有序的数组。
-
-提示:
-
-- graph 节点数不超过 10000.
-- 图的边数不会超过 32000.
-- 每个 graph[i] 被排序为不同的整数列表, 在区间 [0, graph.length - 1] 中选取。
-
-
-## 解题思路
-
-- 给出一个有向图,要求找出所有“安全”节点。“安全”节点的定义是:存在一个自然数 K, 无论选择从哪里开始行走, 我们走了不到 K 步后必能停止在一个终点。
-- 这一题可以用拓扑排序,也可以用 DFS 染色来解答。这里用 DFS 来解答。对于每个节点,我们有 3 种染色的方法:白色 0 号节点表示该节点还没有被访问过;灰色 1 号节点表示该节点在栈中(这一轮搜索中被访问过)或者在环中;黑色 2 号节点表示该节点的所有相连的节点都被访问过,且该节点不在环中。当我们第一次访问一个节点时,我们把它从白色变成灰色,并继续搜索与它相连的节点。如果在搜索过程中我们遇到一个灰色的节点,那么说明找到了一个环,此时退出搜索,所有的灰色节点保持不变(即从任意一个灰色节点开始,都能走到环中),如果搜索过程中,我们没有遇到灰色的节点,那么在回溯到当前节点时,我们把它从灰色变成黑色,即表示它是一个安全的节点。
-
-## 代码
-
-```go
-func eventualSafeNodes(graph [][]int) []int {
- res, color := []int{}, make([]int, len(graph))
- for i := range graph {
- if dfsEventualSafeNodes(graph, i, color) {
- res = append(res, i)
- }
- }
- return res
-}
-
-// colors: WHITE 0, GRAY 1, BLACK 2;
-func dfsEventualSafeNodes(graph [][]int, idx int, color []int) bool {
- if color[idx] > 0 {
- return color[idx] == 2
- }
- color[idx] = 1
- for i := range graph[idx] {
- if !dfsEventualSafeNodes(graph, graph[idx][i], color) {
- return false
- }
- }
- color[idx] = 2
- return true
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0803.Bricks-Falling-When-Hit.md b/website/content/ChapterFour/0803.Bricks-Falling-When-Hit.md
deleted file mode 100755
index 6f5335eda..000000000
--- a/website/content/ChapterFour/0803.Bricks-Falling-When-Hit.md
+++ /dev/null
@@ -1,125 +0,0 @@
-# [803. Bricks Falling When Hit](https://leetcode.com/problems/bricks-falling-when-hit/)
-
-
-## 题目
-
-We have a grid of 1s and 0s; the 1s in a cell represent bricks. A brick will not drop if and only if it is directly connected to the top of the grid, or at least one of its (4-way) adjacent bricks will not drop.
-
-We will do some erasures sequentially. Each time we want to do the erasure at the location (i, j), the brick (if it exists) on that location will disappear, and then some other bricks may drop because of that erasure.
-
-Return an array representing the number of bricks that will drop after each erasure in sequence.
-
-**Example 1**:
-
- Input:
- grid = [[1,0,0,0],[1,1,1,0]]
- hits = [[1,0]]
- Output: [2]
- Explanation:
- If we erase the brick at (1, 0), the brick at (1, 1) and (1, 2) will drop. So we should return 2.
-
-**Example 2**:
-
- Input:
- grid = [[1,0,0,0],[1,1,0,0]]
- hits = [[1,1],[1,0]]
- Output: [0,0]
- Explanation:
- When we erase the brick at (1, 0), the brick at (1, 1) has already disappeared due to the last move. So each erasure will cause no bricks dropping. Note that the erased brick (1, 0) will not be counted as a dropped brick.
-
-**Note**:
-
-- The number of rows and columns in the grid will be in the range [1, 200].
-- The number of erasures will not exceed the area of the grid.
-- It is guaranteed that each erasure will be different from any other erasure, and located inside the grid.
-- An erasure may refer to a location with no brick - if it does, no bricks drop.
-
-
-## 题目大意
-
-我们有一组包含1和0的网格;其中1表示砖块。 当且仅当一块砖直接连接到网格的顶部,或者它至少有一块相邻(4 个方向之一)砖块不会掉落时,它才不会落下。我们会依次消除一些砖块。每当我们消除 (i, j) 位置时, 对应位置的砖块(若存在)会消失,然后其他的砖块可能因为这个消除而落下。返回一个数组表示每次消除操作对应落下的砖块数目。
-
-
-注意:
-
-- 网格的行数和列数的范围是[1, 200]。
-- 消除的数字不会超过网格的区域。
-- 可以保证每次的消除都不相同,并且位于网格的内部。
-- 一个消除的位置可能没有砖块,如果这样的话,就不会有砖块落下。
-
-
-
-## 解题思路
-
-
-- 有一些砖块连接在天花板上,问,如果打掉某个砖块,会掉落几块砖块?打掉的每个砖块不参与计数。
-- 这一题可以用并查集和 DFS 求解。不过尝试用 DFS 的同学就会知道,这一题卡时间卡的很紧。用 DFS 虽然能 AC,但是耗时非常长。用并查集也必须进行秩压缩,不然耗时也非常长。另外,如果用了并查集,每个集合的总数单独统计,不随着 union() 操作,也会导致超时,笔者在这里被 LTE 了多次,最后只能重写 UnionFind 并查集类,将统计操作和 union() 操作写在一起,这一题才 faster than 100.00% AC。
-- 拿到题以后,首先尝试暴力解法,按照顺序打掉砖块,每次打掉砖块以后,都重建并查集。题目要求每次掉落几块砖块,实际上比较每次和天花板连通的砖块个数变化了多少块就可以了。那么解法就出来了,先把和天花板连通的砖块都 union() 起来,记录这个集合中砖块的个数 `count`,然后每次打掉一个砖块以后,重建并查集,计算与天花板连通的砖块的个数 `newCount`,`newCount - count -1` 就是最终答案(打掉的那块砖块不计算其中),提交代码以后,发现 TLE。
-- 出现 TLE 以后一般思路都是对的,只是时间复杂度过高,需要优化。很明显,需要优化的地方是每次都重建了新的并查集,有没有办法能在上一次状态上进行变更,不用重建并查集呢?如果正向的打掉砖块,那么每次还需要以这个砖块为起点进行 DFS,时间复杂度还是很高。如果反向考虑呢?先把所有要打掉的砖块都打掉,构建打掉这些砖块以后剩下与天花板连通的并查集。然后反向添加打掉的砖块,每次添加一块就刷新一次它周围的 4 个砖块,不用 DFS,这样时间复杂度优化了很多。最后在按照 `newCount - count -1` 方式计算最终答案。注意每次还原一个砖块的时候需要染色回原有砖块的颜色 `1` 。优化成这样的做法,基本不会 TLE 了,如果计算 count 是单独计算的,还是会 TLE。如果没有进行秩压缩,时间会超过 1500 ms,所以这一题想拿到 100%,每步优化都要做好。最终 100% 的答案见代码。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func hitBricks(grid [][]int, hits [][]int) []int {
- if len(hits) == 0 {
- return []int{}
- }
- uf, m, n, res, oriCount := template.UnionFindCount{}, len(grid), len(grid[0]), make([]int, len(hits)), 0
- uf.Init(m*n + 1)
- // 先将要打掉的砖块染色
- for _, hit := range hits {
- if grid[hit[0]][hit[1]] == 1 {
- grid[hit[0]][hit[1]] = 2
- }
- }
- for i := 0; i < m; i++ {
- for j := 0; j < n; j++ {
- if grid[i][j] == 1 {
- getUnionFindFromGrid(grid, i, j, uf)
- }
- }
- }
- oriCount = uf.Count()[uf.Find(m*n)]
- for i := len(hits) - 1; i >= 0; i-- {
- if grid[hits[i][0]][hits[i][1]] == 2 {
- grid[hits[i][0]][hits[i][1]] = 1
- getUnionFindFromGrid(grid, hits[i][0], hits[i][1], uf)
- }
- nowCount := uf.Count()[uf.Find(m*n)]
- if nowCount-oriCount > 0 {
- res[i] = nowCount - oriCount - 1
- } else {
- res[i] = 0
- }
- oriCount = nowCount
- }
- return res
-}
-
-func isInGrid(grid [][]int, x, y int) bool {
- return x >= 0 && x < len(grid) && y >= 0 && y < len(grid[0])
-}
-
-func getUnionFindFromGrid(grid [][]int, x, y int, uf template.UnionFindCount) {
- m, n := len(grid), len(grid[0])
- if x == 0 {
- uf.Union(m*n, x*n+y)
- }
- for i := 0; i < 4; i++ {
- nx := x + dir[i][0]
- ny := y + dir[i][1]
- if isInGrid(grid, nx, ny) && grid[nx][ny] == 1 {
- uf.Union(nx*n+ny, x*n+y)
- }
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0811.Subdomain-Visit-Count.md b/website/content/ChapterFour/0811.Subdomain-Visit-Count.md
deleted file mode 100755
index 69840bd97..000000000
--- a/website/content/ChapterFour/0811.Subdomain-Visit-Count.md
+++ /dev/null
@@ -1,143 +0,0 @@
-# [811. Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/)
-
-
-## 题目
-
-A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com". When we visit a domain like "discuss.leetcode.com", we will also visit the parent domains "leetcode.com" and "com" implicitly.
-
-Now, call a "count-paired domain" to be a count (representing the number of visits this domain received), followed by a space, followed by the address. An example of a count-paired domain might be "9001 discuss.leetcode.com".
-
-We are given a list `cpdomains` of count-paired domains. We would like a list of count-paired domains, (in the same format as the input, and in any order), that explicitly counts the number of visits to each subdomain.
-
-**Example 1**:
-
- Input:
- ["9001 discuss.leetcode.com"]
- Output:
- ["9001 discuss.leetcode.com", "9001 leetcode.com", "9001 com"]
- Explanation:
- We only have one website domain: "discuss.leetcode.com". As discussed above, the subdomain "leetcode.com" and "com" will also be visited. So they will all be visited 9001 times.
-
-**Example 2**:
-
- Input:
- ["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"]
- Output:
- ["901 mail.com","50 yahoo.com","900 google.mail.com","5 wiki.org","5 org","1 intel.mail.com","951 com"]
- Explanation:
- We will visit "google.mail.com" 900 times, "yahoo.com" 50 times, "intel.mail.com" once and "wiki.org" 5 times. For the subdomains, we will visit "mail.com" 900 + 1 = 901 times, "com" 900 + 50 + 1 = 951 times, and "org" 5 times.
-
-**Notes**:
-
-- The length of `cpdomains` will not exceed `100`.
-- The length of each domain name will not exceed `100`.
-- Each address will have either 1 or 2 "." characters.
-- The input count in any count-paired domain will not exceed `10000`.
-- The answer output can be returned in any order.
-
-
-## 题目大意
-
-
-一个网站域名,如 "discuss.leetcode.com",包含了多个子域名。作为顶级域名,常用的有 "com",下一级则有 "leetcode.com",最低的一级为 "discuss.leetcode.com"。当我们访问域名 "discuss.leetcode.com" 时,也同时访问了其父域名 "leetcode.com" 以及顶级域名 "com"。给定一个带访问次数和域名的组合,要求分别计算每个域名被访问的次数。其格式为访问次数+空格+地址,例如:"9001 discuss.leetcode.com"。
-
-接下来会给出一组访问次数和域名组合的列表 cpdomains 。要求解析出所有域名的访问次数,输出格式和输入格式相同,不限定先后顺序。
-
-
-
-## 解题思路
-
-
-- 这一题是简单题,统计每个 domain 的出现频次。每个域名根据层级,一级一级的累加频次,比如 `discuss.leetcode.com`、`discuss.leetcode.com` 这个域名频次为 1,`leetcode.com` 这个域名频次为 1,`com` 这个域名频次为 1。用 map 依次统计每个 domain 出现的频次,按照格式要求输出。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "strconv"
- "strings"
-)
-
-// 解法一
-func subdomainVisits(cpdomains []string) []string {
- result := make([]string, 0)
- if len(cpdomains) == 0 {
- return result
- }
- domainCountMap := make(map[string]int, 0)
- for _, domain := range cpdomains {
- countDomain := strings.Split(domain, " ")
- allDomains := strings.Split(countDomain[1], ".")
- temp := make([]string, 0)
- for i := len(allDomains) - 1; i >= 0; i-- {
- temp = append([]string{allDomains[i]}, temp...)
- ld := strings.Join(temp, ".")
- count, _ := strconv.Atoi(countDomain[0])
- if val, ok := domainCountMap[ld]; !ok {
- domainCountMap[ld] = count
- } else {
- domainCountMap[ld] = count + val
- }
- }
- }
- for k, v := range domainCountMap {
- t := strings.Join([]string{strconv.Itoa(v), k}, " ")
- result = append(result, t)
- }
- return result
-}
-
-// 解法二
-func subdomainVisits1(cpdomains []string) []string {
- out := make([]string, 0)
- var b strings.Builder
- domains := make(map[string]int, 0)
- for _, v := range cpdomains {
- splitDomain(v, domains)
- }
- for k, v := range domains {
- b.WriteString(strconv.Itoa(v))
- b.WriteString(" ")
- b.WriteString(k)
- out = append(out, b.String())
- b.Reset()
- }
- return out
-}
-
-func splitDomain(domain string, domains map[string]int) {
- visits := 0
- var e error
- subdomains := make([]string, 0)
- for i, v := range domain {
- if v == ' ' {
- visits, e = strconv.Atoi(domain[0:i])
- if e != nil {
- panic(e)
- }
- break
- }
- }
- for i := len(domain) - 1; i >= 0; i-- {
- if domain[i] == '.' {
- subdomains = append(subdomains, domain[i+1:])
- } else if domain[i] == ' ' {
- subdomains = append(subdomains, domain[i+1:])
- break
- }
- }
- for _, v := range subdomains {
- count, ok := domains[v]
- if ok {
- domains[v] = count + visits
- } else {
- domains[v] = visits
- }
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0812.Largest-Triangle-Area.md b/website/content/ChapterFour/0812.Largest-Triangle-Area.md
deleted file mode 100644
index 426826f15..000000000
--- a/website/content/ChapterFour/0812.Largest-Triangle-Area.md
+++ /dev/null
@@ -1,70 +0,0 @@
-# [812. Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area/)
-
-
-## 题目
-
-You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points.
-
-```
-Example:
-Input: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]
-Output: 2
-Explanation:
-The five points are show in the figure below. The red triangle is the largest.
-```
-
-
-
-**Notes**:
-
-- `3 <= points.length <= 50`.
-- No points will be duplicated.
-- `-50 <= points[i][j] <= 50`.
-- Answers within `10^-6` of the true value will be accepted as correct.
-
-## 题目大意
-
-给定包含多个点的集合,从其中取三个点组成三角形,返回能组成的最大三角形的面积。
-
-## 解题思路
-
-- 给出一组点的坐标,要求找出能组成三角形面积最大的点集合,输出这个最大面积。
-- 数学题。按照数学定义,分别计算这些能构成三角形的点形成的三角形面积,最终输出最大面积即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func largestTriangleArea(points [][]int) float64 {
- maxArea, n := 0.0, len(points)
- for i := 0; i < n; i++ {
- for j := i + 1; j < n; j++ {
- for k := j + 1; k < n; k++ {
- maxArea = max(maxArea, area(points[i], points[j], points[k]))
- }
- }
- }
- return maxArea
-}
-
-func area(p1, p2, p3 []int) float64 {
- return abs(p1[0]*p2[1]+p2[0]*p3[1]+p3[0]*p1[1]-p1[0]*p3[1]-p2[0]*p1[1]-p3[0]*p2[1]) / 2
-}
-
-func abs(num int) float64 {
- if num < 0 {
- num = -num
- }
- return float64(num)
-}
-
-func max(a, b float64) float64 {
- if a > b {
- return a
- }
- return b
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0815.Bus-Routes.md b/website/content/ChapterFour/0815.Bus-Routes.md
deleted file mode 100755
index bddbd3b07..000000000
--- a/website/content/ChapterFour/0815.Bus-Routes.md
+++ /dev/null
@@ -1,88 +0,0 @@
-# [815. Bus Routes](https://leetcode.com/problems/bus-routes/)
-
-
-## 题目
-
-We have a list of bus routes. Each `routes[i]` is a bus route that the i-th bus repeats forever. For example if `routes[0] = [1, 5, 7]`, this means that the first bus (0-th indexed) travels in the sequence 1->5->7->1->5->7->1->... forever.
-
-We start at bus stop `S` (initially not on a bus), and we want to go to bus stop `T`. Travelling by buses only, what is the least number of buses we must take to reach our destination? Return -1 if it is not possible.
-
-**Example**:
-
- Input:
- routes = [[1, 2, 7], [3, 6, 7]]
- S = 1
- T = 6
- Output: 2
- Explanation:
- The best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.
-
-**Note**:
-
-- `1 <= routes.length <= 500`.
-- `1 <= routes[i].length <= 500`.
-- `0 <= routes[i][j] < 10 ^ 6`.
-
-
-## 题目大意
-
-我们有一系列公交路线。每一条路线 routes[i] 上都有一辆公交车在上面循环行驶。例如,有一条路线 routes[0] = [1, 5, 7],表示第一辆 (下标为0) 公交车会一直按照 1->5->7->1->5->7->1->... 的车站路线行驶。假设我们从 S 车站开始(初始时不在公交车上),要去往 T 站。 期间仅可乘坐公交车,求出最少乘坐的公交车数量。返回 -1 表示不可能到达终点车站。
-
-
-说明:
-
-- 1 <= routes.length <= 500.
-- 1 <= routes[i].length <= 500.
-- 0 <= routes[i][j] < 10 ^ 6.
-
-
-## 解题思路
-
-- 给出一些公交路线,公交路径代表经过的哪些站。现在给出起点和终点站,问最少需要换多少辆公交车才能从起点到终点?
-- 这一题可以转换成图论的问题,将每个站台看成顶点,公交路径看成每个顶点的边。同一个公交的边染色相同。题目即可转化为从顶点 S 到顶点 T 需要经过最少多少条不同的染色边。用 BFS 即可轻松解决。从起点 S 开始,不断的扩展它能到达的站点。用 visited 数组防止放入已经可达的站点引起的环。用 map 存储站点和公交车的映射关系(即某个站点可以由哪些公交车到达),BFS 的过程中可以用这个映射关系,拿到公交车的其他站点信息,从而扩张队列里面的可达站点。一旦扩展出现了终点 T,就可以返回结果了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func numBusesToDestination(routes [][]int, S int, T int) int {
- if S == T {
- return 0
- }
- // vertexMap 中 key 是站点,value 是公交车数组,代表这些公交车路线可以到达此站点
- vertexMap, visited, queue, res := map[int][]int{}, make([]bool, len(routes)), []int{}, 0
- for i := 0; i < len(routes); i++ {
- for _, v := range routes[i] {
- tmp := vertexMap[v]
- tmp = append(tmp, i)
- vertexMap[v] = tmp
- }
- }
- queue = append(queue, S)
- for len(queue) > 0 {
- res++
- qlen := len(queue)
- for i := 0; i < qlen; i++ {
- vertex := queue[0]
- queue = queue[1:]
- for _, bus := range vertexMap[vertex] {
- if visited[bus] == true {
- continue
- }
- visited[bus] = true
- for _, v := range routes[bus] {
- if v == T {
- return res
- }
- queue = append(queue, v)
- }
- }
- }
- }
- return -1
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0817.Linked-List-Components.md b/website/content/ChapterFour/0817.Linked-List-Components.md
deleted file mode 100644
index a04153712..000000000
--- a/website/content/ChapterFour/0817.Linked-List-Components.md
+++ /dev/null
@@ -1,109 +0,0 @@
-# [817. Linked List Components](https://leetcode.com/problems/linked-list-components/)
-
-## 题目
-
-We are given head, the head node of a linked list containing unique integer values.
-
-We are also given the list G, a subset of the values in the linked list.
-
-Return the number of connected components in G, where two values are connected if they appear consecutively in the linked list.
-
-**Example 1**:
-
-```
-
-Input:
-head: 0->1->2->3
-G = [0, 1, 3]
-Output: 2
-Explanation:
-0 and 1 are connected, so [0, 1] and [3] are the two connected components.
-
-```
-
-**Example 2**:
-
-```
-
-Input:
-head: 0->1->2->3->4
-G = [0, 3, 1, 4]
-Output: 2
-Explanation:
-0 and 1 are connected, 3 and 4 are connected, so [0, 1] and [3, 4] are the two connected components.
-
-```
-
-**Note**:
-
-- If N is the length of the linked list given by head, 1 <= N <= 10000.
-- The value of each node in the linked list will be in the range [0, N - 1].
-- 1 <= G.length <= 10000.
-- G is a subset of all values in the linked list.
-
-
-
-## 题目大意
-
-这道题题目的意思描述的不是很明白,我提交了几次 WA 以后才悟懂题意。
-
-这道题的意思是,在 G 中能组成多少组子链表,这些子链表的要求是能在原链表中是有序的。
-
-## 解题思路
-
-这个问题再抽象一下就成为这样:在原链表中去掉 G 中不存在的数,会被切断成几段链表。例如,将原链表中 G 中存在的数标为 0,不存在的数标为 1 。原链表标识为 0-0-0-1-0-1-1-0-0-1-0-1,那么这样原链表被断成了 4 段。只要在链表中找 0-1 组合就可以认为是一段,因为这里必定会有一段生成。
-
-考虑末尾的情况,0-1,1-0,0-0,1-1,这 4 种情况的特征都是,末尾一位只要是 0,都会新产生一段。所以链表末尾再单独判断一次,是 0 就再加一。
-
-
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for singly-linked list.
- * type ListNode struct {
- * Val int
- * Next *ListNode
- * }
- */
-
-func numComponents(head *ListNode, G []int) int {
- if head.Next == nil {
- return 1
- }
- gMap := toMap(G)
- count := 0
- cur := head
-
- for cur != nil {
- if _, ok := gMap[cur.Val]; ok {
- if cur.Next == nil { // 末尾存在,直接加一
- count++
- } else {
- if _, ok = gMap[cur.Next.Val]; !ok {
- count++
- }
- }
- }
- cur = cur.Next
- }
- return count
-}
-
-func toMap(G []int) map[int]int {
- GMap := make(map[int]int, 0)
- for _, value := range G {
- GMap[value] = 0
- }
- return GMap
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0819.Most-Common-Word.md b/website/content/ChapterFour/0819.Most-Common-Word.md
deleted file mode 100755
index e37b45ee4..000000000
--- a/website/content/ChapterFour/0819.Most-Common-Word.md
+++ /dev/null
@@ -1,89 +0,0 @@
-# [819. Most Common Word](https://leetcode.com/problems/most-common-word/)
-
-
-## 题目
-
-Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn't banned, and that the answer is unique.
-
-Words in the list of banned words are given in lowercase, and free of punctuation. Words in the paragraph are not case sensitive. The answer is in lowercase.
-
-**Example**:
-
- Input:
- paragraph = "Bob hit a ball, the hit BALL flew far after it was hit."
- banned = ["hit"]
- Output: "ball"
- Explanation:
- "hit" occurs 3 times, but it is a banned word.
- "ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph.
- Note that words in the paragraph are not case sensitive,
- that punctuation is ignored (even if adjacent to words, such as "ball,"),
- and that "hit" isn't the answer even though it occurs more because it is banned.
-
-**Note**:
-
-- `1 <= paragraph.length <= 1000`.
-- `0 <= banned.length <= 100`.
-- `1 <= banned[i].length <= 10`.
-- The answer is unique, and written in lowercase (even if its occurrences in `paragraph` may have uppercase symbols, and even if it is a proper noun.)
-- `paragraph` only consists of letters, spaces, or the punctuation symbols `!?',;.`
-- There are no hyphens or hyphenated words.
-- Words only consist of letters, never apostrophes or other punctuation symbols.
-
-
-## 题目大意
-
-
-给定一个段落 (paragraph) 和一个禁用单词列表 (banned)。返回出现次数最多,同时不在禁用列表中的单词。题目保证至少有一个词不在禁用列表中,而且答案唯一。
-
-禁用列表中的单词用小写字母表示,不含标点符号。段落中的单词不区分大小写。答案都是小写字母。
-
-
-## 解题思路
-
-- 给出一段话和一个 banned 的字符串,要求输出这段话中出现频次最高的并且不出现在 banned 数组里面的字符串,答案唯一。这题是简单题,依次统计每个单词的频次,然后从 map 中删除 banned 里面的单词,取出剩下频次最高的单词即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strings"
-
-func mostCommonWord(paragraph string, banned []string) string {
- freqMap, start := make(map[string]int), -1
- for i, c := range paragraph {
- if c == ' ' || c == '!' || c == '?' || c == '\'' || c == ',' || c == ';' || c == '.' {
- if start > -1 {
- word := strings.ToLower(paragraph[start:i])
- freqMap[word]++
- }
- start = -1
- } else {
- if start == -1 {
- start = i
- }
- }
- }
- if start != -1 {
- word := strings.ToLower(paragraph[start:])
- freqMap[word]++
- }
- // Strip the banned words from the freqmap
- for _, bannedWord := range banned {
- delete(freqMap, bannedWord)
- }
- // Find most freq word
- mostFreqWord, mostFreqCount := "", 0
- for word, freq := range freqMap {
- if freq > mostFreqCount {
- mostFreqWord = word
- mostFreqCount = freq
- }
- }
- return mostFreqWord
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0826.Most-Profit-Assigning-Work.md b/website/content/ChapterFour/0826.Most-Profit-Assigning-Work.md
deleted file mode 100644
index 33059b959..000000000
--- a/website/content/ChapterFour/0826.Most-Profit-Assigning-Work.md
+++ /dev/null
@@ -1,107 +0,0 @@
-# [826. Most Profit Assigning Work](https://leetcode.com/problems/most-profit-assigning-work/)
-
-## 题目
-
-We have jobs: difficulty[i] is the difficulty of the ith job, and profit[i] is the profit of the ith job.
-
-Now we have some workers. worker[i] is the ability of the ith worker, which means that this worker can only complete a job with difficulty at most worker[i].
-
-Every worker can be assigned at most one job, but one job can be completed multiple times.
-
-For example, if 3 people attempt the same job that pays $1, then the total profit will be $3. If a worker cannot complete any job, his profit is $0.
-
-What is the most profit we can make?
-
-
-**Example 1**:
-
-
-```
-
-Input: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]
-Output: 100
-Explanation: Workers are assigned jobs of difficulty [4,4,6,6] and they get profit of [20,20,30,30] seperately.
-
-```
-
-**Note**:
-
-- 1 <= difficulty.length = profit.length <= 10000
-- 1 <= worker.length <= 10000
-- difficulty[i], profit[i], worker[i] are in range [1, 10^5]
-
-
-## 题目大意
-
-这道题考察的是滑动窗口的问题,也是排序相关的问题。
-
-给出一组任务,每个任务都有一定的难度,每个任务也都有完成以后对应的收益(完成难的任务不一定收益最高)。有一批工人,每个人能处理的任务难度不同。要求输出这批工人完成任务以后的最大收益。
-
-## 解题思路
-
-先将任务按照难度排序,工人也按照能处理任务难度的能力排序。用一个数组记录下,每个 i 下标,当前能达到的最大收益。计算这个收益只需要从下标为 1 开始,依次比较自己和前一个的收益即可(因为排过序,难度是依次递增的)。有了这个难度依次递增,并且记录了最大收益的数组以后,就可以计算最终结果了。遍历一遍工人数组,如果工人的能力大于任务的难度,就加上这个最大收益。遍历完工人数组,最终结果就是最大收益。
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "fmt"
- "sort"
-)
-
-// Task define
-type Task struct {
- Difficulty int
- Profit int
-}
-
-// Tasks define
-type Tasks []Task
-
-// Len define
-func (p Tasks) Len() int { return len(p) }
-
-// Swap define
-func (p Tasks) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
-
-// SortByDiff define
-type SortByDiff struct{ Tasks }
-
-// Less define
-func (p SortByDiff) Less(i, j int) bool {
- return p.Tasks[i].Difficulty < p.Tasks[j].Difficulty
-}
-
-func maxProfitAssignment(difficulty []int, profit []int, worker []int) int {
- if len(difficulty) == 0 || len(profit) == 0 || len(worker) == 0 {
- return 0
- }
- tasks, res, index := []Task{}, 0, 0
- for i := 0; i < len(difficulty); i++ {
- tasks = append(tasks, Task{Difficulty: difficulty[i], Profit: profit[i]})
- }
- sort.Sort(SortByDiff{tasks})
- sort.Ints(worker)
- for i := 1; i < len(tasks); i++ {
- tasks[i].Profit = max(tasks[i].Profit, tasks[i-1].Profit)
- }
- fmt.Printf("tasks = %v worker = %v\n", tasks, worker)
- for _, w := range worker {
- for index < len(difficulty) && w >= tasks[index].Difficulty {
- index++
- }
- fmt.Printf("tasks【index】 = %v\n", tasks[index])
- if index > 0 {
- res += tasks[index-1].Profit
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0832.Flipping-an-Image.md b/website/content/ChapterFour/0832.Flipping-an-Image.md
deleted file mode 100644
index 81b8ccc97..000000000
--- a/website/content/ChapterFour/0832.Flipping-an-Image.md
+++ /dev/null
@@ -1,63 +0,0 @@
-# [832. Flipping an Image](https://leetcode.com/problems/flipping-an-image/)
-
-
-## 题目
-
-Given a binary matrix `A`, we want to flip the image horizontally, then invert it, and return the resulting image.
-
-To flip an image horizontally means that each row of the image is reversed. For example, flipping `[1, 1, 0]` horizontally results in `[0, 1, 1]`.
-
-To invert an image means that each `0` is replaced by `1`, and each `1` is replaced by `0`. For example, inverting `[0, 1, 1]` results in `[1, 0, 0]`.
-
-**Example 1**:
-
-```
-Input: [[1,1,0],[1,0,1],[0,0,0]]
-Output: [[1,0,0],[0,1,0],[1,1,1]]
-Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].
-Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]]
-```
-
-**Example 2**:
-
-```
-Input: [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
-Output: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
-Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].
-Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
-```
-
-**Notes**:
-
-- `1 <= A.length = A[0].length <= 20`
-- `0 <= A[i][j] <= 1`
-
-## 题目大意
-
-给定一个二进制矩阵 A,我们想先水平翻转图像,然后反转图像并返回结果。水平翻转图片就是将图片的每一行都进行翻转,即逆序。例如,水平翻转 [1, 1, 0] 的结果是 [0, 1, 1]。反转图片的意思是图片中的 0 全部被 1 替换, 1 全部被 0 替换。例如,反转 [0, 1, 1] 的结果是 [1, 0, 0]。
-
-
-## 解题思路
-
-- 给定一个二进制矩阵,要求先水平翻转,然后再反转( 1→0 , 0→1 )。
-- 简单题,按照题意先水平翻转,再反转即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func flipAndInvertImage(A [][]int) [][]int {
- for i := 0; i < len(A); i++ {
- for a, b := 0, len(A[i])-1; a < b; a, b = a+1, b-1 {
- A[i][a], A[i][b] = A[i][b], A[i][a]
- }
- for a := 0; a < len(A[i]); a++ {
- A[i][a] = (A[i][a] + 1) % 2
- }
- }
- return A
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0834.Sum-of-Distances-in-Tree.md b/website/content/ChapterFour/0834.Sum-of-Distances-in-Tree.md
deleted file mode 100755
index b0390a4aa..000000000
--- a/website/content/ChapterFour/0834.Sum-of-Distances-in-Tree.md
+++ /dev/null
@@ -1,101 +0,0 @@
-# [834. Sum of Distances in Tree](https://leetcode.com/problems/sum-of-distances-in-tree/)
-
-
-## 题目
-
-An undirected, connected tree with `N` nodes labelled `0...N-1` and `N-1edges` are given.
-
-The `i`th edge connects nodes `edges[i][0]` and `edges[i][1]` together.
-
-Return a list `ans`, where `ans[i]` is the sum of the distances between node `i`and all other nodes.
-
-**Example 1**:
-
- Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
- Output: [8,12,6,10,10,10]
- Explanation:
- Here is a diagram of the given tree:
- 0
- / \
- 1 2
- /|\
- 3 4 5
- We can see that dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5)
- equals 1 + 1 + 2 + 2 + 2 = 8. Hence, answer[0] = 8, and so on.
-
-**Note**: `1 <= N <= 10000`
-
-## 题目大意
-
-给定一个无向、连通的树。树中有 N 个标记为 0...N-1 的节点以及 N-1 条边。第 i 条边连接节点 edges[i][0] 和 edges[i][1] 。返回一个表示节点 i 与其他所有节点距离之和的列表 ans。
-
-说明: 1 <= N <= 10000
-
-
-
-## 解题思路
-
-- 给出 N 个节点和这些节点之间的一些边的关系。要求求出分别以 x 为根节点到所有节点路径和。
-- 这一题虽说描述的是求树的路径,但是完全可以当做图来做,因为并不是二叉树,是多叉树。这一题的解题思路是先一次 DFS 求出以 0 为根节点到各个节点的路径和(不以 0 为节点也可以,可以取任意节点作为开始)。第二次 DFS 求出从 0 根节点转换到其他各个节点的路径和。由于第一次计算出来以 0 为节点的路径和是正确的,所以计算其他节点为根节点的路径和只需要转换一下就可以得到正确结果。经过 2 次 DFS 之后就可以得到所有节点以自己为根节点到所有节点的路径和了。
-- 如何从以 0 为根节点到其他所有节点的路径和转换到以其他节点为根节点到所有节点的路径和呢?从 0 节点换成 x 节点,只需要在 0 到所有节点的路径和基础上增增减减就可以了。增加的是 x 节点到除去以 x 为根节点所有子树以外的节点的路径,有多少个节点就增加多少条路径。减少的是 0 到以 x 为根节点所有子树节点的路径和,包含 0 到 x 根节点,有多少节点就减少多少条路径。所以在第一次 DFS 中需要计算好每个节点以自己为根节点的子树总数和(包含自己在内),这样在第二次 DFS 中可以直接拿来做转换。具体细节的实现见代码。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func sumOfDistancesInTree(N int, edges [][]int) []int {
- // count[i] 中存储的是以 i 为根节点,所有子树结点和根节点的总数
- tree, visited, count, res := make([][]int, N), make([]bool, N), make([]int, N), make([]int, N)
- for _, e := range edges {
- i, j := e[0], e[1]
- tree[i] = append(tree[i], j)
- tree[j] = append(tree[j], i)
- }
- deepFirstSearch(0, visited, count, res, tree)
- // 重置访问状态,再进行一次 DFS
- visited = make([]bool, N)
- // 进入第二次 DFS 之前,只有 res[0] 里面存的是正确的值,因为第一次 DFS 计算出了以 0 为根节点的所有路径和
- // 第二次 DFS 的目的是把以 0 为根节点的路径和转换成以 n 为根节点的路径和
- deepSecondSearch(0, visited, count, res, tree)
-
- return res
-}
-
-func deepFirstSearch(root int, visited []bool, count, res []int, tree [][]int) {
- visited[root] = true
- for _, n := range tree[root] {
- if visited[n] {
- continue
- }
- deepFirstSearch(n, visited, count, res, tree)
- count[root] += count[n]
- // root 节点到 n 的所有路径和 = 以 n 为根节点到所有子树的路径和 res[n] + root 到 count[n] 中每个节点的个数(root 节点和以 n 为根节点的每个节点都增加一条路径)
- // root 节点和以 n 为根节点的每个节点都增加一条路径 = 以 n 为根节点,子树节点数和根节点数的总和,即 count[n]
- res[root] += res[n] + count[n]
- }
- count[root]++
-}
-
-// 从 root 开始,把 root 节点的子节点,依次设置成新的根节点
-func deepSecondSearch(root int, visited []bool, count, res []int, tree [][]int) {
- N := len(visited)
- visited[root] = true
- for _, n := range tree[root] {
- if visited[n] {
- continue
- }
- // 根节点从 root 变成 n 后
- // res[root] 存储的是以 root 为根节点到所有节点的路径总长度
- // 1. root 到 n 节点增加的路径长度 = root 节点和以 n 为根节点的每个节点都增加一条路径 = 以 n 为根节点,子树节点数和根节点数的总和,即 count[n]
- // 2. n 到以 n 为根节点的所有子树节点以外的节点增加的路径长度 = n 节点和非 n 为根节点子树的每个节点都增加一条路径 = N - count[n]
- // 所以把根节点从 root 转移到 n,需要增加的路径是上面👆第二步计算的,需要减少的路径是上面👆第一步计算的
- res[n] = res[root] + (N - count[n]) - count[n]
- deepSecondSearch(n, visited, count, res, tree)
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0836.Rectangle-Overlap.md b/website/content/ChapterFour/0836.Rectangle-Overlap.md
deleted file mode 100755
index 2cce0169b..000000000
--- a/website/content/ChapterFour/0836.Rectangle-Overlap.md
+++ /dev/null
@@ -1,54 +0,0 @@
-# [836. Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap/)
-
-
-## 题目
-
-A rectangle is represented as a list `[x1, y1, x2, y2]`, where `(x1, y1)` are the coordinates of its bottom-left corner, and `(x2, y2)` are the coordinates of its top-right corner.
-
-Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.
-
-Given two (axis-aligned) rectangles, return whether they overlap.
-
-**Example 1**:
-
- Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3]
- Output: true
-
-**Example 2**:
-
- Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1]
- Output: false
-
-**Notes**:
-
-1. Both rectangles `rec1` and `rec2` are lists of 4 integers.
-2. All coordinates in rectangles will be between `-10^9` and `10^9`.
-
-
-## 题目大意
-
-矩形以列表 [x1, y1, x2, y2] 的形式表示,其中 (x1, y1) 为左下角的坐标,(x2, y2) 是右上角的坐标。如果相交的面积为正,则称两矩形重叠。需要明确的是,只在角或边接触的两个矩形不构成重叠。给出两个矩形,判断它们是否重叠并返回结果。
-
-说明:
-
-1. 两个矩形 rec1 和 rec2 都以含有四个整数的列表的形式给出。
-2. 矩形中的所有坐标都处于 -10^9 和 10^9 之间。
-
-
-## 解题思路
-
-- 给出两个矩形的坐标,判断两个矩形是否重叠。
-- 几何题,按照几何方法判断即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func isRectangleOverlap(rec1 []int, rec2 []int) bool {
- return rec1[0] < rec2[2] && rec2[0] < rec1[2] && rec1[1] < rec2[3] && rec2[1] < rec1[3]
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0838.Push-Dominoes.md b/website/content/ChapterFour/0838.Push-Dominoes.md
deleted file mode 100644
index 7acc9ce53..000000000
--- a/website/content/ChapterFour/0838.Push-Dominoes.md
+++ /dev/null
@@ -1,144 +0,0 @@
-# [838. Push Dominoes](https://leetcode.com/problems/push-dominoes/)
-
-## 题目
-
-There are N dominoes in a line, and we place each domino vertically upright.
-
-In the beginning, we simultaneously push some of the dominoes either to the left or to the right.
-
-
-
-
-After each second, each domino that is falling to the left pushes the adjacent domino on the left.
-
-Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.
-
-When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.
-
-For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.
-
-Given a string "S" representing the initial state. S[i] = 'L', if the i-th domino has been pushed to the left; S[i] = 'R', if the i-th domino has been pushed to the right; S[i] = '.', if the i-th domino has not been pushed.
-
-Return a string representing the final state.
-
-
-**Example 1**:
-
-```
-
-Input: ".L.R...LR..L.."
-Output: "LL.RR.LLRRLL.."
-
-```
-
-**Example 2**:
-
-```
-
-Input: "RR.L"
-Output: "RR.L"
-Explanation: The first domino expends no additional force on the second domino.
-
-```
-
-
-**Note**:
-
-- 0 <= N <= 10^5
-- String dominoes contains only 'L', 'R' and '.'
-
-
-## 题目大意
-
-这道题是一个道模拟题,考察的也是滑动窗口的问题。
-
-给出一个字符串,L 代表这个多米诺骨牌会往左边倒,R 代表这个多米诺骨牌会往右边倒,问最终这些牌倒下去以后,情况是如何的,输出最终情况的字符串。
-
-## 解题思路
-
-这道题可以预先在初始字符串头和尾都添加一个字符串,左边添加 L,右边添加 R,辅助判断。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一
-func pushDominoes(dominoes string) string {
- d := []byte(dominoes)
- for i := 0; i < len(d); {
- j := i + 1
- for j < len(d)-1 && d[j] == '.' {
- j++
- }
- push(d[i : j+1])
- i = j
- }
- return string(d)
-}
-
-func push(d []byte) {
- first, last := 0, len(d)-1
- switch d[first] {
- case '.', 'L':
- if d[last] == 'L' {
- for ; first < last; first++ {
- d[first] = 'L'
- }
- }
- case 'R':
- if d[last] == '.' || d[last] == 'R' {
- for ; first <= last; first++ {
- d[first] = 'R'
- }
- } else if d[last] == 'L' {
- for first < last {
- d[first] = 'R'
- d[last] = 'L'
- first++
- last--
- }
- }
- }
-}
-
-// 解法二
-func pushDominoes1(dominoes string) string {
- dominoes = "L" + dominoes + "R"
- res := ""
- for i, j := 0, 1; j < len(dominoes); j++ {
- if dominoes[j] == '.' {
- continue
- }
- if i > 0 {
- res += string(dominoes[i])
- }
- middle := j - i - 1
- if dominoes[i] == dominoes[j] {
- for k := 0; k < middle; k++ {
- res += string(dominoes[i])
- }
- } else if dominoes[i] == 'L' && dominoes[j] == 'R' {
- for k := 0; k < middle; k++ {
- res += string('.')
- }
- } else {
- for k := 0; k < middle/2; k++ {
- res += string('R')
- }
- for k := 0; k < middle%2; k++ {
- res += string('.')
- }
- for k := 0; k < middle/2; k++ {
- res += string('L')
- }
- }
- i = j
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0839.Similar-String-Groups.md b/website/content/ChapterFour/0839.Similar-String-Groups.md
deleted file mode 100755
index 217ee2da3..000000000
--- a/website/content/ChapterFour/0839.Similar-String-Groups.md
+++ /dev/null
@@ -1,98 +0,0 @@
-# [839. Similar String Groups](https://leetcode.com/problems/similar-string-groups/)
-
-
-## 题目
-
-Two strings `X` and `Y` are similar if we can swap two letters (in different positions) of `X`, so that it equals `Y`.
-
-For example, `"tars"` and `"rats"` are similar (swapping at positions `0` and `2`), and `"rats"` and `"arts"` are similar, but `"star"` is not similar to `"tars"`, `"rats"`, or `"arts"`.
-
-Together, these form two connected groups by similarity: `{"tars", "rats", "arts"}` and `{"star"}`. Notice that `"tars"` and `"arts"` are in the same group even though they are not similar. Formally, each group is such that a word is in the group if and only if it is similar to at least one other word in the group.
-
-We are given a list `A` of strings. Every string in `A` is an anagram of every other string in `A`. How many groups are there?
-
-**Example 1**:
-
- Input: ["tars","rats","arts","star"]
- Output: 2
-
-**Note**:
-
-1. `A.length <= 2000`
-2. `A[i].length <= 1000`
-3. `A.length * A[i].length <= 20000`
-4. All words in `A` consist of lowercase letters only.
-5. All words in `A` have the same length and are anagrams of each other.
-6. The judging time limit has been increased for this question.
-
-
-## 题目大意
-
-如果我们交换字符串 X 中的两个不同位置的字母,使得它和字符串 Y 相等,那么称 X 和 Y 两个字符串相似。
-
-例如,"tars" 和 "rats" 是相似的 (交换 0 与 2 的位置); "rats" 和 "arts" 也是相似的,但是 "star" 不与 "tars","rats",或 "arts" 相似。
-
-总之,它们通过相似性形成了两个关联组:{"tars", "rats", "arts"} 和 {"star"}。注意,"tars" 和 "arts" 是在同一组中,即使它们并不相似。形式上,对每个组而言,要确定一个单词在组中,只需要这个词和该组中至少一个单词相似。我们给出了一个不包含重复的字符串列表 A。列表中的每个字符串都是 A 中其它所有字符串的一个字母异位词。请问 A 中有多少个相似字符串组?
-
-
-提示:
-
-- A.length <= 2000
-- A[i].length <= 1000
-- A.length * A[i].length <= 20000
-- A 中的所有单词都只包含小写字母。
-- A 中的所有单词都具有相同的长度,且是彼此的字母异位词。
-- 此问题的判断限制时间已经延长。
-
-
-备注:
-
-- 字母异位词[anagram],一种把某个字符串的字母的位置(顺序)加以改换所形成的新词。
-
-
-
-
-## 解题思路
-
-
-- 给出一个字符串数组,要求找出这个数组中,"不相似"的字符串有多少种。相似的字符串的定义是:如果 A 和 B 字符串只需要交换一次字母的位置就能变成两个相等的字符串,那么 A 和 B 是相似的。
-- 这一题的解题思路是用并查集。先将题目中的“相似”的定义转换一下,A 和 B 相似的意思是,A 和 B 中只有 2 个字符不相等,其他字符都相等,这样交换一次才能完全相等。有没有可能这两个字符交换了也不相等呢?这种情况不用考虑,因为题目中提到了给的字符串都是 `anagram` 的(`anagram` 的意思是,字符串的任意排列组合)。那么这题就比较简单了,只需要判断每两个字符串是否“相似”,如果相似就 `union()`,最后看并查集中有几个集合即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func numSimilarGroups(A []string) int {
- uf := template.UnionFind{}
- uf.Init(len(A))
- for i := 0; i < len(A); i++ {
- for j := i + 1; j < len(A); j++ {
- if isSimilar(A[i], A[j]) {
- uf.Union(i, j)
- }
- }
- }
- return uf.TotalCount()
-}
-
-func isSimilar(a, b string) bool {
- var n int
- for i := 0; i < len(a); i++ {
- if a[i] != b[i] {
- n++
- if n > 2 {
- return false
- }
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0841.Keys-and-Rooms.md b/website/content/ChapterFour/0841.Keys-and-Rooms.md
deleted file mode 100644
index 69d1da3a2..000000000
--- a/website/content/ChapterFour/0841.Keys-and-Rooms.md
+++ /dev/null
@@ -1,80 +0,0 @@
-# [841. Keys and Rooms](https://leetcode.com/problems/keys-and-rooms/)
-
-
-
-## 题目
-
-There are `N` rooms and you start in room `0`. Each room has a distinct number in `0, 1, 2, ..., N-1`, and each room may have some keys to access the next room.
-
-Formally, each room `i` has a list of keys `rooms[i]`, and each key `rooms[i][j]` is an integer in `[0, 1, ..., N-1]` where `N = rooms.length`. A key `rooms[i][j] = v` opens the room with number `v`.
-
-Initially, all the rooms start locked (except for room `0`).
-
-You can walk back and forth between rooms freely.
-
-Return `true` if and only if you can enter every room.
-
-**Example 1**:
-
-```
-Input: [[1],[2],[3],[]]
-Output: true
-Explanation:
-We start in room 0, and pick up key 1.
-We then go to room 1, and pick up key 2.
-We then go to room 2, and pick up key 3.
-We then go to room 3. Since we were able to go to every room, we return true.
-```
-
-**Example 2**:
-
-```
-Input: [[1,3],[3,0,1],[2],[0]]
-Output: false
-Explanation: We can't enter the room with number 2.
-```
-
-**Note**:
-
-1. `1 <= rooms.length <= 1000`
-2. `0 <= rooms[i].length <= 1000`
-3. The number of keys in all rooms combined is at most `3000`.
-
-
-## 题目大意
-
-有 N 个房间,开始时你位于 0 号房间。每个房间有不同的号码:0,1,2,...,N-1,并且房间里可能有一些钥匙能使你进入下一个房间。
-
-在形式上,对于每个房间 i 都有一个钥匙列表 rooms[i],每个钥匙 rooms[i][j] 由 [0,1,...,N-1] 中的一个整数表示,其中 N = rooms.length。 钥匙 rooms[i][j] = v 可以打开编号为 v 的房间。最初,除 0 号房间外的其余所有房间都被锁住。你可以自由地在房间之间来回走动。如果能进入每个房间返回 true,否则返回 false。
-
-提示:
-
-- 1 <= rooms.length <= 1000
-- 0 <= rooms[i].length <= 1000
-- 所有房间中的钥匙数量总计不超过 3000。
-
-## 解题思路
-
-- 给出一个房间数组,每个房间里面装了一些钥匙。0 号房间默认是可以进入的,房间进入顺序没有要求,问最终能否进入所有房间。
-- 用 DFS 依次深搜所有房间的钥匙,如果都能访问到,最终输出 true。这题算是 DFS 里面的简单题。
-
-## 代码
-
-```go
-func canVisitAllRooms(rooms [][]int) bool {
- visited := make(map[int]bool)
- visited[0] = true
- dfsVisitAllRooms(rooms, visited, 0)
- return len(rooms) == len(visited)
-}
-
-func dfsVisitAllRooms(es [][]int, visited map[int]bool, from int) {
- for _, to := range es[from] {
- if visited[to] {
- continue
- }
- visited[to] = true
- dfsVisitAllRooms(es, visited, to)
- }
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md b/website/content/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md
deleted file mode 100755
index 9bb286ec4..000000000
--- a/website/content/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md
+++ /dev/null
@@ -1,135 +0,0 @@
-# [842. Split Array into Fibonacci Sequence](https://leetcode.com/problems/split-array-into-fibonacci-sequence/)
-
-
-## 题目
-
-Given a string `S` of digits, such as `S = "123456579"`, we can split it into a *Fibonacci-like sequence* `[123, 456, 579].`
-
-Formally, a Fibonacci-like sequence is a list `F` of non-negative integers such that:
-
-- `0 <= F[i] <= 2^31 - 1`, (that is, each integer fits a 32-bit signed integer type);
-- `F.length >= 3`;
-- and `F[i] + F[i+1] = F[i+2]` for all `0 <= i < F.length - 2`.
-
-Also, note that when splitting the string into pieces, each piece must not have extra leading zeroes, except if the piece is the number 0 itself.
-
-Return any Fibonacci-like sequence split from `S`, or return `[]` if it cannot be done.
-
-**Example 1**:
-
- Input: "123456579"
- Output: [123,456,579]
-
-**Example 2**:
-
- Input: "11235813"
- Output: [1,1,2,3,5,8,13]
-
-**Example 3**:
-
- Input: "112358130"
- Output: []
- Explanation: The task is impossible.
-
-**Example 4**:
-
- Input: "0123"
- Output: []
- Explanation: Leading zeroes are not allowed, so "01", "2", "3" is not valid.
-
-**Example 5**:
-
- Input: "1101111"
- Output: [110, 1, 111]
- Explanation: The output [11, 0, 11, 11] would also be accepted.
-
-**Note**:
-
-1. `1 <= S.length <= 200`
-2. `S` contains only digits.
-
-
-## 题目大意
-
-给定一个数字字符串 S,比如 S = "123456579",我们可以将它分成斐波那契式的序列 [123, 456, 579]。斐波那契式序列是一个非负整数列表 F,且满足:
-
-- 0 <= F[i] <= 2^31 - 1,(也就是说,每个整数都符合 32 位有符号整数类型);
-- F.length >= 3;
-- 对于所有的0 <= i < F.length - 2,都有 F[i] + F[i+1] = F[i+2] 成立。
-
-另外,请注意,将字符串拆分成小块时,每个块的数字一定不要以零开头,除非这个块是数字 0 本身。返回从 S 拆分出来的所有斐波那契式的序列块,如果不能拆分则返回 []。
-
-
-
-## 解题思路
-
-
-- 这一题是第 306 题的加强版。第 306 题要求判断字符串是否满足斐波那契数列形式。这一题要求输出按照斐波那契数列形式分割之后的数字数组。
-- 这一题思路和第 306 题基本一致,需要注意的是题目中的一个限制条件,`0 <= F[i] <= 2^31 - 1`,注意这个条件,笔者开始没注意,后面输出解就出现错误了,可以看笔者的测试文件用例的最后两组数据,这两组都是可以分解成斐波那契数列的,但是由于分割以后的数字都大于了 `2^31 - 1`,所以这些解都不能要!
-- 这一题也要特别注意剪枝条件,没有剪枝条件,时间复杂度特别高,加上合理的剪枝条件以后,0ms 通过。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "strconv"
- "strings"
-)
-
-func splitIntoFibonacci(S string) []int {
- if len(S) < 3 {
- return []int{}
- }
- res, isComplete := []int{}, false
- for firstEnd := 0; firstEnd < len(S)/2; firstEnd++ {
- if S[0] == '0' && firstEnd > 0 {
- break
- }
- first, _ := strconv.Atoi(S[:firstEnd+1])
- if first >= 1<<31 { // 题目要求每个数都要小于 2^31 - 1 = 2147483647,此处剪枝很关键!
- break
- }
- for secondEnd := firstEnd + 1; max(firstEnd, secondEnd-firstEnd) <= len(S)-secondEnd; secondEnd++ {
- if S[firstEnd+1] == '0' && secondEnd-firstEnd > 1 {
- break
- }
- second, _ := strconv.Atoi(S[firstEnd+1 : secondEnd+1])
- if second >= 1<<31 { // 题目要求每个数都要小于 2^31 - 1 = 2147483647,此处剪枝很关键!
- break
- }
- findRecursiveCheck(S, first, second, secondEnd+1, &res, &isComplete)
- }
- }
- return res
-}
-
-//Propagate for rest of the string
-func findRecursiveCheck(S string, x1 int, x2 int, left int, res *[]int, isComplete *bool) {
- if x1 >= 1<<31 || x2 >= 1<<31 { // 题目要求每个数都要小于 2^31 - 1 = 2147483647,此处剪枝很关键!
- return
- }
- if left == len(S) {
- if !*isComplete {
- *isComplete = true
- *res = append(*res, x1)
- *res = append(*res, x2)
- }
- return
- }
- if strings.HasPrefix(S[left:], strconv.Itoa(x1+x2)) && !*isComplete {
- *res = append(*res, x1)
- findRecursiveCheck(S, x2, x1+x2, left+len(strconv.Itoa(x1+x2)), res, isComplete)
- return
- }
- if len(*res) > 0 && !*isComplete {
- *res = (*res)[:len(*res)-1]
- }
- return
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0844.Backspace-String-Compare.md b/website/content/ChapterFour/0844.Backspace-String-Compare.md
deleted file mode 100644
index fb758f3b0..000000000
--- a/website/content/ChapterFour/0844.Backspace-String-Compare.md
+++ /dev/null
@@ -1,111 +0,0 @@
-# [844. Backspace String Compare](https://leetcode.com/problems/backspace-string-compare/)
-
-## 题目
-
-Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.
-
-
-**Example 1**:
-
-```
-
-Input: S = "ab#c", T = "ad#c"
-Output: true
-Explanation: Both S and T become "ac".
-
-```
-
-**Example 2**:
-
-```
-
-Input: S = "ab##", T = "c#d#"
-Output: true
-Explanation: Both S and T become "".
-
-```
-
-**Example 3**:
-
-```
-
-Input: S = "a##c", T = "#a#c"
-Output: true
-Explanation: Both S and T become "c".
-
-```
-
-**Example 4**:
-
-```
-
-Input: S = "a#c", T = "b"
-Output: false
-Explanation: S becomes "c" while T becomes "b".
-
-```
-
-
-**Note**:
-
-- 1 <= S.length <= 200
-- 1 <= T.length <= 200
-- S and T only contain lowercase letters and '#' characters.
-
-
-**Follow up**:
-
-- Can you solve it in O(N) time and O(1) space?
-
-## 题目大意
-
-
-给 2 个字符串,如果遇到 # 号字符,就回退一个字符。问最终的 2 个字符串是否完全一致。
-
-## 解题思路
-
-这一题可以用栈的思想来模拟,遇到 # 字符就回退一个字符。不是 # 号就入栈一个字符。比较最终 2 个字符串即可。
-
-
-
-
-
-
-
-
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func backspaceCompare(S string, T string) bool {
- s := make([]rune, 0)
- for _, c := range S {
- if c == '#' {
- if len(s) > 0 {
- s = s[:len(s)-1]
- }
- } else {
- s = append(s, c)
- }
- }
- s2 := make([]rune, 0)
- for _, c := range T {
- if c == '#' {
- if len(s2) > 0 {
- s2 = s2[:len(s2)-1]
- }
- } else {
- s2 = append(s2, c)
- }
- }
- return string(s) == string(s2)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0845.Longest-Mountain-in-Array.md b/website/content/ChapterFour/0845.Longest-Mountain-in-Array.md
deleted file mode 100644
index 0f44f6739..000000000
--- a/website/content/ChapterFour/0845.Longest-Mountain-in-Array.md
+++ /dev/null
@@ -1,91 +0,0 @@
-# [845. Longest Mountain in Array](https://leetcode.com/problems/longest-mountain-in-array/)
-
-## 题目
-
-Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold:
-
-- B.length >= 3
-- There exists some 0 < i < B.length - 1 such that B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1]
-(Note that B could be any subarray of A, including the entire array A.)
-
-Given an array A of integers, return the length of the longest mountain.
-
-Return 0 if there is no mountain.
-
-
-
-
-**Example 1**:
-
-```
-
-Input: [2,1,4,7,3,2,5]
-Output: 5
-Explanation: The largest mountain is [1,4,7,3,2] which has length 5.
-
-```
-
-**Example 2**:
-
-```
-
-Input: [2,2,2]
-Output: 0
-Explanation: There is no mountain.
-
-```
-
-**Note**:
-
-- 0 <= A.length <= 10000
-- 0 <= A[i] <= 10000
-
-
-**Follow up**:
-
-- Can you solve it using only one pass?
-- Can you solve it in O(1) space?
-
-## 题目大意
-
-这道题考察的是滑动窗口的问题。
-
-给出一个数组,要求求出这个数组里面“山”最长的长度。“山”的意思是,从一个数开始逐渐上升,到顶以后,逐渐下降。
-
-## 解题思路
-
-这道题解题思路也是滑动窗口,只不过在滑动的过程中多判断一个上升和下降的状态即可。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func longestMountain(A []int) int {
- left, right, res, isAscending := 0, 0, 0, true
- for left < len(A) {
- if right+1 < len(A) && ((isAscending == true && A[right+1] > A[left] && A[right+1] > A[right]) || (right != left && A[right+1] < A[right])) {
- if A[right+1] < A[right] {
- isAscending = false
- }
- right++
- } else {
- if right != left && isAscending == false {
- res = max(res, right-left+1)
- }
- left++
- if right < left {
- right = left
- }
- if right == left {
- isAscending = true
- }
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0850.Rectangle-Area-II.md b/website/content/ChapterFour/0850.Rectangle-Area-II.md
deleted file mode 100755
index 29dbe94e4..000000000
--- a/website/content/ChapterFour/0850.Rectangle-Area-II.md
+++ /dev/null
@@ -1,293 +0,0 @@
-# [850. Rectangle Area II](https://leetcode.com/problems/rectangle-area-ii/)
-
-
-## 题目
-
-We are given a list of (axis-aligned) `rectangles`. Each `rectangle[i] = [x1, y1, x2, y2]` , where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the `i`th rectangle.
-
-Find the total area covered by all `rectangles` in the plane. Since the answer may be too large, **return it modulo 10^9 + 7**.
-
-
-
-**Example 1**:
-
- Input: [[0,0,2,2],[1,0,2,3],[1,0,3,1]]
- Output: 6
- Explanation: As illustrated in the picture.
-
-**Example 2**:
-
- Input: [[0,0,1000000000,1000000000]]
- Output: 49
- Explanation: The answer is 10^18 modulo (10^9 + 7), which is (10^9)^2 = (-7)^2 = 49.
-
-**Note**:
-
-- `1 <= rectangles.length <= 200`
-- `rectanges[i].length = 4`
-- `0 <= rectangles[i][j] <= 10^9`
-- The total area covered by all rectangles will never exceed `2^63 - 1` and thus will fit in a 64-bit signed integer.
-
-
-## 题目大意
-
-我们给出了一个(轴对齐的)矩形列表 rectangles。 对于 rectangle[i] = [x1, y1, x2, y2],其中(x1,y1)是矩形 i 左下角的坐标,(x2,y2)是该矩形右上角的坐标。找出平面中所有矩形叠加覆盖后的总面积。由于答案可能太大,请返回它对 10 ^ 9 + 7 取模的结果。
-
-提示:
-
-- 1 <= rectangles.length <= 200
-- rectanges[i].length = 4
-- 0 <= rectangles[i][j] <= 10^9
-- 矩形叠加覆盖后的总面积不会超越 2^63 - 1 ,这意味着可以用一个 64 位有符号整数来保存面积结果。
-
-
-## 解题思路
-
-
-- 在二维坐标系中给出一些矩形,要求这些矩形合并之后的面积。由于矩形有重叠,所以需要考虑合并以后的面积。矩形的坐标值也会很大。
-- 这一题给人的感觉很像第 218 题,求天际线的过程也是有楼挡楼,重叠的情况。不过那一题只用求天际线的拐点,所以我们可以对区间做“右边界减一”的处理,防止两个相邻区间因为共点,而导致结果错误。但是这一题如果还是用相同的做法,就会出错,因为“右边界减一”以后,面积会少一部分,最终得到的结果也是偏小的。所以这一题要将线段树改造一下。
-- 思路是先讲 Y 轴上的坐标离线化,转换成线段树。将矩形的 2 条边变成扫描线,左边是入边,右边是出边。
-
- 
-
-- 再从左往右遍历每条扫描线,并对 Y 轴上的线段树进行 update。X 轴上的每个坐标区间 * query 线段树总高度的结果 = 区间面积。最后将 X 轴对应的每个区间面积加起来,就是最终矩形合并以后的面积。如下图中间的图。
-
- 
-
- 需要注意的一点是,**每次 query 的结果并不一定是连续线段**。如上图最右边的图,中间有一段是可能出现镂空的。这种情况看似复杂,其实很简单,因为每段线段树的线段代表的权值高度是不同的,每次 query 最大高度得到的结果已经考虑了中间可能有镂空的情况了。
-
-- 具体做法,先把各个矩形在 Y 轴方向上离散化,这里的**线段树叶子节点不再是一个点了,而是一个区间长度为 1 的区间段**。
-
- 
-
- 每个叶子节点也不再是存储一个 int 值,而是存 2 个值,一个是 count 值,用来记录这条区间被覆盖的次数,另一个值是 val 值,用来反映射该线段长度是多少,因为 Y 轴被离散化了,区间坐标间隔都是 1,但是实际 Y 轴的高度并不是 1 ,所以用 val 来反映射原来的高度。
-
-- 初始化线段树,叶子节点的 count = 0,val 根据题目给的 Y 坐标进行计算。
-
- 
-
-- 从左往右遍历每个扫描线。每条扫面线都把对应 update 更新到叶子节点。pushUp 的时候需要合并每个区间段的高度 val 值。如果有区间没有被覆盖,那么这个区间高度 val 为 0,这也就处理了可能“中间镂空”的情况。
-
- 
-
- func (sat *SegmentAreaTree) pushUp(treeIndex, leftTreeIndex, rightTreeIndex int) {
- newCount, newValue := sat.merge(sat.tree[leftTreeIndex].count, sat.tree[rightTreeIndex].count), 0
- if sat.tree[leftTreeIndex].count > 0 && sat.tree[rightTreeIndex].count > 0 {
- newValue = sat.merge(sat.tree[leftTreeIndex].val, sat.tree[rightTreeIndex].val)
- } else if sat.tree[leftTreeIndex].count > 0 && sat.tree[rightTreeIndex].count == 0 {
- newValue = sat.tree[leftTreeIndex].val
- } else if sat.tree[leftTreeIndex].count == 0 && sat.tree[rightTreeIndex].count > 0 {
- newValue = sat.tree[rightTreeIndex].val
- }
- sat.tree[treeIndex] = SegmentItem{count: newCount, val: newValue}
- }
-
-- 扫描每一个扫描线,先 pushDown 到叶子节点,再 pushUp 到根节点。
-
- 
-
- 
-
- 
-
- 
-
-- 遍历到倒数第 2 根扫描线的时候就能得到结果了。因为最后一根扫描线 update 以后,整个线段树全部都归为初始化状态了。
-
- 
-
-- 这一题是线段树扫面线解法的经典题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-func rectangleArea(rectangles [][]int) int {
- sat, res := SegmentAreaTree{}, 0
- posXMap, posX, posYMap, posY, lines := discretization850(rectangles)
- tmp := make([]int, len(posYMap))
- for i := 0; i < len(tmp)-1; i++ {
- tmp[i] = posY[i+1] - posY[i]
- }
- sat.Init(tmp, func(i, j int) int {
- return i + j
- })
- for i := 0; i < len(posY)-1; i++ {
- tmp[i] = posY[i+1] - posY[i]
- }
- for i := 0; i < len(posX)-1; i++ {
- for _, v := range lines[posXMap[posX[i]]] {
- sat.Update(posYMap[v.start], posYMap[v.end], v.state)
- }
- res += ((posX[i+1] - posX[i]) * sat.Query(0, len(posY)-1)) % 1000000007
- }
- return res % 1000000007
-}
-
-func discretization850(positions [][]int) (map[int]int, []int, map[int]int, []int, map[int][]LineItem) {
- tmpXMap, tmpYMap, posXArray, posXMap, posYArray, posYMap, lines := map[int]int{}, map[int]int{}, []int{}, map[int]int{}, []int{}, map[int]int{}, map[int][]LineItem{}
- for _, pos := range positions {
- tmpXMap[pos[0]]++
- tmpXMap[pos[2]]++
- }
- for k := range tmpXMap {
- posXArray = append(posXArray, k)
- }
- sort.Ints(posXArray)
- for i, pos := range posXArray {
- posXMap[pos] = i
- }
-
- for _, pos := range positions {
- tmpYMap[pos[1]]++
- tmpYMap[pos[3]]++
- tmp1 := lines[posXMap[pos[0]]]
- tmp1 = append(tmp1, LineItem{start: pos[1], end: pos[3], state: 1})
- lines[posXMap[pos[0]]] = tmp1
- tmp2 := lines[posXMap[pos[2]]]
- tmp2 = append(tmp2, LineItem{start: pos[1], end: pos[3], state: -1})
- lines[posXMap[pos[2]]] = tmp2
- }
- for k := range tmpYMap {
- posYArray = append(posYArray, k)
- }
- sort.Ints(posYArray)
- for i, pos := range posYArray {
- posYMap[pos] = i
- }
- return posXMap, posXArray, posYMap, posYArray, lines
-}
-
-// LineItem define
-type LineItem struct { // 垂直于 x 轴的线段
- start, end, state int // state = 1 代表进入,-1 代表离开
-}
-
-// SegmentItem define
-type SegmentItem struct {
- count int
- val int
-}
-
-// SegmentAreaTree define
-type SegmentAreaTree struct {
- data []int
- tree []SegmentItem
- left, right int
- merge func(i, j int) int
-}
-
-// Init define
-func (sat *SegmentAreaTree) Init(nums []int, oper func(i, j int) int) {
- sat.merge = oper
- data, tree := make([]int, len(nums)), make([]SegmentItem, 4*len(nums))
- for i := 0; i < len(nums); i++ {
- data[i] = nums[i]
- }
- sat.data, sat.tree = data, tree
- if len(nums) > 0 {
- sat.buildSegmentTree(0, 0, len(nums)-1)
- }
-}
-
-// 在 treeIndex 的位置创建 [left....right] 区间的线段树
-func (sat *SegmentAreaTree) buildSegmentTree(treeIndex, left, right int) {
- if left == right-1 {
- sat.tree[treeIndex] = SegmentItem{count: 0, val: sat.data[left]}
- return
- }
- midTreeIndex, leftTreeIndex, rightTreeIndex := left+(right-left)>>1, sat.leftChild(treeIndex), sat.rightChild(treeIndex)
- sat.buildSegmentTree(leftTreeIndex, left, midTreeIndex)
- sat.buildSegmentTree(rightTreeIndex, midTreeIndex, right)
- sat.pushUp(treeIndex, leftTreeIndex, rightTreeIndex)
-}
-
-func (sat *SegmentAreaTree) pushUp(treeIndex, leftTreeIndex, rightTreeIndex int) {
- newCount, newValue := sat.merge(sat.tree[leftTreeIndex].count, sat.tree[rightTreeIndex].count), 0
- if sat.tree[leftTreeIndex].count > 0 && sat.tree[rightTreeIndex].count > 0 {
- newValue = sat.merge(sat.tree[leftTreeIndex].val, sat.tree[rightTreeIndex].val)
- } else if sat.tree[leftTreeIndex].count > 0 && sat.tree[rightTreeIndex].count == 0 {
- newValue = sat.tree[leftTreeIndex].val
- } else if sat.tree[leftTreeIndex].count == 0 && sat.tree[rightTreeIndex].count > 0 {
- newValue = sat.tree[rightTreeIndex].val
- }
- sat.tree[treeIndex] = SegmentItem{count: newCount, val: newValue}
-}
-
-func (sat *SegmentAreaTree) leftChild(index int) int {
- return 2*index + 1
-}
-
-func (sat *SegmentAreaTree) rightChild(index int) int {
- return 2*index + 2
-}
-
-// 查询 [left....right] 区间内的值
-
-// Query define
-func (sat *SegmentAreaTree) Query(left, right int) int {
- if len(sat.data) > 0 {
- return sat.queryInTree(0, 0, len(sat.data)-1, left, right)
- }
- return 0
-}
-
-func (sat *SegmentAreaTree) queryInTree(treeIndex, left, right, queryLeft, queryRight int) int {
- midTreeIndex, leftTreeIndex, rightTreeIndex := left+(right-left)>>1, sat.leftChild(treeIndex), sat.rightChild(treeIndex)
- if left > queryRight || right < queryLeft { // segment completely outside range
- return 0 // represents a null node
- }
- if queryLeft <= left && queryRight >= right { // segment completely inside range
- if sat.tree[treeIndex].count > 0 {
- return sat.tree[treeIndex].val
- }
- return 0
- }
- if queryLeft > midTreeIndex {
- return sat.queryInTree(rightTreeIndex, midTreeIndex, right, queryLeft, queryRight)
- } else if queryRight <= midTreeIndex {
- return sat.queryInTree(leftTreeIndex, left, midTreeIndex, queryLeft, queryRight)
- }
- // merge query results
- return sat.merge(sat.queryInTree(leftTreeIndex, left, midTreeIndex, queryLeft, midTreeIndex),
- sat.queryInTree(rightTreeIndex, midTreeIndex, right, midTreeIndex, queryRight))
-}
-
-// Update define
-func (sat *SegmentAreaTree) Update(updateLeft, updateRight, val int) {
- if len(sat.data) > 0 {
- sat.updateInTree(0, 0, len(sat.data)-1, updateLeft, updateRight, val)
- }
-}
-
-func (sat *SegmentAreaTree) updateInTree(treeIndex, left, right, updateLeft, updateRight, val int) {
- midTreeIndex, leftTreeIndex, rightTreeIndex := left+(right-left)>>1, sat.leftChild(treeIndex), sat.rightChild(treeIndex)
- if left > right || left >= updateRight || right <= updateLeft { // 由于叶子节点的区间不在是 left == right 所以这里判断需要增加等号的判断
- return // out of range. escape.
- }
-
- if updateLeft <= left && right <= updateRight { // segment is fully within update range
- if left == right-1 {
- sat.tree[treeIndex].count = sat.merge(sat.tree[treeIndex].count, val)
- }
- if left != right-1 { // update lazy[] for children
- sat.updateInTree(leftTreeIndex, left, midTreeIndex, updateLeft, updateRight, val)
- sat.updateInTree(rightTreeIndex, midTreeIndex, right, updateLeft, updateRight, val)
- sat.pushUp(treeIndex, leftTreeIndex, rightTreeIndex)
- }
- return
- }
- sat.updateInTree(leftTreeIndex, left, midTreeIndex, updateLeft, updateRight, val)
- sat.updateInTree(rightTreeIndex, midTreeIndex, right, updateLeft, updateRight, val)
- // merge updates
- sat.pushUp(treeIndex, leftTreeIndex, rightTreeIndex)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0851.Loud-and-Rich.md b/website/content/ChapterFour/0851.Loud-and-Rich.md
deleted file mode 100644
index 26351328b..000000000
--- a/website/content/ChapterFour/0851.Loud-and-Rich.md
+++ /dev/null
@@ -1,108 +0,0 @@
-# [851. Loud and Rich](https://leetcode.com/problems/loud-and-rich/)
-
-
-
-## 题目
-
-In a group of N people (labelled `0, 1, 2, ..., N-1`), each person has different amounts of money, and different levels of quietness.
-
-For convenience, we'll call the person with label `x`, simply "person `x`".
-
-We'll say that `richer[i] = [x, y]` if person `x` definitely has more money than person `y`. Note that `richer` may only be a subset of valid observations.
-
-Also, we'll say `quiet = q` if person x has quietness `q`.
-
-Now, return `answer`, where `answer = y` if `y` is the least quiet person (that is, the person `y` with the smallest value of `quiet[y]`), among all people who definitely have equal to or more money than person `x`.
-
-**Example 1**:
-
-```
-Input: richer = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0]
-Output: [5,5,2,5,4,5,6,7]
-Explanation:
-answer[0] = 5.
-Person 5 has more money than 3, which has more money than 1, which has more money than 0.
-The only person who is quieter (has lower quiet[x]) is person 7, but
-it isn't clear if they have more money than person 0.
-
-answer[7] = 7.
-Among all people that definitely have equal to or more money than person 7
-(which could be persons 3, 4, 5, 6, or 7), the person who is the quietest (has lower quiet[x])
-is person 7.
-
-The other answers can be filled out with similar reasoning.
-```
-
-**Note**:
-
-1. `1 <= quiet.length = N <= 500`
-2. `0 <= quiet[i] < N`, all `quiet[i]` are different.
-3. `0 <= richer.length <= N * (N-1) / 2`
-4. `0 <= richer[i][j] < N`
-5. `richer[i][0] != richer[i][1]`
-6. `richer[i]`'s are all different.
-7. The observations in `richer` are all logically consistent.
-
-## 题目大意
-
-在一组 N 个人(编号为 0, 1, 2, ..., N-1)中,每个人都有不同数目的钱,以及不同程度的安静(quietness)。为了方便起见,我们将编号为 x 的人简称为 "person x "。如果能够肯定 person x 比 person y 更有钱的话,我们会说 richer[i] = [x, y] 。注意 richer 可能只是有效观察的一个子集。另外,如果 person x 的安静程度为 q ,我们会说 quiet[x] = q 。现在,返回答案 answer ,其中 answer[x] = y 的前提是,在所有拥有的钱不少于 person x 的人中,person y 是最安静的人(也就是安静值 quiet[y] 最小的人)。
-
-提示:
-
-- 1 <= quiet.length = N <= 500
-- 0 <= quiet[i] < N,所有 quiet[i] 都不相同。
-- 0 <= richer.length <= N * (N-1) / 2
-- 0 <= richer[i][j] < N
-- richer[i][0] != richer[i][1]
-- richer[i] 都是不同的。
-- 对 richer 的观察在逻辑上是一致的。
-
-
-## 解题思路
-
-- 给出 2 个数组,richer 和 quiet,要求输出 answer,其中 answer = y 的前提是,在所有拥有的钱不少于 x 的人中,y 是最安静的人(也就是安静值 quiet[y] 最小的人)
-- 由题意可知,`richer` 构成了一个有向无环图,首先使用字典建立图的关系,找到比当前下标编号富有的所有的人。然后使用广度优先层次遍历,不断的使用富有的人,但是安静值更小的人更新子节点即可。
-- 这一题还可以用拓扑排序来解答。将 `richer` 中描述的关系看做边,如果 `x > y`,则 `x` 指向 `y`。将 `quiet` 看成权值。用一个数组记录答案,初始时 `ans[i] = i`。然后对原图做拓扑排序,对于每一条边,如果发现 `quiet[ans[v]] > quiet[ans[u]]`,则 `ans[v]` 的答案为 `ans[u]`。时间复杂度即为拓扑排序的时间复杂度为 `O(m+n)`。空间复杂度需要 `O(m)` 的数组建图,需要 `O(n)` 的数组记录入度以及存储队列,所以空间复杂度为 `O(m+n)`。
-
-## 代码
-
-```go
-func loudAndRich(richer [][]int, quiet []int) []int {
- edges := make([][]int, len(quiet))
- for i := range edges {
- edges[i] = []int{}
- }
- indegrees := make([]int, len(quiet))
- for _, edge := range richer {
- n1, n2 := edge[0], edge[1]
- edges[n1] = append(edges[n1], n2)
- indegrees[n2]++
- }
- res := make([]int, len(quiet))
- for i := range res {
- res[i] = i
- }
- queue := []int{}
- for i, v := range indegrees {
- if v == 0 {
- queue = append(queue, i)
- }
- }
- for len(queue) > 0 {
- nexts := []int{}
- for _, n1 := range queue {
- for _, n2 := range edges[n1] {
- indegrees[n2]--
- if quiet[res[n2]] > quiet[res[n1]] {
- res[n2] = res[n1]
- }
- if indegrees[n2] == 0 {
- nexts = append(nexts, n2)
- }
- }
- }
- queue = nexts
- }
- return res
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0852.Peak-Index-in-a-Mountain-Array.md b/website/content/ChapterFour/0852.Peak-Index-in-a-Mountain-Array.md
deleted file mode 100755
index ea6ae9421..000000000
--- a/website/content/ChapterFour/0852.Peak-Index-in-a-Mountain-Array.md
+++ /dev/null
@@ -1,91 +0,0 @@
-# [852. Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array/)
-
-
-## 题目
-
-Let's call an array `A` a *mountain* if the following properties hold:
-
-- `A.length >= 3`
-- There exists some `0 < i < A.length - 1` such that `A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]`
-
-Given an array that is definitely a mountain, return any `i` such that `A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]`.
-
-**Example 1**:
-
- Input: [0,1,0]
- Output: 1
-
-**Example 2**:
-
- Input: [0,2,1,0]
- Output: 1
-
-**Note**:
-
-1. `3 <= A.length <= 10000`
-2. `0 <= A[i] <= 10^6`
-3. A is a mountain, as defined above.
-
-
-## 题目大意
-
-我们把符合下列属性的数组 A 称作山脉:
-
-- A.length >= 3
-- 存在 0 < i < A.length - 1 使得A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]
-给定一个确定为山脉的数组,返回任何满足 A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] 的 i 的值。
-
-提示:
-
-- 3 <= A.length <= 10000
-- 0 <= A[i] <= 10^6
-- A 是如上定义的山脉
-
-
-
-## 解题思路
-
-- 给出一个数组,数组里面存在有且仅有一个“山峰”,(山峰的定义是,下标 `i` 比 `i-1`、`i+1` 位置上的元素都要大),找到这个“山峰”,并输出其中一个山峰的下标。
-- 这一题直接用二分搜索即可,数组中的元素算基本有序。判断是否为山峰的条件为比较左右两个数,如果当前的数比左右两个数都大,即找到了山峰。其他的情况都在山坡上。这一题有两种写法,第一种写法是标准的二分写法,第二种写法是变形的二分写法。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 二分
-func peakIndexInMountainArray(A []int) int {
- low, high := 0, len(A)-1
- for low <= high {
- mid := low + (high-low)>>1
- if A[mid] > A[mid+1] && A[mid] > A[mid-1] {
- return mid
- }
- if A[mid] > A[mid+1] && A[mid] < A[mid-1] {
- high = mid - 1
- }
- if A[mid] < A[mid+1] && A[mid] > A[mid-1] {
- low = mid + 1
- }
- }
- return 0
-}
-
-// 解法二 二分
-func peakIndexInMountainArray1(A []int) int {
- low, high := 0, len(A)-1
- for low < high {
- mid := low + (high-low)>>1
- // 如果 mid 较大,则左侧存在峰值,high = m,如果 mid + 1 较大,则右侧存在峰值,low = mid + 1
- if A[mid] > A[mid+1] {
- high = mid
- } else {
- low = mid + 1
- }
- }
- return low
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0853.Car-Fleet.md b/website/content/ChapterFour/0853.Car-Fleet.md
deleted file mode 100755
index b28efdbd7..000000000
--- a/website/content/ChapterFour/0853.Car-Fleet.md
+++ /dev/null
@@ -1,98 +0,0 @@
-# [853. Car Fleet](https://leetcode.com/problems/car-fleet/)
-
-
-## 题目
-
-`N` cars are going to the same destination along a one lane road. The destination is `target` miles away.
-
-Each car `i` has a constant speed `speed[i]` (in miles per hour), and initial position `position[i]` miles towards the target along the road.
-
-A car can never pass another car ahead of it, but it can catch up to it, and drive bumper to bumper at the same speed.
-
-The distance between these two cars is ignored - they are assumed to have the same position.
-
-A *car fleet* is some non-empty set of cars driving at the same position and same speed. Note that a single car is also a car fleet.
-
-If a car catches up to a car fleet right at the destination point, it will still be considered as one car fleet.
-
-How many car fleets will arrive at the destination?
-
-**Example 1**:
-
- Input: target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]
- Output: 3
- Explanation:
- The cars starting at 10 and 8 become a fleet, meeting each other at 12.
- The car starting at 0 doesn't catch up to any other car, so it is a fleet by itself.
- The cars starting at 5 and 3 become a fleet, meeting each other at 6.
- Note that no other cars meet these fleets before the destination, so the answer is 3.
-
-**Note**:
-
-1. `0 <= N <= 10 ^ 4`
-2. `0 < target <= 10 ^ 6`
-3. `0 < speed[i] <= 10 ^ 6`
-4. `0 <= position[i] < target`
-5. All initial positions are different.
-
-
-## 题目大意
-
-N 辆车沿着一条车道驶向位于 target 英里之外的共同目的地。每辆车 i 以恒定的速度 speed[i] (英里/小时),从初始位置 position[i] (英里) 沿车道驶向目的地。
-
-一辆车永远不会超过前面的另一辆车,但它可以追上去,并与前车以相同的速度紧接着行驶。此时,我们会忽略这两辆车之间的距离,也就是说,它们被假定处于相同的位置。车队 是一些由行驶在相同位置、具有相同速度的车组成的非空集合。注意,一辆车也可以是一个车队。即便一辆车在目的地才赶上了一个车队,它们仍然会被视作是同一个车队。
-
- 问最后会有多少车队到达目的地?
-
-
-
-## 解题思路
-
-
-- 根据每辆车距离终点和速度,计算每辆车到达终点的时间,并按照距离从大到小排序(position 越大代表距离终点越近)
-- 从头往后扫描排序以后的数组,时间一旦大于前一个 car 的时间,就会生成一个新的 car fleet,最终计数加一即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-type car struct {
- time float64
- position int
-}
-
-// ByPosition define
-type ByPosition []car
-
-func (a ByPosition) Len() int { return len(a) }
-func (a ByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-func (a ByPosition) Less(i, j int) bool { return a[i].position > a[j].position }
-
-func carFleet(target int, position []int, speed []int) int {
- n := len(position)
- if n <= 1 {
- return n
- }
- cars := make([]car, n)
- for i := 0; i < n; i++ {
- cars[i] = car{float64(target-position[i]) / float64(speed[i]), position[i]}
- }
- sort.Sort(ByPosition(cars))
- fleet, lastTime := 0, 0.0
- for i := 0; i < len(cars); i++ {
- if cars[i].time > lastTime {
- lastTime = cars[i].time
- fleet++
- }
- }
- return fleet
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0856.Score-of-Parentheses.md b/website/content/ChapterFour/0856.Score-of-Parentheses.md
deleted file mode 100644
index 9d5c8758e..000000000
--- a/website/content/ChapterFour/0856.Score-of-Parentheses.md
+++ /dev/null
@@ -1,102 +0,0 @@
-# [856. Score of Parentheses](https://leetcode.com/problems/score-of-parentheses/)
-
-## 题目
-
-Given a balanced parentheses string S, compute the score of the string based on the following rule:
-
-() has score 1
-AB has score A + B, where A and B are balanced parentheses strings.
-(A) has score 2 * A, where A is a balanced parentheses string.
-
-
-**Example 1**:
-
-```
-
-Input: "()"
-Output: 1
-
-```
-
-**Example 2**:
-
-```
-
-Input: "(())"
-Output: 2
-
-```
-
-**Example 3**:
-
-```
-
-Input: "()()"
-Output: 2
-
-```
-
-**Example 4**:
-
-```
-
-Input: "(()(()))"
-Output: 6
-
-```
-
-
-**Note**:
-
-1. S is a balanced parentheses string, containing only ( and ).
-2. 2 <= S.length <= 50
-
-## 题目大意
-
-按照以下规则计算括号的分数:() 代表 1 分。AB 代表 A + B,A 和 B 分别是已经满足匹配规则的括号组。(A) 代表 2 * A,其中 A 也是已经满足匹配规则的括号组。给出一个括号字符串,要求按照这些规则计算出括号的分数值。
-
-
-## 解题思路
-
-按照括号匹配的原则,一步步的计算每个组合的分数入栈。遇到题目中的 3 种情况,取出栈顶元素算分数。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func scoreOfParentheses(S string) int {
- res, stack, top, temp := 0, []int{}, -1, 0
- for _, s := range S {
- if s == '(' {
- stack = append(stack, -1)
- top++
- } else {
- temp = 0
- for stack[top] != -1 {
- temp += stack[top]
- stack = stack[:len(stack)-1]
- top--
- }
- stack = stack[:len(stack)-1]
- top--
- if temp == 0 {
- stack = append(stack, 1)
- top++
- } else {
- stack = append(stack, temp*2)
- top++
- }
- }
- }
- for len(stack) != 0 {
- res += stack[top]
- stack = stack[:len(stack)-1]
- top--
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0862.Shortest-Subarray-with-Sum-at-Least-K.md b/website/content/ChapterFour/0862.Shortest-Subarray-with-Sum-at-Least-K.md
deleted file mode 100644
index 469ca3bd7..000000000
--- a/website/content/ChapterFour/0862.Shortest-Subarray-with-Sum-at-Least-K.md
+++ /dev/null
@@ -1,90 +0,0 @@
-# [862. Shortest Subarray with Sum at Least K](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/)
-
-
-
-## 题目
-
-Return the **length** of the shortest, non-empty, contiguous subarray of `A` with sum at least `K`.
-
-If there is no non-empty subarray with sum at least `K`, return `-1`.
-
-**Example 1**:
-
-```
-Input: A = [1], K = 1
-Output: 1
-```
-
-**Example 2**:
-
-```
-Input: A = [1,2], K = 4
-Output: -1
-```
-
-**Example 3**:
-
-```
-Input: A = [2,-1,2], K = 3
-Output: 3
-```
-
-**Note**:
-
-1. `1 <= A.length <= 50000`
-2. `-10 ^ 5 <= A[i] <= 10 ^ 5`
-3. `1 <= K <= 10 ^ 9`
-
-## 题目大意
-
-返回 A 的最短的非空连续子数组的长度,该子数组的和至少为 K 。如果没有和至少为 K 的非空子数组,返回 -1 。
-
-提示:
-
-- 1 <= A.length <= 50000
-- -10 ^ 5 <= A[i] <= 10 ^ 5
-- 1 <= K <= 10 ^ 9
-
-
-## 解题思路
-
-- 给出一个数组,要求找出一个最短的,非空的,连续的子序列且累加和至少为 k 。
-- 由于给的数组里面可能存在负数,所以子数组的累加和不会随着数组的长度增加而增加。题目中要求区间和,理所应当需要利用 `prefixSum` 前缀和,先计算出 `prefixSum` 前缀和。
-- 简化一下题目的要求,即能否找到 `prefixSum[y] - prefixSum[x] ≥ K` ,且 `y - x` 的差值最小。如果固定的 `y`,那么对于 `x`,`x` 越大,`y - x` 的差值就越小(因为 `x` 越逼近 `y`)。所以想求区间 `[x, y]` 的最短距离,需要保证 `y` 尽量小,`x` 尽量大,这样 `[x, y]` 区间距离最小。那么有以下 2 点“常识”一定成立:
- 1. 如果 `x1 < x2` ,并且 `prefixSum[x2] ≤ prefixSum[x1]`,说明结果一定不会取 `x1`。因为如果 `prefixSum[x1] ≤ prefixSum[y] - k`,那么 `prefixSum[x2] ≤ prefixSum[x1] ≤ prefixSum[y] - k`,`x2` 也能满足题意,并且 `x2` 比 `x1` 更加接近 `y`,最优解一定优先考虑 `x2`。
- 2. 在确定了 `x` 以后,以后就不用再考虑 `x` 了,因为如果 `y2 > y1`,且 `y2` 的时候取 `x` 还是一样的,那么算距离的话,`y2 - x` 显然大于 `y1 - x`,这样的话肯定不会是最短的距离。
-- 从上面这两个常识来看,可以用双端队列 `deque` 来处理 `prefixSum`。`deque` 中存储的是递增的 `x` 下标,为了满足常识一。从双端队列的开头开始遍历,假如区间和之差大于等于 `K`,就移除队首元素并更新结果 `res`。队首移除元素,直到不满足 `prefixSum[i]-prefixSum[deque[0]] >= K` 这一不等式,是为了满足常识二。之后的循环是此题的精髓,从双端队列的末尾开始往前遍历,假如当前区间和 `prefixSum[i]` 小于等于队列末尾的区间和,则移除队列末尾元素。为什么这样处理呢?因为若数组都是正数,那么长度越长,区间和一定越大,则 `prefixSum[i]` 一定大于所有双端队列中的区间和,但由于可能存在负数,从而使得长度变长,区间总和反而减少了,之前的区间和之差值都没有大于等于 `K`(< K),现在的更不可能大于等于 `K`,这个结束位置可以直接淘汰,不用进行计算。循环结束后将当前位置加入双端队列即可。遇到新下标在队尾移除若干元素,这一行为,也是为了满足常识一。
-- 由于所有下标都只进队列一次,也最多 pop 出去一次,所以时间复杂度 O(n),空间复杂度 O(n)。
-
-## 代码
-
-```go
-func shortestSubarray(A []int, K int) int {
- res, prefixSum := len(A)+1, make([]int, len(A)+1)
- for i := 0; i < len(A); i++ {
- prefixSum[i+1] = prefixSum[i] + A[i]
- }
- // deque 中保存递增的 prefixSum 下标
- deque := []int{}
- for i := range prefixSum {
- // 下面这个循环希望能找到 [deque[0], i] 区间内累加和 >= K,如果找到了就更新答案
- for len(deque) > 0 && prefixSum[i]-prefixSum[deque[0]] >= K {
- length := i - deque[0]
- if res > length {
- res = length
- }
- // 找到第一个 deque[0] 能满足条件以后,就移除它,因为它是最短长度的子序列了
- deque = deque[1:]
- }
- // 下面这个循环希望能保证 prefixSum[deque[i]] 递增
- for len(deque) > 0 && prefixSum[i] <= prefixSum[deque[len(deque)-1]] {
- deque = deque[:len(deque)-1]
- }
- deque = append(deque, i)
- }
- if res <= len(A) {
- return res
- }
- return -1
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md b/website/content/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md
deleted file mode 100644
index 4ea32b206..000000000
--- a/website/content/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md
+++ /dev/null
@@ -1,96 +0,0 @@
-# [863. All Nodes Distance K in Binary Tree](https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/)
-
-
-
-## 题目
-
-We are given a binary tree (with root node `root`), a `target` node, and an integer value `K`.
-
-Return a list of the values of all nodes that have a distance `K` from the `target` node. The answer can be returned in any order.
-
-**Example 1**:
-
-```
-Input: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, K = 2
-
-Output: [7,4,1]
-
-Explanation:
-The nodes that are a distance 2 from the target node (with value 5)
-have values 7, 4, and 1.
-```
-
-
-
-**Note**:
-
-1. The given tree is non-empty.
-2. Each node in the tree has unique values `0 <= node.val <= 500`.
-3. The `target` node is a node in the tree.
-4. `0 <= K <= 1000`.
-
-## 题目大意
-
-给定一个二叉树(具有根结点 root), 一个目标结点 target ,和一个整数值 K 。返回到目标结点 target 距离为 K 的所有结点的值的列表。 答案可以以任何顺序返回。
-
-提示:
-
-- 给定的树是非空的。
-- 树上的每个结点都具有唯一的值 0 <= node.val <= 500 。
-- 目标结点 target 是树上的结点。
-- 0 <= K <= 1000.
-
-
-## 解题思路
-
-- 给出一颗树和一个目标节点 target,一个距离 K,要求找到所有距离目标节点 target 的距离是 K 的点。
-- 这一题用 DFS 的方法解题。先找到当前节点距离目标节点的距离,如果在左子树中找到了 target,距离当前节点的距离 > 0,则还需要在它的右子树中查找剩下的距离。如果是在右子树中找到了 target,反之同理。如果当前节点就是目标节点,那么就可以直接记录这个点。否则每次遍历一个点,距离都减一。
-
-## 代码
-
-```go
-func distanceK(root *TreeNode, target *TreeNode, K int) []int {
- visit := []int{}
- findDistanceK(root, target, K, &visit)
- return visit
-}
-
-func findDistanceK(root, target *TreeNode, K int, visit *[]int) int {
- if root == nil {
- return -1
- }
- if root == target {
- findChild(root, K, visit)
- return K - 1
- }
- leftDistance := findDistanceK(root.Left, target, K, visit)
- if leftDistance == 0 {
- findChild(root, leftDistance, visit)
- }
- if leftDistance > 0 {
- findChild(root.Right, leftDistance-1, visit)
- return leftDistance - 1
- }
- rightDistance := findDistanceK(root.Right, target, K, visit)
- if rightDistance == 0 {
- findChild(root, rightDistance, visit)
- }
- if rightDistance > 0 {
- findChild(root.Left, rightDistance-1, visit)
- return rightDistance - 1
- }
- return -1
-}
-
-func findChild(root *TreeNode, K int, visit *[]int) {
- if root == nil {
- return
- }
- if K == 0 {
- *visit = append(*visit, root.Val)
- } else {
- findChild(root.Left, K-1, visit)
- findChild(root.Right, K-1, visit)
- }
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0864.Shortest-Path-to-Get-All-Keys.md b/website/content/ChapterFour/0864.Shortest-Path-to-Get-All-Keys.md
deleted file mode 100755
index d6d65b49c..000000000
--- a/website/content/ChapterFour/0864.Shortest-Path-to-Get-All-Keys.md
+++ /dev/null
@@ -1,231 +0,0 @@
-# [864. Shortest Path to Get All Keys](https://leetcode.com/problems/shortest-path-to-get-all-keys/)
-
-
-## 题目
-
-We are given a 2-dimensional `grid`. `"."` is an empty cell, `"#"` is a wall, `"@"` is the starting point, (`"a"`, `"b"`, ...) are keys, and (`"A"`, `"B"`, ...) are locks.
-
-We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions. We cannot walk outside the grid, or walk into a wall. If we walk over a key, we pick it up. We can't walk over a lock unless we have the corresponding key.
-
-For some 1 <= K <= 6, there is exactly one lowercase and one uppercase letter of the first `K` letters of the English alphabet in the grid. This means that there is exactly one key for each lock, and one lock for each key; and also that the letters used to represent the keys and locks were chosen in the same order as the English alphabet.
-
-Return the lowest number of moves to acquire all keys. If it's impossible, return `-1`.
-
-**Example 1**:
-
- Input: ["@.a.#","###.#","b.A.B"]
- Output: 8
-
-**Example 2**:
-
- Input: ["@..aA","..B#.","....b"]
- Output: 6
-
-**Note**:
-
-1. `1 <= grid.length <= 30`
-2. `1 <= grid[0].length <= 30`
-3. `grid[i][j]` contains only `'.'`, `'#'`, `'@'`, `'a'-'f'` and `'A'-'F'`
-4. The number of keys is in `[1, 6]`. Each key has a different letter and opens exactly one lock.
-
-
-## 题目大意
-
-给定一个二维网格 grid。 "." 代表一个空房间, "#" 代表一堵墙, "@" 是起点,("a", "b", ...)代表钥匙,("A", "B", ...)代表锁。
-
-我们从起点开始出发,一次移动是指向四个基本方向之一行走一个单位空间。我们不能在网格外面行走,也无法穿过一堵墙。如果途经一个钥匙,我们就把它捡起来。除非我们手里有对应的钥匙,否则无法通过锁。
-
-假设 K 为钥匙/锁的个数,且满足 1 <= K <= 6,字母表中的前 K 个字母在网格中都有自己对应的一个小写和一个大写字母。换言之,每个锁有唯一对应的钥匙,每个钥匙也有唯一对应的锁。另外,代表钥匙和锁的字母互为大小写并按字母顺序排列。
-
-返回获取所有钥匙所需要的移动的最少次数。如果无法获取所有钥匙,返回 -1 。
-
-提示:
-
-1. 1 <= grid.length <= 30
-2. 1 <= grid[0].length <= 30
-3. grid[i][j] 只含有 '.', '#', '@', 'a'-'f' 以及 'A'-'F'
-4. 钥匙的数目范围是 [1, 6],每个钥匙都对应一个不同的字母,正好打开一个对应的锁。
-
-
-## 解题思路
-
-
-- 给出一个地图,在图中有钥匙和锁,当锁在没有钥匙的时候不能通行,问从起点 @ 开始,到最终获得所有钥匙,最短需要走多少步。
-- 这一题可以用 BFS 来解答。由于钥匙的种类比较多,所以 visited 数组需要 3 个维度,一个是 x 坐标,一个是 y 坐标,最后一个是当前获取钥匙的状态。每把钥匙都有获取了和没有获取两种状态,题目中说最多有 6 把钥匙,那么排列组合最多是 2^6 = 64 种状态。用一个十进制数的二进制位来压缩这些状态,二进制位分别来表示这些钥匙是否已经获取了。既然钥匙的状态可以压缩,其实 x 和 y 的坐标也可以一并压缩到这个数中。BFS 中存的数字是坐标 + 钥匙状态的状态。在 BFS 遍历的过程中,用 visited 数组来过滤遍历过的情况,来保证走的路是最短的。其他的情况无非是判断锁的状态,是否能通过,判断钥匙获取状态。
-- 这一题不知道是否能用 DFS 来解答。我实现了一版,但是在 18 / 35 这组 case 上超时了,具体 case 见测试文件第一个 case。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
- "strings"
-)
-
-// 解法一 BFS,利用状态压缩来过滤筛选状态
-func shortestPathAllKeys(grid []string) int {
- if len(grid) == 0 {
- return 0
- }
- board, visited, startx, starty, res, fullKeys := make([][]byte, len(grid)), make([][][]bool, len(grid)), 0, 0, 0, 0
- for i := 0; i < len(grid); i++ {
- board[i] = make([]byte, len(grid[0]))
- }
- for i, g := range grid {
- board[i] = []byte(g)
- for _, v := range g {
- if v == 'a' || v == 'b' || v == 'c' || v == 'd' || v == 'e' || v == 'f' {
- fullKeys |= (1 << uint(v-'a'))
- }
- }
- if strings.Contains(g, "@") {
- startx, starty = i, strings.Index(g, "@")
- }
- }
- for i := 0; i < len(visited); i++ {
- visited[i] = make([][]bool, len(board[0]))
- }
- for i := 0; i < len(board); i++ {
- for j := 0; j < len(board[0]); j++ {
- visited[i][j] = make([]bool, 64)
- }
- }
- queue := []int{}
- queue = append(queue, (starty<<16)|(startx<<8))
- visited[startx][starty][0] = true
- for len(queue) != 0 {
- qLen := len(queue)
- for i := 0; i < qLen; i++ {
- state := queue[0]
- queue = queue[1:]
- starty, startx = state>>16, (state>>8)&0xFF
- keys := state & 0xFF
- if keys == fullKeys {
- return res
- }
- for i := 0; i < 4; i++ {
- newState := keys
- nx := startx + dir[i][0]
- ny := starty + dir[i][1]
- if !isInBoard(board, nx, ny) {
- continue
- }
- if board[nx][ny] == '#' {
- continue
- }
- flag, canThroughLock := keys&(1<<(board[nx][ny]-'A')), false
- if flag != 0 {
- canThroughLock = true
- }
- if isLock(board, nx, ny) && !canThroughLock {
- continue
- }
- if isKey(board, nx, ny) {
- newState |= (1 << (board[nx][ny] - 'a'))
- }
- if visited[nx][ny][newState] {
- continue
- }
- queue = append(queue, (ny<<16)|(nx<<8)|newState)
- visited[nx][ny][newState] = true
- }
- }
- res++
- }
- return -1
-}
-
-// 解法二 DFS,但是超时了,剪枝条件不够强
-func shortestPathAllKeys1(grid []string) int {
- if len(grid) == 0 {
- return 0
- }
- board, visited, startx, starty, res, fullKeys := make([][]byte, len(grid)), make([][][]bool, len(grid)), 0, 0, math.MaxInt64, 0
- for i := 0; i < len(grid); i++ {
- board[i] = make([]byte, len(grid[0]))
- }
- for i, g := range grid {
- board[i] = []byte(g)
- for _, v := range g {
- if v == 'a' || v == 'b' || v == 'c' || v == 'd' || v == 'e' || v == 'f' {
- fullKeys |= (1 << uint(v-'a'))
- }
- }
- if strings.Contains(g, "@") {
- startx, starty = i, strings.Index(g, "@")
- }
- }
- for i := 0; i < len(visited); i++ {
- visited[i] = make([][]bool, len(board[0]))
- }
- for i := 0; i < len(board); i++ {
- for j := 0; j < len(board[0]); j++ {
- visited[i][j] = make([]bool, 64)
- }
- }
- searchKeys(board, &visited, fullKeys, 0, (starty<<16)|(startx<<8), &res, []int{})
- if res == math.MaxInt64 {
- return -1
- }
- return res - 1
-}
-
-func searchKeys(board [][]byte, visited *[][][]bool, fullKeys, step, state int, res *int, path []int) {
- y, x := state>>16, (state>>8)&0xFF
- keys := state & 0xFF
-
- if keys == fullKeys {
- *res = min(*res, step)
- return
- }
-
- flag, canThroughLock := keys&(1<<(board[x][y]-'A')), false
- if flag != 0 {
- canThroughLock = true
- }
- newState := keys
- //fmt.Printf("x = %v y = %v fullKeys = %v keys = %v step = %v res = %v path = %v state = %v\n", x, y, fullKeys, keys, step, *res, path, state)
- if (board[x][y] != '#' && !isLock(board, x, y)) || (isLock(board, x, y) && canThroughLock) {
- if isKey(board, x, y) {
- newState |= (1 << uint(board[x][y]-'a'))
- }
- (*visited)[x][y][newState] = true
- path = append(path, x)
- path = append(path, y)
-
- for i := 0; i < 4; i++ {
- nx := x + dir[i][0]
- ny := y + dir[i][1]
- if isInBoard(board, nx, ny) && !(*visited)[nx][ny][newState] {
- searchKeys(board, visited, fullKeys, step+1, (ny<<16)|(nx<<8)|newState, res, path)
- }
- }
- (*visited)[x][y][keys] = false
- path = path[:len(path)-1]
- path = path[:len(path)-1]
- }
-}
-
-func isLock(board [][]byte, x, y int) bool {
- if (board[x][y] == 'A') || (board[x][y] == 'B') ||
- (board[x][y] == 'C') || (board[x][y] == 'D') ||
- (board[x][y] == 'E') || (board[x][y] == 'F') {
- return true
- }
- return false
-}
-
-func isKey(board [][]byte, x, y int) bool {
- if (board[x][y] == 'a') || (board[x][y] == 'b') ||
- (board[x][y] == 'c') || (board[x][y] == 'd') ||
- (board[x][y] == 'e') || (board[x][y] == 'f') {
- return true
- }
- return false
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0867.Transpose-Matrix.md b/website/content/ChapterFour/0867.Transpose-Matrix.md
deleted file mode 100755
index 379b9b25b..000000000
--- a/website/content/ChapterFour/0867.Transpose-Matrix.md
+++ /dev/null
@@ -1,57 +0,0 @@
-# [867. Transpose Matrix](https://leetcode.com/problems/transpose-matrix/)
-
-
-## 题目
-
-Given a matrix `A`, return the transpose of `A`.
-
-The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix.
-
-**Example 1**:
-
- Input: [[1,2,3],[4,5,6],[7,8,9]]
- Output: [[1,4,7],[2,5,8],[3,6,9]]
-
-**Example 2**:
-
- Input: [[1,2,3],[4,5,6]]
- Output: [[1,4],[2,5],[3,6]]
-
-**Note**:
-
-1. `1 <= A.length <= 1000`
-2. `1 <= A[0].length <= 1000`
-
-
-## 题目大意
-
-给定一个矩阵 A, 返回 A 的转置矩阵。矩阵的转置是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引。
-
-
-## 解题思路
-
-
-- 给出一个矩阵,顺时针旋转 90°
-- 解题思路很简单,直接模拟即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func transpose(A [][]int) [][]int {
- row, col, result := len(A), len(A[0]), make([][]int, len(A[0]))
- for i := range result {
- result[i] = make([]int, row)
- }
- for i := 0; i < row; i++ {
- for j := 0; j < col; j++ {
- result[j][i] = A[i][j]
- }
- }
- return result
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0872.Leaf-Similar-Trees.md b/website/content/ChapterFour/0872.Leaf-Similar-Trees.md
deleted file mode 100644
index 900b7e746..000000000
--- a/website/content/ChapterFour/0872.Leaf-Similar-Trees.md
+++ /dev/null
@@ -1,62 +0,0 @@
-# [872. Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees/)
-
-
-
-## 题目
-
-Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a *leaf value sequence.*
-
-
-
-For example, in the given tree above, the leaf value sequence is `(6, 7, 4, 9, 8)`.
-
-Two binary trees are considered *leaf-similar* if their leaf value sequence is the same.
-
-Return `true` if and only if the two given trees with head nodes `root1` and `root2` are leaf-similar.
-
-**Note**:
-
-- Both of the given trees will have between `1` and `100` nodes.
-
-## 题目大意
-
-请考虑一颗二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个 叶值序列 。举个例子,如上图所示,给定一颗叶值序列为 (6, 7, 4, 9, 8) 的树。如果有两颗二叉树的叶值序列是相同,那么我们就认为它们是 叶相似 的。如果给定的两个头结点分别为 root1 和 root2 的树是叶相似的,则返回 true;否则返回 false 。
-
-提示:
-
-- 给定的两颗树可能会有 1 到 200 个结点。
-- 给定的两颗树上的值介于 0 到 200 之间。
-
-## 解题思路
-
-- 给出 2 棵树,如果 2 棵树的叶子节点组成的数组是完全一样的,那么就认为这 2 棵树是“叶子相似”的。给出任何 2 棵树判断这 2 棵树是否是“叶子相似”的。
-- 简单题,分别 DFS 遍历 2 棵树,把叶子节点都遍历出来,然后分别比较叶子节点组成的数组是否完全一致即可。
-
-## 代码
-
-```go
-func leafSimilar(root1 *TreeNode, root2 *TreeNode) bool {
- leaf1, leaf2 := []int{}, []int{}
- dfsLeaf(root1, &leaf1)
- dfsLeaf(root2, &leaf2)
- if len(leaf1) != len(leaf2) {
- return false
- }
- for i := range leaf1 {
- if leaf1[i] != leaf2[i] {
- return false
- }
- }
- return true
-}
-
-func dfsLeaf(root *TreeNode, leaf *[]int) {
- if root != nil {
- if root.Left == nil && root.Right == nil {
- *leaf = append(*leaf, root.Val)
- }
- dfsLeaf(root.Left, leaf)
- dfsLeaf(root.Right, leaf)
- }
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0875.Koko-Eating-Bananas.md b/website/content/ChapterFour/0875.Koko-Eating-Bananas.md
deleted file mode 100755
index f2c7c411c..000000000
--- a/website/content/ChapterFour/0875.Koko-Eating-Bananas.md
+++ /dev/null
@@ -1,101 +0,0 @@
-# [875. Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/)
-
-
-## 题目
-
-Koko loves to eat bananas. There are `N` piles of bananas, the `i`-th pile has `piles[i]` bananas. The guards have gone and will come back in `H` hours.
-
-Koko can decide her bananas-per-hour eating speed of `K`. Each hour, she chooses some pile of bananas, and eats K bananas from that pile. If the pile has less than `K` bananas, she eats all of them instead, and won't eat any more bananas during this hour.
-
-Koko likes to eat slowly, but still wants to finish eating all the bananas before the guards come back.
-
-Return the minimum integer `K` such that she can eat all the bananas within `H` hours.
-
-**Example 1**:
-
- Input: piles = [3,6,7,11], H = 8
- Output: 4
-
-**Example 2**:
-
- Input: piles = [30,11,23,4,20], H = 5
- Output: 30
-
-**Example 3**:
-
- Input: piles = [30,11,23,4,20], H = 6
- Output: 23
-
-**Note**:
-
-- `1 <= piles.length <= 10^4`
-- `piles.length <= H <= 10^9`
-- `1 <= piles[i] <= 10^9`
-
-
-## 题目大意
-
-
-珂珂喜欢吃香蕉。这里有 N 堆香蕉,第 i 堆中有 piles[i] 根香蕉。警卫已经离开了,将在 H 小时后回来。
-
-珂珂可以决定她吃香蕉的速度 K (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 K 根。如果这堆香蕉少于 K 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉。
-
-珂珂喜欢慢慢吃,但仍然想在警卫回来前吃掉所有的香蕉。
-
-返回她可以在 H 小时内吃掉所有香蕉的最小速度 K(K 为整数)。
-
-提示:
-
-- 1 <= piles.length <= 10^4
-- piles.length <= H <= 10^9
-- 1 <= piles[i] <= 10^9
-
-
-
-## 解题思路
-
-
-- 给出一个数组,数组里面每个元素代表的是每个香蕉🍌串上香蕉的个数。koko 以 `k 个香蕉/小时`的速度吃这些香蕉。守卫会在 `H 小时`以后回来。问 k 至少为多少,能在守卫回来之前吃完所有的香蕉。当香蕉的个数小于 k 的时候,这个小时只能吃完这些香蕉,不能再吃其他串上的香蕉了。
-- 这一题可以用二分搜索来解答。在 `[0 , max(piles)]` 的范围内搜索,二分的过程都是常规思路。判断是否左右边界如果划分的时候需要注意题目中给的限定条件。当香蕉个数小于 k 的时候,那个小时不能再吃其他香蕉了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math"
-
-func minEatingSpeed(piles []int, H int) int {
- low, high := 1, maxInArr(piles)
- for low < high {
- mid := low + (high-low)>>1
- if !isPossible(piles, mid, H) {
- low = mid + 1
- } else {
- high = mid
- }
- }
- return low
-}
-
-func isPossible(piles []int, h, H int) bool {
- res := 0
- for _, p := range piles {
- res += int(math.Ceil(float64(p) / float64(h)))
- }
- return res <= H
-}
-
-func maxInArr(xs []int) int {
- res := 0
- for _, x := range xs {
- if res < x {
- res = x
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0876.Middle-of-the-Linked-List.md b/website/content/ChapterFour/0876.Middle-of-the-Linked-List.md
deleted file mode 100644
index b9f801fd2..000000000
--- a/website/content/ChapterFour/0876.Middle-of-the-Linked-List.md
+++ /dev/null
@@ -1,82 +0,0 @@
-# [876. Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/)
-
-## 题目
-
-Given a non-empty, singly linked list with head node head, return a middle node of linked list.
-
-If there are two middle nodes, return the second middle node.
-
-**Example 1**:
-
-```
-
-Input: [1,2,3,4,5]
-Output: Node 3 from this list (Serialization: [3,4,5])
-The returned node has value 3. (The judge's serialization of this node is [3,4,5]).
-Note that we returned a ListNode object ans, such that:
-ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, and ans.next.next.next = NULL.
-
-```
-
-**Example 2**:
-
-```
-
-Input: [1,2,3,4,5,6]
-Output: Node 4 from this list (Serialization: [4,5,6])
-Since the list has two middle nodes with values 3 and 4, we return the second one.
-
-```
-
-**Note**:
-
-- The number of nodes in the given list will be between 1 and 100.
-
-## 题目大意
-
-输出链表中间结点。这题在前面题目中反复出现了很多次了。
-
-如果链表长度是奇数,输出中间结点是中间结点。如果链表长度是双数,输出中间结点是中位数后面的那个结点。
-
-## 解题思路
-
-这道题有一个很简单的做法,用 2 个指针只遍历一次就可以找到中间节点。一个指针每次移动 2 步,另外一个指针每次移动 1 步,当快的指针走到终点的时候,慢的指针就是中间节点。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for singly-linked list.
- * type ListNode struct {
- * Val int
- * Next *ListNode
- * }
- */
-
-func middleNode(head *ListNode) *ListNode {
- if head == nil || head.Next == nil {
- return head
- }
- p1 := head
- p2 := head
- for p2.Next != nil && p2.Next.Next != nil {
- p1 = p1.Next
- p2 = p2.Next.Next
- }
- length := 0
- cur := head
- for cur != nil {
- length++
- cur = cur.Next
- }
- if length%2 == 0 {
- return p1.Next
- }
- return p1
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0878.Nth-Magical-Number.md b/website/content/ChapterFour/0878.Nth-Magical-Number.md
deleted file mode 100755
index d78c5ed96..000000000
--- a/website/content/ChapterFour/0878.Nth-Magical-Number.md
+++ /dev/null
@@ -1,81 +0,0 @@
-# [878. Nth Magical Number](https://leetcode.com/problems/nth-magical-number/)
-
-
-## 题目
-
-A positive integer is *magical* if it is divisible by either A or B.
-
-Return the N-th magical number. Since the answer may be very large, **return it modulo** `10^9 + 7`.
-
-**Example 1**:
-
- Input: N = 1, A = 2, B = 3
- Output: 2
-
-**Example 2**:
-
- Input: N = 4, A = 2, B = 3
- Output: 6
-
-**Example 3**:
-
- Input: N = 5, A = 2, B = 4
- Output: 10
-
-**Example 4**:
-
- Input: N = 3, A = 6, B = 4
- Output: 8
-
-**Note**:
-
-1. `1 <= N <= 10^9`
-2. `2 <= A <= 40000`
-3. `2 <= B <= 40000`
-
-
-## 题目大意
-
-
-如果正整数可以被 A 或 B 整除,那么它是神奇的。返回第 N 个神奇数字。由于答案可能非常大,返回它模 10^9 + 7 的结果。
-
-
-提示:
-
-1. 1 <= N <= 10^9
-2. 2 <= A <= 40000
-3. 2 <= B <= 40000
-
-
-## 解题思路
-
-
-- 给出 3 个数字,a,b,n。要求输出可以整除 a 或者整除 b 的第 n 个数。
-- 这一题是第 1201 题的缩水版,代码和解题思路也基本不变,这一题的二分搜索的区间是 `[min(A, B),N * min(A, B)] = [2, 10 ^ 14]`。其他代码和第 1201 题一致,思路见第 1201 题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func nthMagicalNumber(N int, A int, B int) int {
- low, high := int64(0), int64(1*1e14)
- for low < high {
- mid := low + (high-low)>>1
- if calNthMagicalCount(mid, int64(A), int64(B)) < int64(N) {
- low = mid + 1
- } else {
- high = mid
- }
- }
- return int(low) % 1000000007
-}
-
-func calNthMagicalCount(num, a, b int64) int64 {
- ab := a * b / gcd(a, b)
- return num/a + num/b - num/ab
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0880.Decoded-String-at-Index.md b/website/content/ChapterFour/0880.Decoded-String-at-Index.md
deleted file mode 100644
index 960564387..000000000
--- a/website/content/ChapterFour/0880.Decoded-String-at-Index.md
+++ /dev/null
@@ -1,104 +0,0 @@
-# [880. Decoded String at Index](https://leetcode.com/problems/decoded-string-at-index/)
-
-## 题目
-
-An encoded string S is given. To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken:
-
-If the character read is a letter, that letter is written onto the tape.
-If the character read is a digit (say d), the entire current tape is repeatedly written d-1 more times in total.
-Now for some encoded string S, and an index K, find and return the K-th letter (1 indexed) in the decoded string.
-
-
-
-**Example 1**:
-
-```
-
-Input: S = "leet2code3", K = 10
-Output: "o"
-Explanation:
-The decoded string is "leetleetcodeleetleetcodeleetleetcode".
-The 10th letter in the string is "o".
-
-```
-
-**Example 2**:
-
-```
-
-Input: S = "ha22", K = 5
-Output: "h"
-Explanation:
-The decoded string is "hahahaha". The 5th letter is "h".
-
-```
-
-**Example 3**:
-
-```
-
-Input: S = "a2345678999999999999999", K = 1
-Output: "a"
-Explanation:
-The decoded string is "a" repeated 8301530446056247680 times. The 1st letter is "a".
-
-```
-
-**Note**:
-
-1. 2 <= S.length <= 100
-2. S will only contain lowercase letters and digits 2 through 9.
-3. S starts with a letter.
-4. 1 <= K <= 10^9
-5. The decoded string is guaranteed to have less than 2^63 letters.
-
-## 题目大意
-
-给定一个编码字符串 S。为了找出解码字符串并将其写入磁带,从编码字符串中每次读取一个字符,并采取以下步骤:
-
-- 如果所读的字符是字母,则将该字母写在磁带上。
-- 如果所读的字符是数字(例如 d),则整个当前磁带总共会被重复写 d-1 次。
-
-现在,对于给定的编码字符串 S 和索引 K,查找并返回解码字符串中的第 K 个字母。
-
-
-## 解题思路
-
-按照题意,扫描字符串扫到数字的时候,开始重复字符串,这里可以用递归。注意在重复字符串的时候到第 K 个字符的时候就可以返回了,不要等所有字符都扩展完成,这样会超时。d 有可能超大。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func isLetter(char byte) bool {
- if char >= 'a' && char <= 'z' {
- return true
- }
- return false
-}
-
-func decodeAtIndex(S string, K int) string {
- length := 0
- for i := 0; i < len(S); i++ {
- if isLetter(S[i]) {
- length++
- if length == K {
- return string(S[i])
- }
- } else {
- if length*int(S[i]-'0') >= K {
- if K%length != 0 {
- return decodeAtIndex(S[:i], K%length)
- }
- return decodeAtIndex(S[:i], length)
- }
- length *= int(S[i] - '0')
- }
- }
- return ""
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0881.Boats-to-Save-People.md b/website/content/ChapterFour/0881.Boats-to-Save-People.md
deleted file mode 100644
index 2af2b88d5..000000000
--- a/website/content/ChapterFour/0881.Boats-to-Save-People.md
+++ /dev/null
@@ -1,90 +0,0 @@
-# [881. Boats to Save People](https://leetcode.com/problems/boats-to-save-people/)
-
-## 题目
-
-The i-th person has weight people[i], and each boat can carry a maximum weight of limit.
-
-Each boat carries at most 2 people at the same time, provided the sum of the weight of those people is at most limit.
-
-Return the minimum number of boats to carry every given person. (It is guaranteed each person can be carried by a boat.)
-
-
-**Example 1**:
-
-```
-
-Input: people = [1,2], limit = 3
-Output: 1
-Explanation: 1 boat (1, 2)
-
-```
-
-
-**Example 2**:
-
-```
-
-Input: people = [3,2,2,1], limit = 3
-Output: 3
-Explanation: 3 boats (1, 2), (2) and (3)
-
-```
-
-
-**Example 3**:
-
-```
-
-Input: people = [3,5,3,4], limit = 5
-Output: 4
-Explanation: 4 boats (3), (3), (4), (5)
-
-```
-
-**Note**:
-
-- 1 <= people.length <= 50000
-- 1 <= people[i] <= limit <= 30000
-
-
-## 题目大意
-
-给出人的重量数组,和一个船最大载重量 limit。一个船最多装 2 个人。要求输出装下所有人,最小需要多少艘船。
-
-## 解题思路
-
-先对人的重量进行排序,然后用 2 个指针分别指向一前一后,一起计算这两个指针指向的重量之和,如果小于 limit,左指针往右移动,并且右指针往左移动。如果大于等于 limit,右指针往左移动。每次指针移动,需要船的个数都要 ++。
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-func numRescueBoats(people []int, limit int) int {
- sort.Ints(people)
- left, right, res := 0, len(people)-1, 0
- for left <= right {
- if left == right {
- res++
- return res
- }
- if people[left]+people[right] <= limit {
- left++
- right--
- } else {
- right--
- }
- res++
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0884.Uncommon-Words-from-Two-Sentences.md b/website/content/ChapterFour/0884.Uncommon-Words-from-Two-Sentences.md
deleted file mode 100755
index 66fc23b03..000000000
--- a/website/content/ChapterFour/0884.Uncommon-Words-from-Two-Sentences.md
+++ /dev/null
@@ -1,66 +0,0 @@
-# [884. Uncommon Words from Two Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences/)
-
-
-## 题目
-
-We are given two sentences `A` and `B`. (A *sentence* is a string of space separated words. Each *word* consists only of lowercase letters.)
-
-A word is *uncommon* if it appears exactly once in one of the sentences, and does not appear in the other sentence.
-
-Return a list of all uncommon words.
-
-You may return the list in any order.
-
-**Example 1**:
-
- Input: A = "this apple is sweet", B = "this apple is sour"
- Output: ["sweet","sour"]
-
-**Example 2**:
-
- Input: A = "apple apple", B = "banana"
- Output: ["banana"]
-
-**Note**:
-
-1. `0 <= A.length <= 200`
-2. `0 <= B.length <= 200`
-3. `A` and `B` both contain only spaces and lowercase letters.
-
-
-## 题目大意
-
-给定两个句子 A 和 B 。(句子是一串由空格分隔的单词。每个单词仅由小写字母组成。)
-
-如果一个单词在其中一个句子中只出现一次,在另一个句子中却没有出现,那么这个单词就是不常见的。返回所有不常用单词的列表。您可以按任何顺序返回列表。
-
-
-## 解题思路
-
-- 找出 2 个句子中不同的单词,将它们俩都打印出来。简单题,先将 2 个句子的单词都拆开放入 map 中进行词频统计,不同的两个单词的词频肯定都为 1,输出它们即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strings"
-
-func uncommonFromSentences(A string, B string) []string {
- m, res := map[string]int{}, []string{}
- for _, s := range []string{A, B} {
- for _, word := range strings.Split(s, " ") {
- m[word]++
- }
- }
- for key := range m {
- if m[key] == 1 {
- res = append(res, key)
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0885.Spiral-Matrix-III.md b/website/content/ChapterFour/0885.Spiral-Matrix-III.md
deleted file mode 100755
index 0a80d2e00..000000000
--- a/website/content/ChapterFour/0885.Spiral-Matrix-III.md
+++ /dev/null
@@ -1,84 +0,0 @@
-# [885. Spiral Matrix III](https://leetcode.com/problems/spiral-matrix-iii/)
-
-
-## 题目
-
-On a 2 dimensional grid with `R` rows and `C` columns, we start at `(r0, c0)` facing east.
-
-Here, the north-west corner of the grid is at the first row and column, and the south-east corner of the grid is at the last row and column.
-
-Now, we walk in a clockwise spiral shape to visit every position in this grid.
-
-Whenever we would move outside the boundary of the grid, we continue our walk outside the grid (but may return to the grid boundary later.)
-
-Eventually, we reach all `R * C` spaces of the grid.
-
-Return a list of coordinates representing the positions of the grid in the order they were visited.
-
-**Example 1**:
-
- Input: R = 1, C = 4, r0 = 0, c0 = 0
- Output: [[0,0],[0,1],[0,2],[0,3]]
-
-
-
-**Example 2**:
-
- Input: R = 5, C = 6, r0 = 1, c0 = 4
- Output: [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],
- [3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],
- [0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]
-
-
-
-**Note**:
-
-1. `1 <= R <= 100`
-2. `1 <= C <= 100`
-3. `0 <= r0 < R`
-4. `0 <= c0 < C`
-
-
-## 题目大意
-
-在 R 行 C 列的矩阵上,我们从 (r0, c0) 面朝东面开始。这里,网格的西北角位于第一行第一列,网格的东南角位于最后一行最后一列。现在,我们以顺时针按螺旋状行走,访问此网格中的每个位置。每当我们移动到网格的边界之外时,我们会继续在网格之外行走(但稍后可能会返回到网格边界)。最终,我们到过网格的所有 R * C 个空间。
-
-要求输出按照访问顺序返回表示网格位置的坐标列表。
-
-
-## 解题思路
-
-
-- 给出一个二维数组的行 `R`,列 `C`,以及这个数组中的起始点 `(r0,c0)`。从这个起始点开始出发,螺旋的访问数组中各个点,输出途径经过的每个坐标。注意每个螺旋的步长在变长,第一个螺旋是 1 步,第二个螺旋是 1 步,第三个螺旋是 2 步,第四个螺旋是 2 步……即 1,1,2,2,3,3,4,4,5……这样的步长。
-- 这一题是第 59 题的加强版。除了有螺旋以外,还加入了步长的限制。步长其实是有规律的,第 0 次移动的步长是 `0/2+1`,第 1 次移动的步长是 `1/2+1`,第 n 次移动的步长是 `n/2+1`。其他的做法和第 59 题一致。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func spiralMatrixIII(R int, C int, r0 int, c0 int) [][]int {
- res, round, spDir := [][]int{}, 0, [][]int{
- []int{0, 1}, // 朝右
- []int{1, 0}, // 朝下
- []int{0, -1}, // 朝左
- []int{-1, 0}, // 朝上
- }
- res = append(res, []int{r0, c0})
- for i := 0; len(res) < R*C; i++ {
- for j := 0; j < i/2+1; j++ {
- r0 += spDir[round%4][0]
- c0 += spDir[round%4][1]
- if 0 <= r0 && r0 < R && 0 <= c0 && c0 < C {
- res = append(res, []int{r0, c0})
- }
- }
- round++
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0887.Super-Egg-Drop.md b/website/content/ChapterFour/0887.Super-Egg-Drop.md
deleted file mode 100755
index a79b60859..000000000
--- a/website/content/ChapterFour/0887.Super-Egg-Drop.md
+++ /dev/null
@@ -1,155 +0,0 @@
-# [887. Super Egg Drop](https://leetcode.com/problems/super-egg-drop/)
-
-
-## 题目
-
-You are given `K` eggs, and you have access to a building with `N` floors from `1` to `N`.
-
-Each egg is identical in function, and if an egg breaks, you cannot drop it again.
-
-You know that there exists a floor `F` with `0 <= F <= N` such that any egg dropped at a floor higher than `F` will break, and any egg dropped at or below floor `F` will not break.
-
-Each *move*, you may take an egg (if you have an unbroken one) and drop it from any floor `X` (with `1 <= X <= N`).
-
-Your goal is to know **with certainty** what the value of `F` is.
-
-What is the minimum number of moves that you need to know with certainty what `F` is, regardless of the initial value of `F`?
-
-**Example 1**:
-
- Input: K = 1, N = 2
- Output: 2
- Explanation:
- Drop the egg from floor 1. If it breaks, we know with certainty that F = 0.
- Otherwise, drop the egg from floor 2. If it breaks, we know with certainty that F = 1.
- If it didn't break, then we know with certainty F = 2.
- Hence, we needed 2 moves in the worst case to know what F is with certainty.
-
-**Example 2**:
-
- Input: K = 2, N = 6
- Output: 3
-
-**Example 3**:
-
- Input: K = 3, N = 14
- Output: 4
-
-**Note**:
-
-1. `1 <= K <= 100`
-2. `1 <= N <= 10000`
-
-
-## 题目大意
-
-你将获得 K 个鸡蛋,并可以使用一栋从 1 到 N 共有 N 层楼的建筑。每个蛋的功能都是一样的,如果一个蛋碎了,你就不能再把它掉下去。你知道存在楼层 F ,满足 0 <= F <= N 任何从高于 F 的楼层落下的鸡蛋都会碎,从 F 楼层或比它低的楼层落下的鸡蛋都不会破。每次移动,你可以取一个鸡蛋(如果你有完整的鸡蛋)并把它从任一楼层 X 扔下(满足 1 <= X <= N)。你的目标是确切地知道 F 的值是多少。无论 F 的初始值如何,你确定 F 的值的最小移动次数是多少?
-
-
-提示:
-
-1. 1 <= K <= 100
-2. 1 <= N <= 10000
-
-
-## 解题思路
-
-- 给出 `K` 个鸡蛋,`N` 层楼,要求确定安全楼层 `F` 需要最小步数 `t`。
-- 这一题是微软的经典面试题。拿到题最容易想到的是二分搜索。但是仔细分析以后会发现单纯的二分是不对的。不断的二分确实能找到最终安全的楼层,但是这里没有考虑到 `K` 个鸡蛋。鸡蛋数的限制会导致二分搜索无法找到最终楼层。题目要求要在保证能找到最终安全楼层的情况下,找到最小步数。所以单纯的二分搜索并不能解答这道题。
-- 这一题如果按照题意正向考虑,动态规划的状态转移方程是 `searchTime(K, N) = max( searchTime(K-1, X-1), searchTime(K, N-X) )`。其中 `X` 是丢鸡蛋的楼层。随着 `X` 从 `[1,N]`,都能计算出一个 `searchTime` 的值,在所有这 `N` 个值之中,取最小值就是本题的答案了。这个解法可以 AC 这道题。不过这个解法不细展开了。时间复杂度 `O(k*N^2)`。
-
-
-- 利用二分搜索,不断的二分 `t`,直到逼近找到 `f(t,k) ≥ N` 时候最小的 `t`。时间复杂度 `O(K * log N)`,空间复杂度 `O(1)`。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 二分搜索
-func superEggDrop(K int, N int) int {
- low, high := 1, N
- for low < high {
- mid := low + (high-low)>>1
- if counterF(K, N, mid) >= N {
- high = mid
- } else {
- low = mid + 1
- }
- }
- return low
-}
-
-// 计算二项式和,特殊的第一项 C(t,0) = 1
-func counterF(k, n, mid int) int {
- res, sum := 1, 0
- for i := 1; i <= k && sum < n; i++ {
- res *= mid - i + 1
- res /= i
- sum += res
- }
- return sum
-}
-
-// 解法二 动态规划 DP
-func superEggDrop1(K int, N int) int {
- dp, step := make([]int, K+1), 0
- for ; dp[K] < N; step++ {
- for i := K; i > 0; i-- {
- dp[i] = (1 + dp[i] + dp[i-1])
- }
- }
- return step
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0888.Fair-Candy-Swap.md b/website/content/ChapterFour/0888.Fair-Candy-Swap.md
deleted file mode 100644
index 79a2c2bc1..000000000
--- a/website/content/ChapterFour/0888.Fair-Candy-Swap.md
+++ /dev/null
@@ -1,110 +0,0 @@
-# [888. Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap/)
-
-
-## 题目
-
-Alice and Bob have candy bars of different sizes: `A[i]` is the size of the `i`-th bar of candy that Alice has, and `B[j]` is the size of the `j`-th bar of candy that Bob has.
-
-Since they are friends, they would like to exchange one candy bar each so that after the exchange, they both have the same total amount of candy. (*The total amount of candy a person has is the sum of the sizes of candy bars they have*.)
-
-Return an integer array `ans` where `ans[0]` is the size of the candy bar that Alice must exchange, and `ans[1]` is the size of the candy bar that Bob must exchange.
-
-If there are multiple answers, you may return any one of them. It is guaranteed an answer exists.
-
-**Example 1**:
-
-```
-Input: A = [1,1], B = [2,2]
-Output: [1,2]
-```
-
-**Example 2**:
-
-```
-Input: A = [1,2], B = [2,3]
-Output: [1,2]
-```
-
-**Example 3**:
-
-```
-Input: A = [2], B = [1,3]
-Output: [2,3]
-```
-
-**Example 4**:
-
-```
-Input: A = [1,2,5], B = [2,4]
-Output: [5,4]
-```
-
-**Note**:
-
-- `1 <= A.length <= 10000`
-- `1 <= B.length <= 10000`
-- `1 <= A[i] <= 100000`
-- `1 <= B[i] <= 100000`
-- It is guaranteed that Alice and Bob have different total amounts of candy.
-- It is guaranteed there exists an answer.
-
-
-## 题目大意
-
-爱丽丝和鲍勃有不同大小的糖果棒:A[i] 是爱丽丝拥有的第 i 块糖的大小,B[j] 是鲍勃拥有的第 j 块糖的大小。因为他们是朋友,所以他们想交换一个糖果棒,这样交换后,他们都有相同的糖果总量。(一个人拥有的糖果总量是他们拥有的糖果棒大小的总和。)返回一个整数数组 ans,其中 ans[0] 是爱丽丝必须交换的糖果棒的大小,ans[1] 是 Bob 必须交换的糖果棒的大小。如果有多个答案,你可以返回其中任何一个。保证答案存在。
-
-提示:
-
-- 1 <= A.length <= 10000
-- 1 <= B.length <= 10000
-- 1 <= A[i] <= 100000
-- 1 <= B[i] <= 100000
-- 保证爱丽丝与鲍勃的糖果总量不同。
-- 答案肯定存在。
-
-
-## 解题思路
-
-- 两人交换糖果,使得两人糖果相等。要求输出一个数组,里面分别包含两人必须交换的糖果大小。
-- 首先这一题肯定了一定有解,其次只允许交换一次。有了这两个前提,使本题变成简单题。先计算出为了使得交换以后两个相同的糖果数,A 需要增加或者减少的糖果数 diff。然后遍历 B ,看 A 中是否存在一个元素,能使得 B 做了对应交换 diff 以后,两人糖果相等。(此题前提保证了一定能找到)。最后输出 A 中的这个元素和遍历到 B 的这个元素,即是两人要交换的糖果数。
-
-## 代码
-
-```go
-
-package leetcode
-
-func fairCandySwap(A []int, B []int) []int {
- hDiff, aMap := diff(A, B)/2, make(map[int]int, len(A))
- for _, a := range A {
- aMap[a] = a
- }
- for _, b := range B {
- if a, ok := aMap[hDiff+b]; ok {
- return []int{a, b}
- }
- }
- return nil
-}
-
-func diff(A []int, B []int) int {
- diff, maxLen := 0, max(len(A), len(B))
- for i := 0; i < maxLen; i++ {
- if i < len(A) {
- diff += A[i]
- }
- if i < len(B) {
- diff -= B[i]
- }
- }
- return diff
-}
-
-func max(a, b int) int {
- if a > b {
- return a
- }
- return b
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0891.Sum-of-Subsequence-Widths.md b/website/content/ChapterFour/0891.Sum-of-Subsequence-Widths.md
deleted file mode 100644
index 9e5f04794..000000000
--- a/website/content/ChapterFour/0891.Sum-of-Subsequence-Widths.md
+++ /dev/null
@@ -1,68 +0,0 @@
-# [891. Sum of Subsequence Widths](https://leetcode.com/problems/sum-of-subsequence-widths/)
-
-## 题目
-
-Given an array of integers A, consider all non-empty subsequences of A.
-
-For any sequence S, let the width of S be the difference between the maximum and minimum element of S.
-
-Return the sum of the widths of all subsequences of A.
-
-As the answer may be very large, return the answer modulo 10^9 + 7.
-
-
-
-**Example 1**:
-
-```
-
-Input: [2,1,3]
-Output: 6
-Explanation:
-Subsequences are [1], [2], [3], [2,1], [2,3], [1,3], [2,1,3].
-The corresponding widths are 0, 0, 0, 1, 1, 2, 2.
-The sum of these widths is 6.
-
-```
-
-**Note**:
-
-- 1 <= A.length <= 20000
-- 1 <= A[i] <= 20000
-
-
-## 题目大意
-
-给定一个整数数组 A ,考虑 A 的所有非空子序列。对于任意序列 S ,设 S 的宽度是 S 的最大元素和最小元素的差。返回 A 的所有子序列的宽度之和。由于答案可能非常大,请返回答案模 10^9+7。
-
-
-## 解题思路
-
-- 理解题意以后,可以发现,数组内元素的顺序并不影响最终求得的所有子序列的宽度之和。
-
- [2,1,3]:[1],[2],[3],[2,1],[2,3],[1,3],[2,1,3]
- [1,2,3]:[1],[2],[3],[1,2],[2,3],[1,3],[1,2,3]
- 针对每个 A[i] 而言,A[i] 对最终结果的贡献是在子序列的左右两边的时候才有贡献,当 A[i] 位于区间中间的时候,不影响最终结果。先对 A[i] 进行排序,排序以后,有 i 个数 <= A[i],有 n - i - 1 个数 >= A[i]。所以 A[i] 会在 2^i 个子序列的右边界出现,2^(n-i-1) 个左边界出现。那么 A[i] 对最终结果的贡献是 A[i] * 2^i - A[i] * 2^(n-i-1) 。举个例子,[1,4,5,7],A[2] = 5,那么 5 作为右边界的子序列有 2^2 = 4 个,即 [5],[1,5],[4,5],[1,4,5],5 作为左边界的子序列有 2^(4-2-1) = 2 个,即 [5],[5,7]。A[2] = 5 对最终结果的影响是 5 * 2^2 - 5 * 2^(4-2-1) = 10 。
-- 题目要求所有子序列的宽度之和,也就是求每个区间最大值减去最小值的总和。那么 `Ans = SUM{ A[i]*2^i - A[n-i-1] * 2^(n-i-1) }`,其中 `0 <= i < n`。需要注意的是 2^i 可能非常大,所以在计算中就需要去 mod 了,而不是最后计算完了再 mod。注意取模的结合律:`(a * b) % c = (a % c) * (b % c) % c`。
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-func sumSubseqWidths(A []int) int {
- sort.Ints(A)
- res, mod, n, p := 0, 1000000007, len(A), 1
- for i := 0; i < n; i++ {
- res = (res + (A[i]-A[n-1-i])*p) % mod
- p = (p << 1) % mod
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0892.Surface-Area-of-3D-Shapes.md b/website/content/ChapterFour/0892.Surface-Area-of-3D-Shapes.md
deleted file mode 100644
index bcb6ad517..000000000
--- a/website/content/ChapterFour/0892.Surface-Area-of-3D-Shapes.md
+++ /dev/null
@@ -1,108 +0,0 @@
-# [892. Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes/)
-
-
-## 题目
-
-On a `N * N` grid, we place some `1 * 1 * 1` cubes.
-
-Each value `v = grid[i][j]` represents a tower of `v` cubes placed on top of grid cell `(i, j)`.
-
-Return the total surface area of the resulting shapes.
-
-**Example 1**:
-
-```
-Input: [[2]]
-Output: 10
-```
-
-**Example 2**:
-
-```
-Input: [[1,2],[3,4]]
-Output: 34
-```
-
-**Example 3**:
-
-```
-Input: [[1,0],[0,2]]
-Output: 16
-```
-
-**Example 4**:
-
-```
-Input: [[1,1,1],[1,0,1],[1,1,1]]
-Output: 32
-```
-
-**Example 5**:
-
-```
-Input: [[2,2,2],[2,1,2],[2,2,2]]
-Output: 46
-```
-
-**Note**:
-
-- `1 <= N <= 50`
-- `0 <= grid[i][j] <= 50`
-
-## 题目大意
-
-在 N * N 的网格上,我们放置一些 1 * 1 * 1 的立方体。每个值 v = grid[i][j] 表示 v 个正方体叠放在对应单元格 (i, j) 上。请你返回最终形体的表面积。
-
-
-## 解题思路
-
-- 给定一个网格数组,数组里面装的是立方体叠放在所在的单元格,求最终这些叠放的立方体的表面积。
-- 简单题。按照题目意思,找到叠放时,重叠的面,然后用总表面积减去这些重叠的面积即为最终答案。
-
-## 代码
-
-```go
-
-package leetcode
-
-func surfaceArea(grid [][]int) int {
- area := 0
- for i := 0; i < len(grid); i++ {
- for j := 0; j < len(grid[0]); j++ {
- if grid[i][j] == 0 {
- continue
- }
- area += grid[i][j]*4 + 2
- // up
- if i > 0 {
- m := min(grid[i][j], grid[i-1][j])
- area -= m
- }
- // down
- if i < len(grid)-1 {
- m := min(grid[i][j], grid[i+1][j])
- area -= m
- }
- // left
- if j > 0 {
- m := min(grid[i][j], grid[i][j-1])
- area -= m
- }
- // right
- if j < len(grid[i])-1 {
- m := min(grid[i][j], grid[i][j+1])
- area -= m
- }
- }
- }
- return area
-}
-
-func min(a, b int) int {
- if a > b {
- return b
- }
- return a
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0895.Maximum-Frequency-Stack.md b/website/content/ChapterFour/0895.Maximum-Frequency-Stack.md
deleted file mode 100644
index bd1c20607..000000000
--- a/website/content/ChapterFour/0895.Maximum-Frequency-Stack.md
+++ /dev/null
@@ -1,113 +0,0 @@
-# [895. Maximum Frequency Stack](https://leetcode.com/problems/maximum-frequency-stack/)
-
-## 题目
-
-Implement FreqStack, a class which simulates the operation of a stack-like data structure.
-
-FreqStack has two functions:
-
-push(int x), which pushes an integer x onto the stack.
-pop(), which removes and returns the most frequent element in the stack.
-If there is a tie for most frequent element, the element closest to the top of the stack is removed and returned.
-
-
-**Example 1**:
-
-```
-
-Input:
-["FreqStack","push","push","push","push","push","push","pop","pop","pop","pop"],
-[[],[5],[7],[5],[7],[4],[5],[],[],[],[]]
-Output: [null,null,null,null,null,null,null,5,7,5,4]
-Explanation:
-After making six .push operations, the stack is [5,7,5,7,4,5] from bottom to top. Then:
-
-pop() -> returns 5, as 5 is the most frequent.
-The stack becomes [5,7,5,7,4].
-
-pop() -> returns 7, as 5 and 7 is the most frequent, but 7 is closest to the top.
-The stack becomes [5,7,5,4].
-
-pop() -> returns 5.
-The stack becomes [5,7,4].
-
-pop() -> returns 4.
-The stack becomes [5,7].
-
-```
-
-**Note**:
-
-- Calls to FreqStack.push(int x) will be such that 0 <= x <= 10^9.
-- It is guaranteed that FreqStack.pop() won't be called if the stack has zero elements.
-- The total number of FreqStack.push calls will not exceed 10000 in a single test case.
-- The total number of FreqStack.pop calls will not exceed 10000 in a single test case.
-- The total number of FreqStack.push and FreqStack.pop calls will not exceed 150000 across all test cases.
-
-## 题目大意
-
-实现 FreqStack,模拟类似栈的数据结构的操作的一个类。
-
-FreqStack 有两个函数:
-
-- push(int x),将整数 x 推入栈中。
-- pop(),它移除并返回栈中出现最频繁的元素。如果最频繁的元素不只一个,则移除并返回最接近栈顶的元素。
-
-
-## 解题思路
-
-FreqStack 里面保存频次的 map 和相同频次 group 的 map。push 的时候动态的维护 x 的频次,并更新到对应频次的 group 中。pop 的时候对应减少频次字典里面的频次,并更新到对应频次的 group 中。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-type FreqStack struct {
- freq map[int]int
- group map[int][]int
- maxfreq int
-}
-
-func Constructor895() FreqStack {
- hash := make(map[int]int)
- maxHash := make(map[int][]int)
- return FreqStack{freq: hash, group: maxHash}
-}
-
-func (this *FreqStack) Push(x int) {
- if _, ok := this.freq[x]; ok {
- this.freq[x]++
- } else {
- this.freq[x] = 1
- }
- f := this.freq[x]
- if f > this.maxfreq {
- this.maxfreq = f
- }
-
- this.group[f] = append(this.group[f], x)
-}
-
-func (this *FreqStack) Pop() int {
- tmp := this.group[this.maxfreq]
- x := tmp[len(tmp)-1]
- this.group[this.maxfreq] = this.group[this.maxfreq][:len(this.group[this.maxfreq])-1]
- this.freq[x]--
- if len(this.group[this.maxfreq]) == 0 {
- this.maxfreq--
- }
- return x
-}
-
-/**
- * Your FreqStack object will be instantiated and called as such:
- * obj := Constructor();
- * obj.Push(x);
- * param_2 := obj.Pop();
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0896.Monotonic-Array.md b/website/content/ChapterFour/0896.Monotonic-Array.md
deleted file mode 100644
index afd6b08d4..000000000
--- a/website/content/ChapterFour/0896.Monotonic-Array.md
+++ /dev/null
@@ -1,99 +0,0 @@
-# [896. Monotonic Array](https://leetcode.com/problems/monotonic-array/)
-
-
-## 题目
-
-An array is *monotonic* if it is either monotone increasing or monotone decreasing.
-
-An array `A` is monotone increasing if for all `i <= j`, `A[i] <= A[j]`. An array `A` is monotone decreasing if for all `i <= j`, `A[i] >= A[j]`.
-
-Return `true` if and only if the given array `A` is monotonic.
-
-**Example 1**:
-
-```
-Input: [1,2,2,3]
-Output: true
-```
-
-**Example 2**:
-
-```
-Input: [6,5,4,4]
-Output: true
-```
-
-**Example 3**:
-
-```
-Input: [1,3,2]
-Output: false
-```
-
-**Example 4**:
-
-```
-Input: [1,2,4,5]
-Output: true
-```
-
-**Example 5**:
-
-```
-Input: [1,1,1]
-Output: true
-```
-
-**Note**:
-
-1. `1 <= A.length <= 50000`
-2. `-100000 <= A[i] <= 100000`
-
-## 题目大意
-
-如果数组是单调递增或单调递减的,那么它是单调的。如果对于所有 i <= j,A[i] <= A[j],那么数组 A 是单调递增的。 如果对于所有 i <= j,A[i]> = A[j],那么数组 A 是单调递减的。当给定的数组 A 是单调数组时返回 true,否则返回 false。
-
-
-## 解题思路
-
-- 判断给定的数组是不是单调(单调递增或者单调递减)的。
-- 简单题,按照题意循环判断即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func isMonotonic(A []int) bool {
- if len(A) <= 1 {
- return true
- }
- if A[0] < A[1] {
- return inc(A[1:])
- }
- if A[0] > A[1] {
- return dec(A[1:])
- }
- return inc(A[1:]) || dec(A[1:])
-}
-
-func inc(A []int) bool {
- for i := 0; i < len(A)-1; i++ {
- if A[i] > A[i+1] {
- return false
- }
- }
- return true
-}
-
-func dec(A []int) bool {
- for i := 0; i < len(A)-1; i++ {
- if A[i] < A[i+1] {
- return false
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md b/website/content/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md
deleted file mode 100755
index 259871f11..000000000
--- a/website/content/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md
+++ /dev/null
@@ -1,143 +0,0 @@
-# [898. Bitwise ORs of Subarrays](https://leetcode.com/problems/bitwise-ors-of-subarrays/)
-
-
-## 题目
-
-We have an array `A` of non-negative integers.
-
-For every (contiguous) subarray `B = [A[i], A[i+1], ..., A[j]]` (with `i <= j`), we take the bitwise OR of all the elements in `B`, obtaining a result `A[i] | A[i+1] | ... | A[j]`.
-
-Return the number of possible results. (Results that occur more than once are only counted once in the final answer.)
-
-**Example 1**:
-
- Input: [0]
- Output: 1
- Explanation:
- There is only one possible result: 0.
-
-**Example 2**:
-
- Input: [1,1,2]
- Output: 3
- Explanation:
- The possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].
- These yield the results 1, 1, 2, 1, 3, 3.
- There are 3 unique values, so the answer is 3.
-
-**Example 3**:
-
- Input: [1,2,4]
- Output: 6
- Explanation:
- The possible results are 1, 2, 3, 4, 6, and 7.
-
-**Note**:
-
-1. `1 <= A.length <= 50000`
-2. `0 <= A[i] <= 10^9`
-
-
-## 题目大意
-
-我们有一个非负整数数组 A。对于每个(连续的)子数组 B = [A[i], A[i+1], ..., A[j]] ( i <= j),我们对 B 中的每个元素进行按位或操作,获得结果 A[i] | A[i+1] | ... | A[j]。返回可能结果的数量。(多次出现的结果在最终答案中仅计算一次。)
-
-
-
-## 解题思路
-
-- 给出一个数组,要求求出这个数组所有的子数组中,每个集合内所有数字取 `|` 运算以后,不同结果的种类数。
-- 这道题可以这样考虑,第一步,先考虑所有的子数组如何得到,以 `[001, 011, 100, 110, 101]` 为例,所有的子数组集合如下:
-
-```c
- [001]
- [001 011] [011]
- [001 011 100] [011 100] [100]
- [001 011 100 110] [011 100 110] [100 110] [110]
- [001 011 100 110 101] [011 100 110 101] [100 110 101] [110 101] [101]
-```
-
-可以发现,从左往右遍历原数组,每次新来的一个元素,依次加入到之前已经生成过的集合中,再以自己为单独集合。这样就可以生成原数组的所有子集。
-
-- 第二步,将每一行的子集内的所有元素都进行 `|` 运算,得到:
-
-```c
- 001
- 011 011
- 111 111 100
- 111 111 110 110
- 111 111 111 111 101
-```
-
-- 第三步,去重:
-
-```c
- 001
- 011
- 111 100
- 111 110
- 111 101
-```
-
-由于二进制位不超过 32 位,所以这里每一行最多不会超过 32 个数。所以最终时间复杂度不会超过 O(32 N),即 O(K * N)。最后将这每一行的数字都放入最终的 map 中去重即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 array 优化版
-func subarrayBitwiseORs(A []int) int {
- res, cur, isInMap := []int{}, []int{}, make(map[int]bool)
- cur = append(cur, 0)
- for _, v := range A {
- var cur2 []int
- for _, vv := range cur {
- tmp := v | vv
- if !inSlice(cur2, tmp) {
- cur2 = append(cur2, tmp)
- }
- }
- if !inSlice(cur2, v) {
- cur2 = append(cur2, v)
- }
- cur = cur2
- for _, vv := range cur {
- if _, ok := isInMap[vv]; !ok {
- isInMap[vv] = true
- res = append(res, vv)
- }
- }
- }
- return len(res)
-}
-
-func inSlice(A []int, T int) bool {
- for _, v := range A {
- if v == T {
- return true
- }
- }
- return false
-}
-
-// 解法二 map 版
-func subarrayBitwiseORs1(A []int) int {
- res, t := map[int]bool{}, map[int]bool{}
- for _, num := range A {
- r := map[int]bool{}
- r[num] = true
- for n := range t {
- r[(num | n)] = true
- }
- t = r
- for n := range t {
- res[n] = true
- }
- }
- return len(res)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0901.Online-Stock-Span.md b/website/content/ChapterFour/0901.Online-Stock-Span.md
deleted file mode 100644
index 582fa43f5..000000000
--- a/website/content/ChapterFour/0901.Online-Stock-Span.md
+++ /dev/null
@@ -1,111 +0,0 @@
-# [901. Online Stock Span](https://leetcode.com/problems/online-stock-span/)
-
-## 题目
-
-Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock's price for the current day.
-
-The span of the stock's price today is defined as the maximum number of consecutive days (starting from today and going backwards) for which the price of the stock was less than or equal to today's price.
-
-For example, if the price of a stock over the next 7 days were [100, 80, 60, 70, 60, 75, 85], then the stock spans would be [1, 1, 1, 2, 1, 4, 6].
-
-
-
-**Example 1**:
-
-```
-
-Input: ["StockSpanner","next","next","next","next","next","next","next"], [[],[100],[80],[60],[70],[60],[75],[85]]
-Output: [null,1,1,1,2,1,4,6]
-Explanation:
-First, S = StockSpanner() is initialized. Then:
-S.next(100) is called and returns 1,
-S.next(80) is called and returns 1,
-S.next(60) is called and returns 1,
-S.next(70) is called and returns 2,
-S.next(60) is called and returns 1,
-S.next(75) is called and returns 4,
-S.next(85) is called and returns 6.
-
-Note that (for example) S.next(75) returned 4, because the last 4 prices
-(including today's price of 75) were less than or equal to today's price.
-
-```
-
-**Note**:
-
-1. Calls to StockSpanner.next(int price) will have 1 <= price <= 10^5.
-2. There will be at most 10000 calls to StockSpanner.next per test case.
-3. There will be at most 150000 calls to StockSpanner.next across all test cases.
-4. The total time limit for this problem has been reduced by 75% for C++, and 50% for all other languages.
-
-## 题目大意
-
-编写一个 StockSpanner 类,它收集某些股票的每日报价,并返回该股票当日价格的跨度。
-
-今天股票价格的跨度被定义为股票价格小于或等于今天价格的最大连续日数(从今天开始往回数,包括今天)。
-
-例如,如果未来7天股票的价格是 [100, 80, 60, 70, 60, 75, 85],那么股票跨度将是 [1, 1, 1, 2, 1, 4, 6]。
-
-
-
-## 解题思路
-
-这一题就是单调栈的题目。维护一个单调递增的下标。
-
-## 总结
-
-单调栈类似的题
-
-496. Next Greater Element I
-497. Next Greater Element II
-498. Daily Temperatures
-499. Sum of Subarray Minimums
-500. Largest Rectangle in Histogram
-
-## 代码
-
-```go
-
-package leetcode
-
-import "fmt"
-
-// node pair
-type Node struct {
- Val int
- res int
-}
-
-// slice
-type StockSpanner struct {
- Item []Node
-}
-
-func Constructor901() StockSpanner {
- stockSpanner := StockSpanner{make([]Node, 0)}
- return stockSpanner
-}
-
-// need refactor later
-func (this *StockSpanner) Next(price int) int {
- res := 1
- if len(this.Item) == 0 {
- this.Item = append(this.Item, Node{price, res})
- return res
- }
- for len(this.Item) > 0 && this.Item[len(this.Item)-1].Val <= price {
- res = res + this.Item[len(this.Item)-1].res
- this.Item = this.Item[:len(this.Item)-1]
- }
- this.Item = append(this.Item, Node{price, res})
- fmt.Printf("this.Item = %v\n", this.Item)
- return res
-}
-
-/**
- * Your StockSpanner object will be instantiated and called as such:
- * obj := Constructor();
- * param_1 := obj.Next(price);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0904.Fruit-Into-Baskets.md b/website/content/ChapterFour/0904.Fruit-Into-Baskets.md
deleted file mode 100644
index c3786ae76..000000000
--- a/website/content/ChapterFour/0904.Fruit-Into-Baskets.md
+++ /dev/null
@@ -1,115 +0,0 @@
-# [904. Fruit Into Baskets](https://leetcode.com/problems/fruit-into-baskets/)
-
-## 题目
-
-In a row of trees, the i-th tree produces fruit with type tree[i].
-
-You start at any tree of your choice, then repeatedly perform the following steps:
-
-1. Add one piece of fruit from this tree to your baskets. If you cannot, stop.
-2. Move to the next tree to the right of the current tree. If there is no tree to the right, stop.
-
-Note that you do not have any choice after the initial choice of starting tree: you must perform step 1, then step 2, then back to step 1, then step 2, and so on until you stop.
-
-You have two baskets, and each basket can carry any quantity of fruit, but you want each basket to only carry one type of fruit each.
-
-What is the total amount of fruit you can collect with this procedure?
-
-
-**Example 1**:
-
-```
-Input: [1,2,1]
-Output: 3
-Explanation: We can collect [1,2,1].
-
-```
-
-**Example 2**:
-
-```
-
-Input: [0,1,2,2]
-Output: 3
-Explanation: We can collect [1,2,2].
-If we started at the first tree, we would only collect [0, 1].
-
-```
-
-**Example 3**:
-
-```
-
-Input: [1,2,3,2,2]
-Output: 4
-Explanation: We can collect [2,3,2,2].
-If we started at the first tree, we would only collect [1, 2].
-
-```
-
-**Example 4**:
-
-```
-
-Input: [3,3,3,1,2,1,1,2,3,3,4]
-Output: 5
-Explanation: We can collect [1,2,1,1,2].
-If we started at the first tree or the eighth tree, we would only collect 4 fruits.
-
-```
-
-**Note**:
-
-- 1 <= tree.length <= 40000
-- 0 <= tree[i] < tree.length
-
-## 题目大意
-
-这道题考察的是滑动窗口的问题。
-
-给出一个数组,数组里面的数字代表每个果树上水果的种类,1 代表一号水果,不同数字代表的水果不同。现在有 2 个篮子,每个篮子只能装一个种类的水果,这就意味着只能选 2 个不同的数字。摘水果只能从左往右摘,直到右边没有水果可以摘就停下。问可以连续摘水果的最长区间段的长度。
-
-
-## 解题思路
-
-简化一下题意,给出一段数字,要求找出包含 2 个不同数字的最大区间段长度。这个区间段内只能包含这 2 个不同数字,可以重复,但是不能包含其他数字。
-
-用典型的滑动窗口的处理方法处理即可。
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func totalFruit(tree []int) int {
- if len(tree) == 0 {
- return 0
- }
- left, right, counter, res, freq := 0, 0, 1, 1, map[int]int{}
- freq[tree[0]]++
- for left < len(tree) {
- if right+1 < len(tree) && ((counter > 0 && tree[right+1] != tree[left]) || (tree[right+1] == tree[left] || freq[tree[right+1]] > 0)) {
- if counter > 0 && tree[right+1] != tree[left] {
- counter--
- }
- right++
- freq[tree[right]]++
- } else {
- if counter == 0 || (counter > 0 && right == len(tree)-1) {
- res = max(res, right-left+1)
- }
- freq[tree[left]]--
- if freq[tree[left]] == 0 {
- counter++
- }
- left++
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0907.Sum-of-Subarray-Minimums.md b/website/content/ChapterFour/0907.Sum-of-Subarray-Minimums.md
deleted file mode 100644
index 7c5374d43..000000000
--- a/website/content/ChapterFour/0907.Sum-of-Subarray-Minimums.md
+++ /dev/null
@@ -1,124 +0,0 @@
-# [907. Sum of Subarray Minimums](https://leetcode.com/problems/sum-of-subarray-minimums/)
-
-## 题目
-
-Given an array of integers A, find the sum of min(B), where B ranges over every (contiguous) subarray of A.
-
-Since the answer may be large, return the answer modulo 10^9 + 7.
-
-
-
-**Example 1**:
-
-```
-
-Input: [3,1,2,4]
-Output: 17
-Explanation: Subarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4].
-Minimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1. Sum is 17.
-
-```
-
-**Note**:
-
-1. 1 <= A.length <= 30000
-2. 1 <= A[i] <= 30000
-
-
-## 题目大意
-
-给定一个整数数组 A,找到 min(B) 的总和,其中 B 的范围为 A 的每个(连续)子数组。
-
-由于答案可能很大,因此返回答案模 10^9 + 7。
-
-
-## 解题思路
-
-- 首先想到的是暴力解法,用两层循环,分别枚举每个连续的子区间,区间内用一个元素记录区间内最小值。每当区间起点发生变化的时候,最终结果都加上上次遍历区间找出的最小值。当整个数组都扫完一遍以后,最终结果模上 10^9+7。
-- 上面暴力解法时间复杂度特别大,因为某个区间的最小值可能是很多区间的最小值,但是我们暴力枚举所有区间,导致要遍历的区间特别多。优化点就在如何减少遍历的区间。第二种思路是用 2 个单调栈。想得到思路是 `res = sum(A[i] * f(i))`,其中 f(i) 是子区间的数,A[i] 是这个子区间内的最小值。为了得到 f(i) 我们需要找到 left[i] 和 right[i],left[i] 是 A[i] 左边严格大于 A[i](> 关系)的区间长度。right[i] 是 A[i] 右边非严格大于(>= 关系)的区间长度。left[i] + 1 等于以 A[i] 结尾的子数组数目,A[i] 是唯一的最小值;right[i] + 1 等于以 A[i] 开始的子数组数目,A[i] 是第一个最小值。于是有 `f(i) = (left[i] + 1) * (right[i] + 1)`。例如对于 [3,1,4,2,5,3,3,1] 中的“2”,我们找到的串就为[4,2,5,3,3],2 左边有 1 个数比 2 大且相邻,2 右边有 3 个数比 2 大且相邻,所以 2 作为最小值的串有 2 * 4 = 8 种。用排列组合的思维也能分析出来,2 的左边可以拿 0,1,…… m 个,总共 (m + 1) 种,同理右边可以拿 0,1,…… n 个,总共 (n + 1) 种,所以总共 (m + 1)(n + 1)种。只要计算出了 f(i),这个题目就好办了。以 [3,1,2,4] 为例,left[i] + 1 = [1,2,1,1],right[i] + 1 = [1,3,2,1],对应 i 位的乘积是 f[i] = [1 * 1,2 * 3,1 * 2,1 * 1] = [1,6,2,1],最终要求的最小值的总和 res = 3 * 1 + 1 * 6 + 2 * 2 + 4 * 1 = 17。
-- **看到这种 mod1e9+7 的题目,首先要想到的就是dp**。最终的优化解即是利用 DP + 单调栈。单调栈维护数组中的值逐渐递增的对应下标序列。定义 `dp[i + 1]` 代表以 A[i] 结尾的子区间内最小值的总和。状态转移方程是 `dp[i + 1] = dp[prev + 1] + (i - prev) * A[i]`,其中 prev 是比 A[i] 小的前一个数,由于我们维护了一个单调栈,所以 prev 就是栈顶元素。(i - prev) * A[i] 代表在还没有出现 prev 之前,这些区间内都是 A[i] 最小,那么这些区间有 i - prev 个,所以最小值总和应该是 (i - prev) * A[i]。再加上 dp[prev + 1] 就是 dp[i + 1] 的最小值总和了。以 [3, 1, 2, 4, 3] 为例,当 i = 4, 所有以 A[4] 为结尾的子区间有:
-
- [3]
- [4, 3]
- [2, 4, 3]
- [1, 2, 4, 3]
- [3, 1, 2, 4, 3]
- 在这种情况下, stack.peek() = 2, A[2] = 2。前两个子区间 [3] and [4, 3], 最小值的总和 = (i - stack.peek()) * A[i] = 6。后 3 个子区间是 [2, 4, 3], [1, 2, 4, 3] 和 [3, 1, 2, 4, 3], 它们都包含 2,2 是比 3 小的前一个数,所以 dp[i + 1] = dp[stack.peek() + 1] = dp[2 + 1] = dp[3] = dp[2 + 1]。即需要求 i = 2 的时候 dp[i + 1] 的值。继续递推,比 2 小的前一个值是 1,A[1] = 1。dp[3] = dp[1 + 1] + (2 - 1) * A[2]= dp[2] + 2。dp[2] = dp[1 + 1],当 i = 1 的时候,prev = -1,即没有人比 A[1] 更小了,所以 dp[2] = dp[1 + 1] = dp[-1 + 1] + (1 - (-1)) * A[1] = 0 + 2 * 1 = 2。迭代回去,dp[3] = dp[2] + 2 = 2 + 2 = 4。dp[stack.peek() + 1] = dp[2 + 1] = dp[3] = 4。所以 dp[i + 1] = 4 + 6 = 10。
-- 与这一题相似的解题思路的题目有第 828 题,第 891 题。
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 最快的解是 DP + 单调栈
-func sumSubarrayMins(A []int) int {
- stack, dp, res, mod := []int{}, make([]int, len(A)+1), 0, 1000000007
- stack = append(stack, -1)
-
- for i := 0; i < len(A); i++ {
- for stack[len(stack)-1] != -1 && A[i] <= A[stack[len(stack)-1]] {
- stack = stack[:len(stack)-1]
- }
- dp[i+1] = (dp[stack[len(stack)-1]+1] + (i-stack[len(stack)-1])*A[i]) % mod
- stack = append(stack, i)
- res += dp[i+1]
- res %= mod
- }
- return res
-}
-
-type pair struct {
- val int
- count int
-}
-
-// 解法二 用两个单调栈
-func sumSubarrayMins1(A []int) int {
- res, n, mod := 0, len(A), 1000000007
- lefts, rights, leftStack, rightStack := make([]int, n), make([]int, n), []*pair{}, []*pair{}
- for i := 0; i < n; i++ {
- count := 1
- for len(leftStack) != 0 && leftStack[len(leftStack)-1].val > A[i] {
- count += leftStack[len(leftStack)-1].count
- leftStack = leftStack[:len(leftStack)-1]
- }
- leftStack = append(leftStack, &pair{val: A[i], count: count})
- lefts[i] = count
- }
-
- for i := n - 1; i >= 0; i-- {
- count := 1
- for len(rightStack) != 0 && rightStack[len(rightStack)-1].val >= A[i] {
- count += rightStack[len(rightStack)-1].count
- rightStack = rightStack[:len(rightStack)-1]
- }
- rightStack = append(rightStack, &pair{val: A[i], count: count})
- rights[i] = count
- }
-
- for i := 0; i < n; i++ {
- res = (res + A[i]*lefts[i]*rights[i]) % mod
- }
- return res
-}
-
-// 解法三 暴力解法,中间很多重复判断子数组的情况
-func sumSubarrayMins2(A []int) int {
- res, mod := 0, 1000000007
- for i := 0; i < len(A); i++ {
- stack := []int{}
- stack = append(stack, A[i])
- for j := i; j < len(A); j++ {
- if stack[len(stack)-1] >= A[j] {
- stack = stack[:len(stack)-1]
- stack = append(stack, A[j])
- }
- res += stack[len(stack)-1]
- }
- }
- return res % mod
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0911.Online-Election.md b/website/content/ChapterFour/0911.Online-Election.md
deleted file mode 100755
index 63a73bb66..000000000
--- a/website/content/ChapterFour/0911.Online-Election.md
+++ /dev/null
@@ -1,99 +0,0 @@
-# [911. Online Election](https://leetcode.com/problems/online-election/)
-
-
-## 题目
-
-In an election, the `i`-th vote was cast for `persons[i]` at time `times[i]`.
-
-Now, we would like to implement the following query function: `TopVotedCandidate.q(int t)` will return the number of the person that was leading the election at time `t`.
-
-Votes cast at time `t` will count towards our query. In the case of a tie, the most recent vote (among tied candidates) wins.
-
-**Example 1**:
-
- Input: ["TopVotedCandidate","q","q","q","q","q","q"], [[[0,1,1,0,0,1,0],[0,5,10,15,20,25,30]],[3],[12],[25],[15],[24],[8]]
- Output: [null,0,1,1,0,0,1]
- Explanation:
- At time 3, the votes are [0], and 0 is leading.
- At time 12, the votes are [0,1,1], and 1 is leading.
- At time 25, the votes are [0,1,1,0,0,1], and 1 is leading (as ties go to the most recent vote.)
- This continues for 3 more queries at time 15, 24, and 8.
-
-**Note**:
-
-1. `1 <= persons.length = times.length <= 5000`
-2. `0 <= persons[i] <= persons.length`
-3. `times` is a strictly increasing array with all elements in `[0, 10^9]`.
-4. `TopVotedCandidate.q` is called at most `10000` times per test case.
-5. `TopVotedCandidate.q(int t)` is always called with `t >= times[0]`.
-
-
-## 题目大意
-
-在选举中,第 i 张票是在时间为 times[i] 时投给 persons[i] 的。
-
-现在,我们想要实现下面的查询函数: TopVotedCandidate.q(int t) 将返回在 t 时刻主导选举的候选人的编号。
-
-在 t 时刻投出的选票也将被计入我们的查询之中。在平局的情况下,最近获得投票的候选人将会获胜。
-
-提示:
-
-1. 1 <= persons.length = times.length <= 5000
-2. 0 <= persons[i] <= persons.length
-3. times 是严格递增的数组,所有元素都在 [0, 10^9] 范围中。
-4. 每个测试用例最多调用 10000 次 TopVotedCandidate.q。
-5. TopVotedCandidate.q(int t) 被调用时总是满足 t >= times[0]。
-
-
-
-
-## 解题思路
-
-- 给出一个 2 个数组,分别代表第 `i` 人在第 `t` 时刻获得的票数。需要实现一个查询功能的函数,查询在任意 `t` 时刻,输出谁的选票领先。
-- `persons[]` 数组里面装的是获得选票人的编号,`times[]` 数组里面对应的是每个选票的时刻。`times[]` 数组默认是有序的,从小到大排列。先计算出每个时刻哪个人选票领先,放在一个数组中,实现查询函数的时候,只需要先对 `times[]` 数组二分搜索,找到比查询时间 `t` 小的最大时刻 `i`,再在选票领先的数组里面输出对应时刻领先的人的编号即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-// TopVotedCandidate define
-type TopVotedCandidate struct {
- persons []int
- times []int
-}
-
-// Constructor911 define
-func Constructor911(persons []int, times []int) TopVotedCandidate {
- leaders, votes := make([]int, len(persons)), make([]int, len(persons))
- leader := persons[0]
- for i := 0; i < len(persons); i++ {
- p := persons[i]
- votes[p]++
- if votes[p] >= votes[leader] {
- leader = p
- }
- leaders[i] = leader
- }
- return TopVotedCandidate{persons: leaders, times: times}
-}
-
-// Q define
-func (tvc *TopVotedCandidate) Q(t int) int {
- i := sort.Search(len(tvc.times), func(p int) bool { return tvc.times[p] > t })
- return tvc.persons[i-1]
-}
-
-/**
- * Your TopVotedCandidate object will be instantiated and called as such:
- * obj := Constructor(persons, times);
- * param_1 := obj.Q(t);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md b/website/content/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md
deleted file mode 100644
index 02c8ebddd..000000000
--- a/website/content/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md
+++ /dev/null
@@ -1,105 +0,0 @@
-# [914. X of a Kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/)
-
-
-## 题目
-
-In a deck of cards, each card has an integer written on it.
-
-Return `true` if and only if you can choose `X >= 2` such that it is possible to split the entire deck into 1 or more groups of cards, where:
-
-- Each group has exactly `X` cards.
-- All the cards in each group have the same integer.
-
-**Example 1**:
-
-```
-Input: deck = [1,2,3,4,4,3,2,1]
-Output: true
-Explanation: Possible partition [1,1],[2,2],[3,3],[4,4].
-```
-
-**Example 2**:
-
-```
-Input: deck = [1,1,1,2,2,2,3,3]
-Output: false´
-Explanation: No possible partition.
-```
-
-**Example 3**:
-
-```
-Input: deck = [1]
-Output: false
-Explanation: No possible partition.
-```
-
-**Example 4**:
-
-```
-Input: deck = [1,1]
-Output: true
-Explanation: Possible partition [1,1].
-```
-
-**Example 5**:
-
-```
-Input: deck = [1,1,2,2,2,2]
-Output: true
-Explanation: Possible partition [1,1],[2,2],[2,2].
-```
-
-**Constraints**:
-
-- `1 <= deck.length <= 10^4`
-- `0 <= deck[i] < 10^4`
-
-## 题目大意
-
-给定一副牌,每张牌上都写着一个整数。此时,你需要选定一个数字 X,使我们可以将整副牌按下述规则分成 1 组或更多组:
-
-- 每组都有 X 张牌。
-- 组内所有的牌上都写着相同的整数。
-
-仅当你可选的 X >= 2 时返回 true。
-
-
-## 解题思路
-
-- 给定一副牌,要求选出数字 X,使得每组都有 X 张牌,每组牌的数字都相同。当 X ≥ 2 的时候,输出 true。
-- 通过分析题目,我们可以知道,只有当 X 为所有 count 的约数,即所有 count 的最大公约数的约数时,才存在可能的分组。因此我们只要求出所有 count 的最大公约数 g,判断 g 是否大于等于 2 即可,如果大于等于 2,则满足条件,否则不满足。
-- 时间复杂度:O(NlogC),其中 N 是卡牌的个数,C 是数组 deck 中数的范围,在本题中 C 的值为 10000。求两个数最大公约数的复杂度是 O(logC),需要求最多 N - 1 次。空间复杂度:O(N + C) 或 O(N)。
-
-## 代码
-
-```go
-
-package leetcode
-
-func hasGroupsSizeX(deck []int) bool {
- if len(deck) < 2 {
- return false
- }
- m, g := map[int]int{}, -1
- for _, d := range deck {
- m[d]++
- }
- for _, v := range m {
- if g == -1 {
- g = v
- } else {
- g = gcd(g, v)
- }
- }
- return g >= 2
-}
-
-func gcd(a, b int) int {
- if a == 0 {
- return b
- }
- return gcd(b%a, a)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0918.Maximum-Sum-Circular-Subarray.md b/website/content/ChapterFour/0918.Maximum-Sum-Circular-Subarray.md
deleted file mode 100755
index 1b60e16e3..000000000
--- a/website/content/ChapterFour/0918.Maximum-Sum-Circular-Subarray.md
+++ /dev/null
@@ -1,101 +0,0 @@
-# [918. Maximum Sum Circular Subarray](https://leetcode.com/problems/maximum-sum-circular-subarray/)
-
-
-## 题目
-
-Given a **circular array** **C** of integers represented by `A`, find the maximum possible sum of a non-empty subarray of **C**.
-
-Here, a *circular array* means the end of the array connects to the beginning of the array. (Formally, `C[i] = A[i]` when `0 <= i < A.length`, and `C[i+A.length] = C[i]` when `i >= 0`.)
-
-Also, a subarray may only include each element of the fixed buffer `A` at most once. (Formally, for a subarray `C[i], C[i+1], ..., C[j]`, there does not exist `i <= k1, k2 <= j` with `k1 % A.length = k2 % A.length`.)
-
-**Example 1**:
-
- Input: [1,-2,3,-2]
- Output: 3
- Explanation: Subarray [3] has maximum sum 3
-
-**Example 2**:
-
- Input: [5,-3,5]
- Output: 10
- Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10
-
-**Example 3**:
-
- Input: [3,-1,2,-1]
- Output: 4
- Explanation: Subarray [2,-1,3] has maximum sum 2 + (-1) + 3 = 4
-
-**Example 4**:
-
- Input: [3,-2,2,-3]
- Output: 3
- Explanation: Subarray [3] and [3,-2,2] both have maximum sum 3
-
-**Example 5**:
-
- Input: [-2,-3,-1]
- Output: -1
- Explanation: Subarray [-1] has maximum sum -1
-
-**Note**:
-
-1. `-30000 <= A[i] <= 30000`
-2. `1 <= A.length <= 30000`
-
-
-## 题目大意
-
-给定一个由整数数组 A 表示的环形数组 C,求 C 的非空子数组的最大可能和。在此处,环形数组意味着数组的末端将会与开头相连呈环状。(形式上,当0 <= i < A.length 时 C[i] = A[i],而当 i >= 0 时 C[i+A.length] = C[i])
-
-此外,子数组最多只能包含固定缓冲区 A 中的每个元素一次。(形式上,对于子数组 C[i], C[i+1], ..., C[j],不存在 i <= k1, k2 <= j 其中 k1 % A.length = k2 % A.length)
-
-提示:
-
-- -30000 <= A[i] <= 30000
-- 1 <= A.length <= 30000
-
-
-## 解题思路
-
-
-- 给出一个环形数组,要求出这个环形数组中的连续子数组的最大和。
-- 拿到这题最先想到的思路是把这个数组再拼接一个,在这两个数组中查找连续子数组的最大和。这种做法是错误的,例如在 `[5,-3,5]` 这个数组中会得出 `7` 的结果,但是实际结果是 `10` 。那么这题怎么做呢?仔细分析可以得到,环形数组的最大连续子段和有两种情况,第一种情况是这个连续子段就出现在数组中, 不存在循环衔接的情况。针对这种情况就比较简单,用 `kadane` 算法(也是动态规划的思想),`O(n)` 的时间复杂度就可以求出结果。第二种情况是这个连续的子段出现在跨数组的情况,即会出现首尾相连的情况。要想找到这样一个连续子段,可以反向考虑。想找到跨段的连续子段,那么这个数组剩下的这一段就是不跨段的连续子段。想要跨段的子段和最大,那么剩下的这段连续子段和最小。如果能找到这个数组的每个元素取相反数组成的数组中的最大连续子段和,那么反过来就能找到原数组的连续子段和最小。举个例子:`[1,2,-3,-4,5]` ,取它的每个元素的相反数 `[-1,-2,3,4,-5]`,构造的数组中最大连续子段和是 `3 + 4 = 7`,由于取了相反数,所以可以得到原数组中最小连续子段和是 `-7` 。所以跨段的最大连续子段和就是剩下的那段 `[1,2,5]`。
-- 还有一些边界的情况,例如,`[1,2,-2,-3,5,5,-4,6]` 和 `[1,2,-2,-3,5,5,-4,8]`,所以还需要比较一下情况一和情况二的值,它们两者最大值才是最终环形数组的连续子数组的最大和。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math"
-
-func maxSubarraySumCircular(A []int) int {
- n, sum := len(A), 0
- for _, v := range A {
- sum += v
- }
- kad := kadane(A)
- for i := 0; i < n; i++ {
- A[i] = -A[i]
- }
- negativeMax := kadane(A)
- if sum+negativeMax <= 0 {
- return kad
- }
- return max(kad, sum+negativeMax)
-}
-
-func kadane(a []int) int {
- n, MaxEndingHere, maxSoFar := len(a), a[0], math.MinInt32
- for i := 1; i < n; i++ {
- MaxEndingHere = max(a[i], MaxEndingHere+a[i])
- maxSoFar = max(MaxEndingHere, maxSoFar)
- }
- return maxSoFar
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0920.Number-of-Music-Playlists.md b/website/content/ChapterFour/0920.Number-of-Music-Playlists.md
deleted file mode 100755
index b0efa478d..000000000
--- a/website/content/ChapterFour/0920.Number-of-Music-Playlists.md
+++ /dev/null
@@ -1,85 +0,0 @@
-# [920. Number of Music Playlists](https://leetcode.com/problems/number-of-music-playlists/)
-
-
-## 题目
-
-Your music player contains `N` different songs and she wants to listen to `L` ****(not necessarily different) songs during your trip. You create a playlist so that:
-
-- Every song is played at least once
-- A song can only be played again only if `K` other songs have been played
-
-Return the number of possible playlists. **As the answer can be very large, return it modulo `10^9 + 7`**.
-
-**Example 1**:
-
- Input: N = 3, L = 3, K = 1
- Output: 6
- Explanation: There are 6 possible playlists. [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1].
-
-**Example 2**:
-
- Input: N = 2, L = 3, K = 0
- Output: 6
- Explanation: There are 6 possible playlists. [1, 1, 2], [1, 2, 1], [2, 1, 1], [2, 2, 1], [2, 1, 2], [1, 2, 2]
-
-**Example 3**:
-
- Input: N = 2, L = 3, K = 1
- Output: 2
- Explanation: There are 2 possible playlists. [1, 2, 1], [2, 1, 2]
-
-**Note**:
-
-1. `0 <= K < N <= L <= 100`
-
-## 题目大意
-
-你的音乐播放器里有 N 首不同的歌,在旅途中,你的旅伴想要听 L 首歌(不一定不同,即,允许歌曲重复)。请你为她按如下规则创建一个播放列表:
-
-- 每首歌至少播放一次。
-- 一首歌只有在其他 K 首歌播放完之后才能再次播放。
-
-返回可以满足要求的播放列表的数量。由于答案可能非常大,请返回它模 10^9 + 7 的结果。
-
-提示:
-
-- 0 <= K < N <= L <= 100
-
-
-
-
-## 解题思路
-
-- 简化抽象一下题意,给 N 个数,要求从这 N 个数里面组成一个长度为 L 的序列,并且相同元素的间隔不能小于 K 个数。问总共有多少组组成方法。
-- 一拿到题,会觉得这一题是三维 DP,因为存在 3 个变量,但是实际考虑一下,可以降一维。我们先不考虑 K 的限制,只考虑 N 和 L。定义 `dp[i][j]` 代表播放列表里面有 `i` 首歌,其中包含 `j` 首不同的歌曲,那么题目要求的最终解存在 `dp[L][N]` 中。考虑 `dp[i][j]` 的递归公式,音乐列表当前需要组成 `i` 首歌,有 2 种方式可以得到,由 `i - 1` 首歌的列表中添加一首列表中**不存在**的新歌曲,或者由 `i - 1` 首歌的列表中添加一首列表中**已经存在**的歌曲。即,`dp[i][j]` 可以由 `dp[i - 1][j - 1]` 得到,也可以由 `dp[i - 1][j]` 得到。如果是第一种情况,添加一首新歌,那么新歌有 N - ( j - 1 ) 首,如果是第二种情况,添加一首已经存在的歌,歌有 j 首,所以状态转移方程是 `dp[i][j] = dp[i - 1][j - 1] * ( N - ( j - 1 ) ) + dp[i - 1][j] * j` 。但是这个方程是在不考虑 K 的限制条件下得到的,距离满足题意还差一步。接下来需要考虑加入 K 这个限制条件以后,状态转移方程该如何推导。
-- 如果是添加一首新歌,是不受 K 限制的,所以 `dp[i - 1][j - 1] * ( N - ( j - 1 ) )` 这里不需要变化。如果是添加一首存在的歌曲,这个时候就会受到 K 的限制了。如果当前播放列表里面的歌曲有 `j` 首,并且 `j > K`,那么选择歌曲只能从 `j - K` 里面选,因为不能选择 `j - 1` 到 `j - k` 的这些歌,选择了就不满足重复的歌之间间隔不能小于 `K` 的限制条件了。那 j ≤ K 呢?这个时候一首歌都不能选,因为歌曲数都没有超过 K,当然不能再选择重复的歌曲。(选择了就再次不满足重复的歌之间间隔不能小于 `K` 的限制条件了)。经过上述分析,可以得到最终的状态转移方程:
-
-
-
-- 上面的式子可以合并简化成下面这个式子:`dp[i][j] = dp[i - 1][j - 1]*(N - (j - 1)) + dp[i-1][j]*max(j-K, 0)`,递归初始值 `dp[0][0] = 1`。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func numMusicPlaylists(N int, L int, K int) int {
- dp, mod := make([][]int, L+1), 1000000007
- for i := 0; i < L+1; i++ {
- dp[i] = make([]int, N+1)
- }
- dp[0][0] = 1
- for i := 1; i <= L; i++ {
- for j := 1; j <= N; j++ {
- dp[i][j] = (dp[i-1][j-1] * (N - (j - 1))) % mod
- if j > K {
- dp[i][j] = (dp[i][j] + (dp[i-1][j]*(j-K))%mod) % mod
- }
- }
- }
- return dp[L][N]
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md b/website/content/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md
deleted file mode 100644
index 8952fe952..000000000
--- a/website/content/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md
+++ /dev/null
@@ -1,88 +0,0 @@
-# [921. Minimum Add to Make Parentheses Valid](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/)
-
-## 题目
-
-Given a string S of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', and in any positions ) so that the resulting parentheses string is valid.
-
-Formally, a parentheses string is valid if and only if:
-
-- It is the empty string, or
-- It can be written as AB (A concatenated with B), where A and B are valid strings, or
-- It can be written as (A), where A is a valid string.
-Given a parentheses string, return the minimum number of parentheses we must add to make the resulting string valid.
-
-
-
-**Example 1**:
-
-```
-
-Input: "())"
-Output: 1
-
-```
-
-**Example 2**:
-
-```
-
-Input: "((("
-Output: 3
-
-```
-
-**Example 3**:
-
-```
-
-Input: "()"
-Output: 0
-
-```
-
-**Example 4**:
-
-```
-
-Input: "()))(("
-Output: 4
-
-```
-
-**Note**:
-
-1. S.length <= 1000
-2. S only consists of '(' and ')' characters.
-
-## 题目大意
-
-给一个括号的字符串,如果能在这个括号字符串中的任意位置添加括号,问能使得这串字符串都能完美匹配的最少添加数是多少。
-
-## 解题思路
-
-这题也是栈的题目,利用栈进行括号匹配。最后栈里剩下几个括号,就是最少需要添加的数目。
-
-## 代码
-
-```go
-
-package leetcode
-
-func minAddToMakeValid(S string) int {
- if len(S) == 0 {
- return 0
- }
- stack := make([]rune, 0)
- for _, v := range S {
- if v == '(' {
- stack = append(stack, v)
- } else if (v == ')') && len(stack) > 0 && stack[len(stack)-1] == '(' {
- stack = stack[:len(stack)-1]
- } else {
- stack = append(stack, v)
- }
- }
- return len(stack)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0922.Sort-Array-By-Parity-II.md b/website/content/ChapterFour/0922.Sort-Array-By-Parity-II.md
deleted file mode 100644
index ca915fd94..000000000
--- a/website/content/ChapterFour/0922.Sort-Array-By-Parity-II.md
+++ /dev/null
@@ -1,61 +0,0 @@
-# [922. Sort Array By Parity II](https://leetcode.com/problems/sort-array-by-parity-ii/)
-
-## 题目
-
-Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even.
-
-Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even.
-
-You may return any answer array that satisfies this condition.
-
-
-**Example 1**:
-
-```
-
-Input: [4,2,5,7]
-Output: [4,5,2,7]
-Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.
-
-```
-
-**Note**:
-
-- 2 <= A.length <= 20000
-- A.length % 2 == 0
-- 0 <= A[i] <= 1000
-
-## 题目大意
-
-要求数组中奇数下标位置上放奇数,偶数下标位置上放偶数。
-
-## 解题思路
-
-这题比较简单,用两个下标控制奇数,偶数放置在哪个下标即可。奇数奇数之间,偶数偶数之间的顺序可以是无序的。
-
-## 代码
-
-```go
-
-package leetcode
-
-func sortArrayByParityII(A []int) []int {
- if len(A) == 0 || len(A)%2 != 0 {
- return []int{}
- }
- res := make([]int, len(A))
- oddIndex := 1
- evenIndex := 0
- for i := 0; i < len(A); i++ {
- if A[i]%2 == 0 {
- res[evenIndex] = A[i]
- evenIndex += 2
- } else {
- res[oddIndex] = A[i]
- oddIndex += 2
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0923.3Sum-With-Multiplicity.md b/website/content/ChapterFour/0923.3Sum-With-Multiplicity.md
deleted file mode 100644
index 0673f0de4..000000000
--- a/website/content/ChapterFour/0923.3Sum-With-Multiplicity.md
+++ /dev/null
@@ -1,102 +0,0 @@
-# [923. 3Sum With Multiplicity](https://leetcode.com/problems/3sum-with-multiplicity/)
-
-## 题目
-
-Given an integer array A, and an integer target, return the number of tuples i, j, k such that i < j < k and A[i] + A[j] + A[k] == target.
-
-As the answer can be very large, return it modulo 10^9 + 7.
-
-
-**Example 1**:
-
-```
-
-Input: A = [1,1,2,2,3,3,4,4,5,5], target = 8
-Output: 20
-Explanation:
-Enumerating by the values (A[i], A[j], A[k]):
-(1, 2, 5) occurs 8 times;
-(1, 3, 4) occurs 8 times;
-(2, 2, 4) occurs 2 times;
-(2, 3, 3) occurs 2 times.
-
-```
-
-
-**Example 2**:
-
-```
-
-Input: A = [1,1,2,2,2,2], target = 5
-Output: 12
-Explanation:
-A[i] = 1, A[j] = A[k] = 2 occurs 12 times:
-We choose one 1 from [1,1] in 2 ways,
-and two 2s from [2,2,2,2] in 6 ways.
-
-```
-
-
-**Note**:
-
-- 3 <= A.length <= 3000
-- 0 <= A[i] <= 100
-- 0 <= target <= 300
-
-
-## 题目大意
-
-这道题是第 15 题的升级版。给出一个数组,要求找到 3 个数相加的和等于 target 的解组合的个数,并且要求 i < j < k。解的组合个数不需要去重,相同数值不同下标算不同解(这里也是和第 15 题的区别)
-
-## 解题思路
-
-这一题大体解法和第 15 题一样的,只不过算所有解组合的时候需要一点排列组合的知识,如果取 3 个一样的数,需要计算 C n 3,去 2 个相同的数字的时候,计算 C n 2,取一个数字就正常计算。最后所有解的个数都加起来就可以了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-func threeSumMulti(A []int, target int) int {
- mod := 1000000007
- counter := map[int]int{}
- for _, value := range A {
- counter[value]++
- }
-
- uniqNums := []int{}
- for key := range counter {
- uniqNums = append(uniqNums, key)
- }
- sort.Ints(uniqNums)
-
- res := 0
- for i := 0; i < len(uniqNums); i++ {
- ni := counter[uniqNums[i]]
- if (uniqNums[i]*3 == target) && counter[uniqNums[i]] >= 3 {
- res += ni * (ni - 1) * (ni - 2) / 6
- }
- for j := i + 1; j < len(uniqNums); j++ {
- nj := counter[uniqNums[j]]
- if (uniqNums[i]*2+uniqNums[j] == target) && counter[uniqNums[i]] > 1 {
- res += ni * (ni - 1) / 2 * nj
- }
- if (uniqNums[j]*2+uniqNums[i] == target) && counter[uniqNums[j]] > 1 {
- res += nj * (nj - 1) / 2 * ni
- }
- c := target - uniqNums[i] - uniqNums[j]
- if c > uniqNums[j] && counter[c] > 0 {
- res += ni * nj * counter[c]
- }
- }
- }
- return res % mod
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0924.Minimize-Malware-Spread.md b/website/content/ChapterFour/0924.Minimize-Malware-Spread.md
deleted file mode 100755
index ce5c89702..000000000
--- a/website/content/ChapterFour/0924.Minimize-Malware-Spread.md
+++ /dev/null
@@ -1,105 +0,0 @@
-# [924. Minimize Malware Spread](https://leetcode.com/problems/minimize-malware-spread/)
-
-
-## 题目
-
-In a network of nodes, each node `i` is directly connected to another node `j` if and only if `graph[i][j] = 1`.
-
-Some nodes `initial` are initially infected by malware. Whenever two nodes are directly connected and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.
-
-Suppose `M(initial)` is the final number of nodes infected with malware in the entire network, after the spread of malware stops.
-
-We will remove one node from the initial list. Return the node that if removed, would minimize `M(initial)`. If multiple nodes could be removed to minimize `M(initial)`, return such a node with the smallest index.
-
-Note that if a node was removed from the `initial` list of infected nodes, it may still be infected later as a result of the malware spread.
-
-**Example 1**:
-
- Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]
- Output: 0
-
-**Example 2**:
-
- Input: graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]
- Output: 0
-
-**Example 3**:
-
- Input: graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]
- Output: 1
-
-**Note**:
-
-1. `1 < graph.length = graph[0].length <= 300`
-2. `0 <= graph[i][j] == graph[j][i] <= 1`
-3. `graph[i][i] = 1`
-4. `1 <= initial.length < graph.length`
-5. `0 <= initial[i] < graph.length`
-
-
-## 题目大意
-
-在节点网络中,只有当 graph[i][j] = 1 时,每个节点 i 能够直接连接到另一个节点 j。一些节点 initial 最初被恶意软件感染。只要两个节点直接连接,且其中至少一个节点受到恶意软件的感染,那么两个节点都将被恶意软件感染。这种恶意软件的传播将继续,直到没有更多的节点可以被这种方式感染。假设 M(initial) 是在恶意软件停止传播之后,整个网络中感染恶意软件的最终节点数。我们可以从初始列表中删除一个节点。如果移除这一节点将最小化 M(initial), 则返回该节点。如果有多个节点满足条件,就返回索引最小的节点。请注意,如果某个节点已从受感染节点的列表 initial 中删除,它以后可能仍然因恶意软件传播而受到感染。
-
-
-提示:
-
-- 1 < graph.length = graph[0].length <= 300
-- 0 <= graph[i][j] == graph[j][i] <= 1
-- graph[i][i] = 1
-- 1 <= initial.length < graph.length
-- 0 <= initial[i] < graph.length
-
-
-## 解题思路
-
-
-- 给出一个节点之间的关系图,如果两个节点是连通的,那么病毒软件就会感染到连通的所有节点。现在如果想移除一个病毒节点,能最大减少感染,请问移除哪个节点?如果多个节点都能减少感染量,优先移除序号偏小的那个节点。
-- 这一题一看就是考察的并查集。利用节点的连通关系,把题目中给的所有节点都 `union()` 起来,然后依次统计每个集合内有多少个点。最后扫描一次 initial 数组,选出这个数组中节点小的并且所在集合节点多,这个节点就是最终答案。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
-
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func minMalwareSpread(graph [][]int, initial []int) int {
- if len(initial) == 0 {
- return 0
- }
- uf, minIndex, count, countMap := template.UnionFind{}, 0, math.MinInt64, map[int]int{}
- uf.Init(len(graph))
- for i := range graph {
- for j := range graph[i] {
- if i == j {
- break
- }
- if graph[i][j] == 1 {
- uf.Union(i, j)
- }
- }
- }
- for i := 0; i < len(graph); i++ {
- countMap[uf.Find(i)]++
- }
- for _, v := range initial {
- tmp := countMap[uf.Find(v)]
- if count == tmp && minIndex > v {
- minIndex = v
- }
- if count < tmp {
- minIndex = v
- count = tmp
- }
- }
- return minIndex
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0927.Three-Equal-Parts.md b/website/content/ChapterFour/0927.Three-Equal-Parts.md
deleted file mode 100755
index 311b8c493..000000000
--- a/website/content/ChapterFour/0927.Three-Equal-Parts.md
+++ /dev/null
@@ -1,113 +0,0 @@
-# [927. Three Equal Parts](https://leetcode.com/problems/three-equal-parts/)
-
-
-## 题目
-
-Given an array `A` of `0`s and `1`s, divide the array into 3 non-empty parts such that all of these parts represent the same binary value.
-
-If it is possible, return **any** `[i, j]` with `i+1 < j`, such that:
-
-- `A[0], A[1], ..., A[i]` is the first part;
-- `A[i+1], A[i+2], ..., A[j-1]` is the second part, and
-- `A[j], A[j+1], ..., A[A.length - 1]` is the third part.
-- All three parts have equal binary value.
-
-If it is not possible, return `[-1, -1]`.
-
-Note that the entire part is used when considering what binary value it represents. For example, `[1,1,0]` represents `6` in decimal, not `3`. Also, leading zeros are allowed, so `[0,1,1]` and `[1,1]` represent the same value.
-
-**Example 1**:
-
- Input: [1,0,1,0,1]
- Output: [0,3]
-
-**Example 2**:
-
- Input: [1,1,0,1,1]
- Output: [-1,-1]
-
-**Note**:
-
-1. `3 <= A.length <= 30000`
-2. `A[i] == 0` or `A[i] == 1`
-
-
-## 题目大意
-
-给定一个由 0 和 1 组成的数组 A,将数组分成 3 个非空的部分,使得所有这些部分表示相同的二进制值。如果可以做到,请返回任何 [i, j],其中 i+1 < j,这样一来:
-
-- A[0], A[1], ..., A[i] 组成第一部分;
-- A[i+1], A[i+2], ..., A[j-1] 作为第二部分;
-- A[j], A[j+1], ..., A[A.length - 1] 是第三部分。
-- 这三个部分所表示的二进制值相等。
-
-如果无法做到,就返回 [-1, -1]。
-
-注意,在考虑每个部分所表示的二进制时,应当将其看作一个整体。例如,[1,1,0] 表示十进制中的 6,而不会是 3。此外,前导零也是被允许的,所以 [0,1,1] 和 [1,1] 表示相同的值。
-
-提示:
-
-1. 3 <= A.length <= 30000
-2. A[i] == 0 或 A[i] == 1
-
-
-## 解题思路
-
-- 给出一个数组,数组里面只包含 0 和 1,要求找到 2 个分割点,使得分成的 3 个子数组的二进制是完全一样的。
-- 这一题的解题思路不难,按照题意模拟即可。先统计 1 的个数 total,然后除以 3 就是每段 1 出现的个数。有一些特殊情况需要额外判断一下,例如没有 1 的情况,那么只能首尾分割。1 个个数不是 3 的倍数,也无法分割成满足题意。然后找到第一个 1 的下标,然后根据 total/3 找到 mid,第一个分割点。再往后移动,找到第二个分割点。找到这 3 个点以后,同步的移动这 3 个点,移动中判断这 3 个下标对应的数值是否相等,如果都相等,并且最后一个点能移动到末尾,就算找到了满足题意的解了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func threeEqualParts(A []int) []int {
- n, ones, i, count := len(A), 0, 0, 0
- for _, a := range A {
- ones += a
- }
- if ones == 0 {
- return []int{0, n - 1}
- }
- if ones%3 != 0 {
- return []int{-1, -1}
- }
- k := ones / 3
- for i < n {
- if A[i] == 1 {
- break
- }
- i++
- }
- start, j := i, i
- for j < n {
- count += A[j]
- if count == k+1 {
- break
- }
- j++
- }
- mid := j
- j, count = 0, 0
- for j < n {
- count += A[j]
- if count == 2*k+1 {
- break
- }
- j++
- }
- end := j
- for end < n && A[start] == A[mid] && A[mid] == A[end] {
- start++
- mid++
- end++
- }
- if end == n {
- return []int{start - 1, mid}
- }
- return []int{-1, -1}
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0928.Minimize-Malware-Spread-II.md b/website/content/ChapterFour/0928.Minimize-Malware-Spread-II.md
deleted file mode 100755
index 4d83986bb..000000000
--- a/website/content/ChapterFour/0928.Minimize-Malware-Spread-II.md
+++ /dev/null
@@ -1,137 +0,0 @@
-# [928. Minimize Malware Spread II](https://leetcode.com/problems/minimize-malware-spread-ii/)
-
-
-## 题目
-
-(This problem is the same as *Minimize Malware Spread*, with the differences bolded.)
-
-In a network of nodes, each node `i` is directly connected to another node `j` if and only if `graph[i][j] = 1`.
-
-Some nodes `initial` are initially infected by malware. Whenever two nodes are directly connected and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.
-
-Suppose `M(initial)` is the final number of nodes infected with malware in the entire network, after the spread of malware stops.
-
-We will remove one node from the initial list, **completely removing it and any connections from this node to any other node**. Return the node that if removed, would minimize `M(initial)`. If multiple nodes could be removed to minimize `M(initial)`, return such a node with the smallest index.
-
-**Example 1**:
-
- Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]
- Output: 0
-
-**Example 2**:
-
- Input: graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]
- Output: 1
-
-**Example 3**:
-
- Input: graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]
- Output: 1
-
-**Note**:
-
-1. `1 < graph.length = graph[0].length <= 300`
-2. `0 <= graph[i][j] == graph[j][i] <= 1`
-3. `graph[i][i] = 1`
-4. `1 <= initial.length < graph.length`
-5. `0 <= initial[i] < graph.length`
-
-
-## 题目大意
-
-(这个问题与 尽量减少恶意软件的传播 是一样的,不同之处用粗体表示。)在节点网络中,只有当 graph[i][j] = 1 时,每个节点 i 能够直接连接到另一个节点 j。一些节点 initial 最初被恶意软件感染。只要两个节点直接连接,且其中至少一个节点受到恶意软件的感染,那么两个节点都将被恶意软件感染。这种恶意软件的传播将继续,直到没有更多的节点可以被这种方式感染。假设 M(initial) 是在恶意软件停止传播之后,整个网络中感染恶意软件的最终节点数。我们可以从初始列表中删除一个节点,并完全移除该节点以及从该节点到任何其他节点的任何连接。如果移除这一节点将最小化 M(initial), 则返回该节点。如果有多个节点满足条件,就返回索引最小的节点。
-
-提示:
-
-- 1 < graph.length = graph[0].length <= 300
-- 0 <= graph[i][j] == graph[j][i] <= 1
-- graph[i][i] = 1
-- 1 <= initial.length < graph.length
-- 0 <= initial[i] < graph.length
-
-
-## 解题思路
-
-
-- 这一题是第 924 题的加强版。给出一个节点之间的关系图,如果两个节点是连通的,那么病毒软件就会感染到连通的所有节点。现在如果想**完全彻底**移除一个病毒节点,能最大减少感染,请问移除哪个节点?如果多个节点都能减少感染量,优先移除序号偏小的那个节点。这一题的输入输出要求和第 924 题是完全一样的,区别在于第 924 题实际上是要求把一个病毒节点变成非病毒节点,而这道题是完全删除一个病毒节点以及它连接的所有边。
-- 这一题考察的是并查集。当然用 DFS 也可以解答这一题。并查集的做法如下,首先先将所有的病毒节点去掉,然后将所有连通块合并成一个节点。因为一个连通集合中的节点,要么全部被感染,要么全部不被感染,所以可以把每个集合整体考虑。然后统计所有集合直接相邻的病毒节点的个数。对于一个集合来说:
- 1. 如果直接相邻的病毒节点的个数为 0,则一定不会被感染,忽略这种情况;
- 2. 如果直接相邻的病毒节点的个数为 1,则将该病毒节点删除后,整个连通块就可以避免被感染,这种情况是我们寻找的答案;
- 3. 如果直接相邻的病毒节点的个数大于等于2,则不管删除哪个病毒节点,该连通块都仍会被感染,忽略这种情况;
-- 所以只需在所有第二种连通块(直接相邻的病毒节点的个数为 1 的连通块)中,找出节点个数最多的连通块,与它相邻的病毒节点就是我们要删除的节点;如果有多个连通块节点个数相同,再找出与之对应的编号最小的病毒节点即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
-
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func minMalwareSpread2(graph [][]int, initial []int) int {
- if len(initial) == 0 {
- return 0
- }
- uf, minIndex, count, countMap, malwareMap, infectMap := template.UnionFind{}, initial[0], math.MinInt64, map[int]int{}, map[int]int{}, map[int]map[int]int{}
- for _, v := range initial {
- malwareMap[v]++
- }
- uf.Init(len(graph))
- for i := range graph {
- for j := range graph[i] {
- if i == j {
- break
- }
- if graph[i][j] == 1 && malwareMap[i] == 0 && malwareMap[j] == 0 {
- uf.Union(i, j)
- }
- }
- }
- for i := 0; i < len(graph); i++ {
- countMap[uf.Find(i)]++
- }
- // 记录每个集合和直接相邻病毒节点的个数
- for _, i := range initial {
- for j := 0; j < len(graph); j++ {
- if malwareMap[j] == 0 && graph[i][j] == 1 {
- p := uf.Find(j)
- if _, ok := infectMap[p]; ok {
- infectMap[p][i] = i
- } else {
- tmp := map[int]int{}
- tmp[i] = i
- infectMap[p] = tmp
- }
- }
- }
- }
- // 选出病毒节点中序号最小的
- for _, v := range initial {
- minIndex = min(minIndex, v)
- }
- for i, v := range infectMap {
- // 找出只和一个病毒节点相连通的
- if len(v) == 1 {
- tmp := countMap[uf.Find(i)]
- keys := []int{}
- for k := range v {
- keys = append(keys, k)
- }
- if count == tmp && minIndex > keys[0] {
- minIndex = keys[0]
- }
- if count < tmp {
- minIndex = keys[0]
- count = tmp
- }
- }
- }
- return minIndex
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0930.Binary-Subarrays-With-Sum.md b/website/content/ChapterFour/0930.Binary-Subarrays-With-Sum.md
deleted file mode 100644
index 161579ce6..000000000
--- a/website/content/ChapterFour/0930.Binary-Subarrays-With-Sum.md
+++ /dev/null
@@ -1,65 +0,0 @@
-# [930. Binary Subarrays With Sum](https://leetcode.com/problems/binary-subarrays-with-sum/)
-
-## 题目
-
-In an array A of 0s and 1s, how many non-empty subarrays have sum S?
-
-
-
-**Example 1**:
-
-```
-
-Input: A = [1,0,1,0,1], S = 2
-Output: 4
-Explanation:
-The 4 subarrays are bolded below:
-[1,0,1,0,1]
-[1,0,1,0,1]
-[1,0,1,0,1]
-[1,0,1,0,1]
-
-```
-
-
-**Note**:
-
-- A.length <= 30000
-- 0 <= S <= A.length
-- A[i] is either 0 or 1.
-
-
-## 题目大意
-
-给定一个数组,数组里面的元素只有 0 和 1 两种。问这个数组有多少个和为 S 的子数组。
-
-## 解题思路
-
-这道题也是滑动窗口的题目。不断的加入右边的值,直到总和等于 S。[i,j] 区间内的和可以等于 [0,j] 的和减去 [0,i-1] 的和。在 freq 中不断的记下能使得和为 sum 的组合方法数,例如 freq[1] = 2 ,代表和为 1 有两种组合方法,(可能是 1 和 1,0 或者 0,1,这道题只管组合总数,没要求输出具体的组合对)。这道题的做法就是不断的累加,如果遇到比 S 多的情况,多出来的值就在 freq 中查表,看多出来的值可能是由几种情况构成的。一旦和与 S 相等以后,之后比 S 多出来的情况会越来越多(因为在不断累积,总和只会越来越大),不断的查 freq 表就可以了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "fmt"
-
-func numSubarraysWithSum(A []int, S int) int {
- freq, sum, res := make([]int, len(A)+1), 0, 0
- freq[0] = 1
- for _, v := range A {
- t := sum + v - S
- if t >= 0 {
- // 总和有多余的,需要减去 t,除去的方法有 freq[t] 种
- res += freq[t]
- }
- sum += v
- freq[sum]++
- fmt.Printf("freq = %v sum = %v res = %v t = %v\n", freq, sum, res, t)
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0933.Number-of-Recent-Calls.md b/website/content/ChapterFour/0933.Number-of-Recent-Calls.md
deleted file mode 100644
index 02b2340ce..000000000
--- a/website/content/ChapterFour/0933.Number-of-Recent-Calls.md
+++ /dev/null
@@ -1,74 +0,0 @@
-# [933. Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls/)
-
-
-
-## 题目
-
-Write a class `RecentCounter` to count recent requests.
-
-It has only one method: `ping(int t)`, where t represents some time in milliseconds.
-
-Return the number of `ping`s that have been made from 3000 milliseconds ago until now.
-
-Any ping with time in `[t - 3000, t]` will count, including the current ping.
-
-It is guaranteed that every call to `ping` uses a strictly larger value of `t` than before.
-
-**Example 1**:
-
-```
-Input: inputs = ["RecentCounter","ping","ping","ping","ping"], inputs = [[],[1],[100],[3001],[3002]]
-Output: [null,1,2,3,3]
-```
-
-**Note**:
-
-1. Each test case will have at most `10000` calls to `ping`.
-2. Each test case will call `ping` with strictly increasing values of `t`.
-3. Each call to ping will have `1 <= t <= 10^9`.
-
-
-## 题目大意
-
-写一个 RecentCounter 类来计算最近的请求。它只有一个方法:ping(int t),其中 t 代表以毫秒为单位的某个时间。返回从 3000 毫秒前到现在的 ping 数。任何处于 [t - 3000, t] 时间范围之内的 ping 都将会被计算在内,包括当前(指 t 时刻)的 ping。保证每次对 ping 的调用都使用比之前更大的 t 值。
-
-提示:
-
-- 每个测试用例最多调用 10000 次 ping。
-- 每个测试用例会使用严格递增的 t 值来调用 ping。
-- 每次调用 ping 都有 1 <= t <= 10^9。
-
-
-## 解题思路
-
-- 要求设计一个类,可以用 `ping(t)` 的方法,计算 [t-3000, t] 区间内的 ping 数。t 是毫秒。
-- 这一题比较简单,`ping()` 方法用二分搜索即可。
-
-## 代码
-
-```go
-type RecentCounter struct {
- list []int
-}
-
-func Constructor933() RecentCounter {
- return RecentCounter{
- list: []int{},
- }
-}
-
-func (this *RecentCounter) Ping(t int) int {
- this.list = append(this.list, t)
- index := sort.Search(len(this.list), func(i int) bool { return this.list[i] >= t-3000 })
- if index < 0 {
- index = -index - 1
- }
- return len(this.list) - index
-}
-
-/**
- * Your RecentCounter object will be instantiated and called as such:
- * obj := Constructor();
- * param_1 := obj.Ping(t);
- */
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0942.DI-String-Match.md b/website/content/ChapterFour/0942.DI-String-Match.md
deleted file mode 100755
index 485dee18f..000000000
--- a/website/content/ChapterFour/0942.DI-String-Match.md
+++ /dev/null
@@ -1,73 +0,0 @@
-# [942. DI String Match](https://leetcode.com/problems/di-string-match/)
-
-
-## 题目
-
-Given a string `S` that **only** contains "I" (increase) or "D" (decrease), let `N = S.length`.
-
-Return **any** permutation `A` of `[0, 1, ..., N]` such that for all `i = 0, ..., N-1`:
-
-- If `S[i] == "I"`, then `A[i] < A[i+1]`
-- If `S[i] == "D"`, then `A[i] > A[i+1]`
-
-**Example 1**:
-
- Input: "IDID"
- Output: [0,4,1,3,2]
-
-**Example 2**:
-
- Input: "III"
- Output: [0,1,2,3]
-
-**Example 3**:
-
- Input: "DDI"
- Output: [3,2,0,1]
-
-**Note**:
-
-1. `1 <= S.length <= 10000`
-2. `S` only contains characters `"I"` or `"D"`.
-
-
-## 题目大意
-
-给定只含 "I"(增大)或 "D"(减小)的字符串 S ,令 N = S.length。返回 [0, 1, ..., N] 的任意排列 A 使得对于所有 i = 0, ..., N-1,都有:
-
-- 如果 S[i] == "I",那么 A[i] < A[i+1]
-- 如果 S[i] == "D",那么 A[i] > A[i+1]
-
-
-
-## 解题思路
-
-
-- 给出一个字符串,字符串中只有字符 `"I"` 和字符 `"D"`。字符 `"I"` 代表 `A[i] < A[i+1]`,字符 `"D"` 代表 `A[i] > A[i+1]` ,要求找到满足条件的任意组合。
-- 这一题也是水题,取出字符串长度即是最大数的数值,然后按照题意一次排出最终数组即可。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func diStringMatch(S string) []int {
- result, maxNum, minNum, index := make([]int, len(S)+1), len(S), 0, 0
- for _, ch := range S {
- if ch == 'I' {
- result[index] = minNum
- minNum++
- } else {
- result[index] = maxNum
- maxNum--
- }
- index++
- }
- result[index] = minNum
- return result
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0946.Validate-Stack-Sequences.md b/website/content/ChapterFour/0946.Validate-Stack-Sequences.md
deleted file mode 100644
index f69621d28..000000000
--- a/website/content/ChapterFour/0946.Validate-Stack-Sequences.md
+++ /dev/null
@@ -1,68 +0,0 @@
-# [946. Validate Stack Sequences](https://leetcode.com/problems/validate-stack-sequences/)
-
-## 题目
-
-Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.
-
-
-
-**Example 1**:
-
-```
-
-Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
-Output: true
-Explanation: We might do the following sequence:
-push(1), push(2), push(3), push(4), pop() -> 4,
-push(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1
-
-```
-
-**Example 2**:
-
-```
-
-Input: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
-Output: false
-Explanation: 1 cannot be popped before 2.
-
-```
-
-**Note**:
-
-1. 0 <= pushed.length == popped.length <= 1000
-2. 0 <= pushed[i], popped[i] < 1000
-3. pushed is a permutation of popped.
-4. pushed and popped have distinct values.
-
-## 题目大意
-
-给 2 个数组,一个数组里面代表的是 push 的顺序,另一个数组里面代表的是 pop 的顺序。问按照这样的顺序操作以后,最终能否把栈清空?
-
-## 解题思路
-
-这一题也是靠栈操作的题目,按照 push 数组的顺序先把压栈,然后再依次在 pop 里面找栈顶元素,找到了就 pop,直到遍历完 pop 数组,最终如果遍历完了 pop 数组,就代表清空了整个栈了。
-
-## 代码
-
-```go
-
-package leetcode
-
-import "fmt"
-
-func validateStackSequences(pushed []int, popped []int) bool {
- stack, j, N := []int{}, 0, len(pushed)
- for _, x := range pushed {
- stack = append(stack, x)
- fmt.Printf("stack = %v j = %v\n", stack, j)
- for len(stack) != 0 && j < N && stack[len(stack)-1] == popped[j] {
- stack = stack[0 : len(stack)-1]
- j++
- }
- fmt.Printf("*****stack = %v j = %v\n", stack, j)
- }
- return j == N
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md b/website/content/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md
deleted file mode 100755
index 886bb0361..000000000
--- a/website/content/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md
+++ /dev/null
@@ -1,82 +0,0 @@
-# [947. Most Stones Removed with Same Row or Column](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/)
-
-
-## 题目
-
-On a 2D plane, we place stones at some integer coordinate points. Each coordinate point may have at most one stone.
-
-Now, a *move* consists of removing a stone that shares a column or row with another stone on the grid.
-
-What is the largest possible number of moves we can make?
-
-**Example 1**:
-
- Input: stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]
- Output: 5
-
-**Example 2**:
-
- Input: stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]
- Output: 3
-
-**Example 3**:
-
- Input: stones = [[0,0]]
- Output: 0
-
-**Note**:
-
-1. `1 <= stones.length <= 1000`
-2. `0 <= stones[i][j] < 10000`
-
-
-## 题目大意
-
-在二维平面上,我们将石头放置在一些整数坐标点上。每个坐标点上最多只能有一块石头。现在,move 操作将会移除与网格上的某一块石头共享一列或一行的一块石头。我们最多能执行多少次 move 操作?
-
-提示:
-
-- 1 <= stones.length <= 1000
-- 0 <= stones[i][j] < 10000
-
-
-## 解题思路
-
-
-- 给出一个数组,数组中的元素是一系列的坐标点。现在可以移除一些坐标点,移除必须满足:移除的这个点,在相同的行或者列上有一个点。问最终可以移除多少个点。移除到最后必然有些点独占一行,那么这些点都不能被移除。
-- 这一题的解题思路是并查集。把所有共行或者共列的点都 `union()` 起来。不同集合之间是不能相互移除的。反证法:如果能移除,代表存在共行或者共列的情况,那么肯定是同一个集合了,这样就不满足不同集合了。最终剩下的点就是集合的个数,每个集合只会留下一个点。所以移除的点就是点的总数减去集合的个数 `len(stones) - uf.totalCount()`。
-- 如果暴力合并集合,时间复杂度也非常差,可以由优化的地方。再遍历所有点的过程中,可以把遍历过的行和列存起来。这里可以用 map 来记录,key 为行号,value 为上一次遍历过的点的序号。同样,列也可以用 map 存起来,key 为列号,value 为上一次遍历过的点的序号。经过这样的优化以后,时间复杂度会提高不少。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func removeStones(stones [][]int) int {
- if len(stones) <= 1 {
- return 0
- }
- uf, rowMap, colMap := template.UnionFind{}, map[int]int{}, map[int]int{}
- uf.Init(len(stones))
- for i := 0; i < len(stones); i++ {
- if _, ok := rowMap[stones[i][0]]; ok {
- uf.Union(rowMap[stones[i][0]], i)
- } else {
- rowMap[stones[i][0]] = i
- }
- if _, ok := colMap[stones[i][1]]; ok {
- uf.Union(colMap[stones[i][1]], i)
- } else {
- colMap[stones[i][1]] = i
- }
- }
- return len(stones) - uf.TotalCount()
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0949.Largest-Time-for-Given-Digits.md b/website/content/ChapterFour/0949.Largest-Time-for-Given-Digits.md
deleted file mode 100644
index 02f0bf435..000000000
--- a/website/content/ChapterFour/0949.Largest-Time-for-Given-Digits.md
+++ /dev/null
@@ -1,78 +0,0 @@
-# [949. Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits/)
-
-
-## 题目
-
-Given an array of 4 digits, return the largest 24 hour time that can be made.
-
-The smallest 24 hour time is 00:00, and the largest is 23:59. Starting from 00:00, a time is larger if more time has elapsed since midnight.
-
-Return the answer as a string of length 5. If no valid time can be made, return an empty string.
-
-**Example 1**:
-
-```
-Input: [1,2,3,4]
-Output: "23:41"
-```
-
-**Example 2**:
-
-```
-Input: [5,5,5,5]
-Output: ""
-```
-
-**Note**:
-
-1. `A.length == 4`
-2. `0 <= A[i] <= 9`
-
-## 题目大意
-
-给定一个由 4 位数字组成的数组,返回可以设置的符合 24 小时制的最大时间。最小的 24 小时制时间是 00:00,而最大的是 23:59。从 00:00 (午夜)开始算起,过得越久,时间越大。以长度为 5 的字符串返回答案。如果不能确定有效时间,则返回空字符串。
-
-## 解题思路
-
-- 给出 4 个数字,要求返回一个字符串,代表由这 4 个数字能组成的最大 24 小时制的时间。
-- 简单题,这一题直接暴力枚举就可以了。依次检查给出的 4 个数字每个排列组合是否是时间合法的。例如检查 10 * A[i] + A[j] 是不是小于 24, 10 * A[k] + A[l] 是不是小于 60。如果合法且比目前存在的最大时间更大,就更新这个最大时间。
-
-## 代码
-
-```go
-
-package leetcode
-
-import "fmt"
-
-func largestTimeFromDigits(A []int) string {
- flag, res := false, 0
- for i := 0; i < 4; i++ {
- for j := 0; j < 4; j++ {
- if i == j {
- continue
- }
- for k := 0; k < 4; k++ {
- if i == k || j == k {
- continue
- }
- l := 6 - i - j - k
- hour := A[i]*10 + A[j]
- min := A[k]*10 + A[l]
- if hour < 24 && min < 60 {
- if hour*60+min >= res {
- res = hour*60 + min
- flag = true
- }
- }
- }
- }
- }
- if flag {
- return fmt.Sprintf("%02d:%02d", res/60, res%60)
- } else {
- return ""
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md b/website/content/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md
deleted file mode 100755
index d37262bce..000000000
--- a/website/content/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md
+++ /dev/null
@@ -1,119 +0,0 @@
-# [952. Largest Component Size by Common Factor](https://leetcode.com/problems/largest-component-size-by-common-factor/)
-
-
-## 题目
-
-Given a non-empty array of unique positive integers `A`, consider the following graph:
-
-- There are `A.length` nodes, labelled `A[0]` to `A[A.length - 1];`
-- There is an edge between `A[i]` and `A[j]` if and only if `A[i]`and `A[j]` share a common factor greater than 1.
-
-Return the size of the largest connected component in the graph.
-
-**Example 1**:
-
- Input: [4,6,15,35]
- Output: 4
-
-
-
-**Example 2**:
-
- Input: [20,50,9,63]
- Output: 2
-
-
-
-**Example 3**:
-
- Input: [2,3,6,7,4,12,21,39]
- Output: 8
-
-
-
-**Note**:
-
-1. `1 <= A.length <= 20000`
-2. `1 <= A[i] <= 100000`
-
-
-## 题目大意
-
-给定一个由不同正整数的组成的非空数组 A,考虑下面的图:
-
-有 A.length 个节点,按从 A[0] 到 A[A.length - 1] 标记;
-只有当 A[i] 和 A[j] 共用一个大于 1 的公因数时,A[i] 和 A[j] 之间才有一条边。
-返回图中最大连通组件的大小。
-
-提示:
-
-1. 1 <= A.length <= 20000
-2. 1 <= A[i] <= 100000
-
-## 解题思路
-
-- 给出一个数组,数组中的元素如果每两个元素有公约数,那么这两个元素可以算有关系。所有有关系的数可以放在一个集合里,问这个数组里面有关系的元素组成的集合里面最多有多少个元素。
-- 这一题读完题直觉就是用并查集来解题。首先可以用暴力的解法尝试。用 2 层循环,两两比较有没有公约数,如果有公约数就 `union()` 到一起。提交以后出现 TLE,其实看一下数据规模就知道会超时,`1 <= A.length <= 20000`。注意到 `1 <= A[i] <= 100000`,开根号以后最后才 316.66666,这个规模的数不大。所以把每个数小于根号自己的因子都找出来,例如 `6 = 2 * 3`,`15 = 3 * 5`,那么把 6 和 2,6 和 3 都 `union()`,15 和 3,15 和 5 都 `union()`,最终遍历所有的集合,找到最多元素的集合,输出它包含的元素值。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-// 解法一 并查集 UnionFind
-func largestComponentSize(A []int) int {
- maxElement, uf, countMap, res := 0, template.UnionFind{}, map[int]int{}, 1
- for _, v := range A {
- maxElement = max(maxElement, v)
- }
- uf.Init(maxElement + 1)
- for _, v := range A {
- for k := 2; k*k <= v; k++ {
- if v%k == 0 {
- uf.Union(v, k)
- uf.Union(v, v/k)
- }
- }
- }
- for _, v := range A {
- countMap[uf.Find(v)]++
- res = max(res, countMap[uf.Find(v)])
- }
- return res
-}
-
-// 解法二 UnionFindCount
-func largestComponentSize1(A []int) int {
- uf, factorMap := template.UnionFindCount{}, map[int]int{}
- uf.Init(len(A))
- for i, v := range A {
- for k := 2; k*k <= v; k++ {
- if v%k == 0 {
- if _, ok := factorMap[k]; !ok {
- factorMap[k] = i
- } else {
- uf.Union(i, factorMap[k])
- }
- if _, ok := factorMap[v/k]; !ok {
- factorMap[v/k] = i
- } else {
- uf.Union(i, factorMap[v/k])
- }
- }
- }
- if _, ok := factorMap[v]; !ok {
- factorMap[v] = i
- } else {
- uf.Union(i, factorMap[v])
- }
- }
- return uf.MaxUnionCount()
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0953.Verifying-an-Alien-Dictionary.md b/website/content/ChapterFour/0953.Verifying-an-Alien-Dictionary.md
deleted file mode 100755
index ff648c14e..000000000
--- a/website/content/ChapterFour/0953.Verifying-an-Alien-Dictionary.md
+++ /dev/null
@@ -1,81 +0,0 @@
-# [953. Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary/)
-
-
-## 题目
-
-In an alien language, surprisingly they also use english lowercase letters, but possibly in a different `order`. The `order`of the alphabet is some permutation of lowercase letters.
-
-Given a sequence of `words` written in the alien language, and the `order` of the alphabet, return `true` if and only if the given `words` are sorted lexicographicaly in this alien language.
-
-**Example 1**:
-
- Input: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"
- Output: true
- Explanation: As 'h' comes before 'l' in this language, then the sequence is sorted.
-
-**Example 2**:
-
- Input: words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"
- Output: false
- Explanation: As 'd' comes after 'l' in this language, then words[0] > words[1], hence the sequence is unsorted.
-
-**Example 3**:
-
- Input: words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"
- Output: false
- Explanation: The first three characters "app" match, and the second string is shorter (in size.) According to lexicographical rules "apple" > "app", because 'l' > '∅', where '∅' is defined as the blank character which is less than any other character (More info).
-
-**Note**:
-
-1. `1 <= words.length <= 100`
-2. `1 <= words[i].length <= 20`
-3. `order.length == 26`
-4. All characters in `words[i]` and `order` are english lowercase letters.
-
-
-## 题目大意
-
-某种外星语也使用英文小写字母,但可能顺序 order 不同。字母表的顺序(order)是一些小写字母的排列。给定一组用外星语书写的单词 words,以及其字母表的顺序 order,只有当给定的单词在这种外星语中按字典序排列时,返回 true;否则,返回 false。
-
-
-
-## 解题思路
-
-
-- 这一题是简单题。给出一个字符串数组,判断把字符串数组里面字符串是否是按照 order 的排序排列的。order 是给出个一个字符串排序。这道题的解法是把 26 个字母的顺序先存在 map 中,然后依次遍历判断字符串数组里面字符串的大小。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func isAlienSorted(words []string, order string) bool {
- if len(words) < 2 {
- return true
- }
- hash := make(map[byte]int)
- for i := 0; i < len(order); i++ {
- hash[order[i]] = i
- }
- for i := 0; i < len(words)-1; i++ {
- pointer, word, wordplus := 0, words[i], words[i+1]
- for pointer < len(word) && pointer < len(wordplus) {
- if hash[word[pointer]] > hash[wordplus[pointer]] {
- return false
- }
- if hash[word[pointer]] < hash[wordplus[pointer]] {
- break
- } else {
- pointer = pointer + 1
- }
- }
- if pointer < len(word) && pointer >= len(wordplus) {
- return false
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0959.Regions-Cut-By-Slashes.md b/website/content/ChapterFour/0959.Regions-Cut-By-Slashes.md
deleted file mode 100755
index c560cc59b..000000000
--- a/website/content/ChapterFour/0959.Regions-Cut-By-Slashes.md
+++ /dev/null
@@ -1,150 +0,0 @@
-# [959. Regions Cut By Slashes](https://leetcode.com/problems/regions-cut-by-slashes/)
-
-
-## 题目
-
-In a N x N `grid` composed of 1 x 1 squares, each 1 x 1 square consists of a `/`, `\`, or blank space. These characters divide the square into contiguous regions.
-
-(Note that backslash characters are escaped, so a `\` is represented as `"\\"`.)
-
-Return the number of regions.
-
-**Example 1**:
-
- Input:
- [
- " /",
- "/ "
- ]
- Output: 2
- Explanation: The 2x2 grid is as follows:
-
-
-
-**Example 2**:
-
- Input:
- [
- " /",
- " "
- ]
- Output: 1
- Explanation: The 2x2 grid is as follows:
-
-
-
-**Example 3**:
-
- Input:
- [
- "\\/",
- "/\\"
- ]
- Output: 4
- Explanation: (Recall that because \ characters are escaped, "\\/" refers to \/, and "/\\" refers to /\.)
- The 2x2 grid is as follows:
-
-
-
-**Example 4**:
-
- Input:
- [
- "/\\",
- "\\/"
- ]
- Output: 5
- Explanation: (Recall that because \ characters are escaped, "/\\" refers to /\, and "\\/" refers to \/.)
- The 2x2 grid is as follows:
-
-
-
-**Example 5**:
-
- Input:
- [
- "//",
- "/ "
- ]
- Output: 3
- Explanation: The 2x2 grid is as follows:
-
-
-
-**Note**:
-
-1. `1 <= grid.length == grid[0].length <= 30`
-2. `grid[i][j]` is either `'/'`, `'\'`, or `' '`.
-
-
-## 题目大意
-
-在由 1 x 1 方格组成的 N x N 网格 grid 中,每个 1 x 1 方块由 /、\ 或空格构成。这些字符会将方块划分为一些共边的区域。(请注意,反斜杠字符是转义的,因此 \ 用 "\\" 表示)返回区域的数目。
-
-
-提示:
-
-- 1 <= grid.length == grid[0].length <= 30
-- grid[i][j] 是 '/'、'\'、或 ' '。
-
-## 解题思路
-
-
-- 给出一个字符串,代表的是 `N x N` 正方形中切分的情况,有 2 种切分的情况 `'\'` 和 `'/'` ,即从左上往右下切和从右上往左下切。问按照给出的切分方法,能把 `N x N` 正方形切成几部分?
-- 这一题解题思路是并查集。先将每个 `1*1` 的正方形切分成下图的样子。分成 4 小块。然后按照题目给的切分图来合并各个小块。
-
-
-
-- 遇到 `'\\'`,就把第 0 块和第 1 块 `union()` 起来,第 2 块和第 3 块 `union()` 起来;遇到 `'/'`,就把第 0 块和第 3 块 `union()` 起来,第 2 块和第 1 块 `union()` 起来;遇到 `' '`,就把第 0 块和第 1 块 `union()` 起来,第 2 块和第 1 块 `union()` 起来,第 2 块和第 3 块 `union()` 起来,即 4 块都 `union()` 起来;最后还需要记得上一行和下一行还需要 `union()`,即本行的第 2 块和下一行的第 0 块 `union()` 起来;左边一列和右边一列也需要 `union()`。即本列的第 1 块和右边一列的第 3 块 `union()` 起来。最后计算出集合总个数就是最终答案了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func regionsBySlashes(grid []string) int {
- size := len(grid)
- uf := template.UnionFind{}
- uf.Init(4 * size * size)
- for i := 0; i < size; i++ {
- for j := 0; j < size; j++ {
- switch grid[i][j] {
- case '\\':
- uf.Union(getFaceIdx(size, i, j, 0), getFaceIdx(size, i, j, 1))
- uf.Union(getFaceIdx(size, i, j, 2), getFaceIdx(size, i, j, 3))
- case '/':
- uf.Union(getFaceIdx(size, i, j, 0), getFaceIdx(size, i, j, 3))
- uf.Union(getFaceIdx(size, i, j, 2), getFaceIdx(size, i, j, 1))
- case ' ':
- uf.Union(getFaceIdx(size, i, j, 0), getFaceIdx(size, i, j, 1))
- uf.Union(getFaceIdx(size, i, j, 2), getFaceIdx(size, i, j, 1))
- uf.Union(getFaceIdx(size, i, j, 2), getFaceIdx(size, i, j, 3))
- }
- if i < size-1 {
- uf.Union(getFaceIdx(size, i, j, 2), getFaceIdx(size, i+1, j, 0))
- }
- if j < size-1 {
- uf.Union(getFaceIdx(size, i, j, 1), getFaceIdx(size, i, j+1, 3))
- }
- }
- }
- count := 0
- for i := 0; i < 4*size*size; i++ {
- if uf.Find(i) == i {
- count++
- }
- }
- return count
-}
-
-func getFaceIdx(size, i, j, k int) int {
- return 4*(i*size+j) + k
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0961.N-Repeated-Element-in-Size-2N-Array.md b/website/content/ChapterFour/0961.N-Repeated-Element-in-Size-2N-Array.md
deleted file mode 100755
index a9e53e779..000000000
--- a/website/content/ChapterFour/0961.N-Repeated-Element-in-Size-2N-Array.md
+++ /dev/null
@@ -1,60 +0,0 @@
-# [961. N-Repeated Element in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array/)
-
-
-## 题目
-
-In a array `A` of size `2N`, there are `N+1` unique elements, and exactly one of these elements is repeated N times.
-
-Return the element repeated `N` times.
-
-**Example 1**:
-
- Input: [1,2,3,3]
- Output: 3
-
-**Example 2**:
-
- Input: [2,1,2,5,3,2]
- Output: 2
-
-**Example 3**:
-
- Input: [5,1,5,2,5,3,5,4]
- Output: 5
-
-**Note**:
-
-1. `4 <= A.length <= 10000`
-2. `0 <= A[i] < 10000`
-3. `A.length` is even
-
-
-## 题目大意
-
-在大小为 2N 的数组 A 中有 N+1 个不同的元素,其中有一个元素重复了 N 次。返回重复了 N 次的那个元素。
-
-
-## 解题思路
-
-
-- 简单题。数组中有 2N 个数,有 N + 1 个数是不重复的,这之中有一个数重复了 N 次,请找出这个数。解法非常简单,把所有数都存入 map 中,如果遇到存在的 key 就返回这个数。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func repeatedNTimes(A []int) int {
- kv := make(map[int]struct{})
- for _, val := range A {
- if _, ok := kv[val]; ok {
- return val
- }
- kv[val] = struct{}{}
- }
- return 0
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0968.Binary-Tree-Cameras.md b/website/content/ChapterFour/0968.Binary-Tree-Cameras.md
deleted file mode 100755
index d9873a5bb..000000000
--- a/website/content/ChapterFour/0968.Binary-Tree-Cameras.md
+++ /dev/null
@@ -1,103 +0,0 @@
-# [968. Binary Tree Cameras](https://leetcode.com/problems/binary-tree-cameras/)
-
-## 题目
-
-Given a binary tree, we install cameras on the nodes of the tree.
-
-Each camera at a node can monitor **its parent, itself, and its immediate children**.
-
-Calculate the minimum number of cameras needed to monitor all nodes of the tree.
-
-**Example 1**:
-
-
-
- Input: [0,0,null,0,0]
- Output: 1
- Explanation: One camera is enough to monitor all nodes if placed as shown.
-
-**Example 2**:
-
-
-
- Input: [0,0,null,0,null,0,null,null,0]
- Output: 2
- Explanation: At least two cameras are needed to monitor all nodes of the tree. The above image shows one of the valid configurations of camera placement.
-
-**Note**:
-
-1. The number of nodes in the given tree will be in the range `[1, 1000]`.
-2. **Every** node has value 0.
-
-
-## 题目大意
-
-给定一个二叉树,我们在树的节点上安装摄像头。节点上的每个摄影头都可以监视其父对象、自身及其直接子对象。计算监控树的所有节点所需的最小摄像头数量。
-
-提示:
-
-1. 给定树的节点数的范围是 [1, 1000]。
-2. 每个节点的值都是 0。
-
-
-
-## 解题思路
-
-- 给出一棵树,要求在这个树上面放摄像头,一个摄像头最多可以监视 4 个节点,2 个孩子,本身节点,还有父亲节点。问最少放多少个摄像头可以覆盖树上的所有节点。
-- 这一题可以用贪心思想来解题。先将节点分为 3 类,第一类,叶子节点,第二类,包含叶子节点的节点,第三类,其中一个叶子节点上放了摄像头的。按照这个想法,将树的每个节点染色,如下图。
-
-
-
-- 所有包含叶子节点的节点,可以放一个摄像头,这个可以覆盖至少 3 个节点,如果还有父节点的话,可以覆盖 4 个节点。所以贪心的策略是从最下层的叶子节点开始往上“染色”,先把最下面的一层 1 染色。标 1 的节点都是要放一个摄像头的。如果叶子节点中包含 1 的节点,那么再将这个节点染成 2 。如下图的黄色节点。黄色节点代表的是不用放摄像头的节点,因为它被叶子节点的摄像头覆盖了。出现了 2 的节点以后,再往上的节点又再次恢复成叶子节点 0 。如此类推,直到推到根节点。
-
-
-
-- 最后根节点还需要注意多种情况,根节点可能是叶子节点 0,那么最终答案还需要 + 1,因为需要在根节点上放一个摄像头,不然根节点覆盖不到了。根节点也有可能是 1 或者 2,这两种情况都不需要增加摄像头了,以为都覆盖到了。按照上述的方法,递归即可得到答案。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-type status int
-
-const (
- isLeaf status = iota
- parentofLeaf
- isMonitoredWithoutCamera
-)
-
-func minCameraCover(root *TreeNode) int {
- res := 0
- if minCameraCoverDFS(root, &res) == isLeaf {
- res++
- }
- return res
-}
-
-func minCameraCoverDFS(root *TreeNode, res *int) status {
- if root == nil {
- return 2
- }
- left, right := minCameraCoverDFS(root.Left, res), minCameraCoverDFS(root.Right, res)
- if left == isLeaf || right == isLeaf {
- *res++
- return parentofLeaf
- } else if left == parentofLeaf || right == parentofLeaf {
- return isMonitoredWithoutCamera
- } else {
- return isLeaf
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0969.Pancake-Sorting.md b/website/content/ChapterFour/0969.Pancake-Sorting.md
deleted file mode 100644
index 68288d5c2..000000000
--- a/website/content/ChapterFour/0969.Pancake-Sorting.md
+++ /dev/null
@@ -1,96 +0,0 @@
-# [969. Pancake Sorting](https://leetcode.com/problems/pancake-sorting/)
-
-## 题目
-
-Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, then reverse the order of the first k elements of A. We want to perform zero or more pancake flips (doing them one after another in succession) to sort the array A.
-
-Return the k-values corresponding to a sequence of pancake flips that sort A. Any valid answer that sorts the array within 10 * A.length flips will be judged as correct.
-
-**Example 1**:
-
-```
-
-Input: [3,2,4,1]
-Output: [4,2,4,3]
-Explanation:
-We perform 4 pancake flips, with k values 4, 2, 4, and 3.
-Starting state: A = [3, 2, 4, 1]
-After 1st flip (k=4): A = [1, 4, 2, 3]
-After 2nd flip (k=2): A = [4, 1, 2, 3]
-After 3rd flip (k=4): A = [3, 2, 1, 4]
-After 4th flip (k=3): A = [1, 2, 3, 4], which is sorted.
-
-```
-
-**Example 2**:
-
-```
-
-Input: [1,2,3]
-Output: []
-Explanation: The input is already sorted, so there is no need to flip anything.
-Note that other answers, such as [3, 3], would also be accepted.
-
-```
-
-**Note**:
-
-- 1 <= A.length <= 100
-- A[i] is a permutation of [1, 2, ..., A.length]
-
-## 题目大意
-
-给定一个数组,要求输出“煎饼排序”的步骤,使得最终数组是从小到大有序的。“煎饼排序”,每次排序都反转前 n 个数,n 小于数组的长度。
-
-## 解题思路
-
-这道题的思路是,每次找到当前数组中无序段中最大的值,(初始的时候,整个数组相当于都是无序段),将最大值的下标 i 进行“煎饼排序”,前 i 个元素都反转一遍。这样最大值就到了第一个位置了。然后紧接着再进行一次数组总长度 n 的“煎饼排序”,目的是使最大值到数组最后一位,这样它的位置就归位了。那么数组的无序段为 n-1 。然后用这个方法不断的循环,直至数组中每个元素都到了排序后最终的位置下标上了。最终数组就有序了。
-
-这道题有一个特殊点在于,数组里面的元素都是自然整数,那么最终数组排序完成以后,数组的长度就是最大值。所以找最大值也不需要遍历一次数组了,直接取出长度就是最大值。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func pancakeSort(A []int) []int {
- if len(A) == 0 {
- return []int{}
- }
- right := len(A)
- var (
- ans []int
- )
- for right > 0 {
- idx := find(A, right)
- if idx != right-1 {
- reverse969(A, 0, idx)
- reverse969(A, 0, right-1)
- ans = append(ans, idx+1, right)
- }
- right--
- }
-
- return ans
-}
-
-func reverse969(nums []int, l, r int) {
- for l < r {
- nums[l], nums[r] = nums[r], nums[l]
- l++
- r--
- }
-}
-
-func find(nums []int, t int) int {
- for i, num := range nums {
- if num == t {
- return i
- }
- }
- return -1
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0970.Powerful-Integers.md b/website/content/ChapterFour/0970.Powerful-Integers.md
deleted file mode 100755
index 9de409549..000000000
--- a/website/content/ChapterFour/0970.Powerful-Integers.md
+++ /dev/null
@@ -1,88 +0,0 @@
-# [970. Powerful Integers](https://leetcode.com/problems/powerful-integers/)
-
-
-## 题目
-
-Given two positive integers `x` and `y`, an integer is *powerful* if it is equal to `x^i + y^j` for some integers `i >= 0` and `j >= 0`.
-
-Return a list of all *powerful* integers that have value less than or equal to `bound`.
-
-You may return the answer in any order. In your answer, each value should occur at most once.
-
-**Example 1**:
-
- Input: x = 2, y = 3, bound = 10
- Output: [2,3,4,5,7,9,10]
- Explanation:
- 2 = 2^0 + 3^0
- 3 = 2^1 + 3^0
- 4 = 2^0 + 3^1
- 5 = 2^1 + 3^1
- 7 = 2^2 + 3^1
- 9 = 2^3 + 3^0
- 10 = 2^0 + 3^2
-
-**Example 2**:
-
- Input: x = 3, y = 5, bound = 15
- Output: [2,4,6,8,10,14]
-
-**Note**:
-
-- `1 <= x <= 100`
-- `1 <= y <= 100`
-- `0 <= bound <= 10^6`
-
-
-## 题目大意
-
-给定两个正整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个强整数。返回值小于或等于 bound 的所有强整数组成的列表。你可以按任何顺序返回答案。在你的回答中,每个值最多出现一次。
-
-
-## 解题思路
-
-
-- 简答题,题目要求找出满足 `x^i + y^j ≤ bound` 条件的所有解。题目要求输出中不能重复,所以用 map 来去重。剩下的就是 `n^2` 暴力循环枚举所有解。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math"
-
-func powerfulIntegers(x int, y int, bound int) []int {
- if x == 1 && y == 1 {
- if bound < 2 {
- return []int{}
- }
- return []int{2}
- }
- if x > y {
- x, y = y, x
- }
- visit, result := make(map[int]bool), make([]int, 0)
- for i := 0; ; i++ {
- found := false
- for j := 0; pow(x, i)+pow(y, j) <= bound; j++ {
- v := pow(x, i) + pow(y, j)
- if !visit[v] {
- found = true
- visit[v] = true
- result = append(result, v)
- }
- }
- if !found {
- break
- }
- }
- return result
-}
-
-func pow(x, i int) int {
- return int(math.Pow(float64(x), float64(i)))
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0973.K-Closest-Points-to-Origin.md b/website/content/ChapterFour/0973.K-Closest-Points-to-Origin.md
deleted file mode 100644
index a0b3a7608..000000000
--- a/website/content/ChapterFour/0973.K-Closest-Points-to-Origin.md
+++ /dev/null
@@ -1,71 +0,0 @@
-# [973. K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin/)
-
-## 题目
-
-We have a list of points on the plane. Find the K closest points to the origin (0, 0).
-
-(Here, the distance between two points on a plane is the Euclidean distance.)
-
-You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in.)
-
-
-**Example 1**:
-
-```
-
-Input: points = [[1,3],[-2,2]], K = 1
-Output: [[-2,2]]
-Explanation:
-The distance between (1, 3) and the origin is sqrt(10).
-The distance between (-2, 2) and the origin is sqrt(8).
-Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.
-We only want the closest K = 1 points from the origin, so the answer is just [[-2,2]].
-
-```
-
-**Example 2**:
-
-```
-
-Input: points = [[3,3],[5,-1],[-2,4]], K = 2
-Output: [[3,3],[-2,4]]
-(The answer [[-2,4],[3,3]] would also be accepted.)
-
-```
-
-**Note**:
-
-- 1 <= K <= points.length <= 10000
-- -10000 < points[i][0] < 10000
-- -10000 < points[i][1] < 10000
-
-## 题目大意
-
-找出 K 个距离坐标原点最近的坐标点。
-
-## 解题思路
-
-这题也是排序题,先将所有点距离坐标原点的距离都算出来,然后从小到大排序。取前 K 个即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-import "sort"
-
-// KClosest define
-func KClosest(points [][]int, K int) [][]int {
- sort.Slice(points, func(i, j int) bool {
- return points[i][0]*points[i][0]+points[i][1]*points[i][1] <
- points[j][0]*points[j][0]+points[j][1]*points[j][1]
- })
- ans := make([][]int, K)
- for i := 0; i < K; i++ {
- ans[i] = points[i]
- }
- return ans
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0976.Largest-Perimeter-Triangle.md b/website/content/ChapterFour/0976.Largest-Perimeter-Triangle.md
deleted file mode 100644
index 52b5b24c4..000000000
--- a/website/content/ChapterFour/0976.Largest-Perimeter-Triangle.md
+++ /dev/null
@@ -1,78 +0,0 @@
-# [976. Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle/)
-
-## 题目
-
-Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths.
-
-If it is impossible to form any triangle of non-zero area, return 0.
-
-
-**Example 1**:
-
-```
-
-Input: [2,1,2]
-Output: 5
-
-```
-
-**Example 2**:
-
-```
-
-Input: [1,2,1]
-Output: 0
-
-```
-
-**Example 3**:
-
-```
-
-Input: [3,2,3,4]
-Output: 10
-
-```
-
-**Example 4**:
-
-```
-
-Input: [3,6,2,3]
-Output: 8
-
-```
-
-**Note**:
-
-- 3 <= A.length <= 10000
-- 1 <= A[i] <= 10^6
-
-## 题目大意
-
-找到可以组成三角形三条边的长度,要求输出三条边之和最长的,即三角形周长最长。
-
-## 解题思路
-
-这道题也是排序题,先讲所有的长度进行排序,从大边开始往前找,找到第一个任意两边之和大于第三边(满足能构成三角形的条件)的下标,然后输出这 3 条边之和即可,如果没有找到输出 0 。
-
-## 代码
-
-```go
-
-package leetcode
-
-func largestPerimeter(A []int) int {
- if len(A) < 3 {
- return 0
- }
- quickSort164(A, 0, len(A)-1)
- for i := len(A) - 1; i >= 2; i-- {
- if (A[i]+A[i-1] > A[i-2]) && (A[i]+A[i-2] > A[i-1]) && (A[i-2]+A[i-1] > A[i]) {
- return A[i] + A[i-1] + A[i-2]
- }
- }
- return 0
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0977.Squares-of-a-Sorted-Array.md b/website/content/ChapterFour/0977.Squares-of-a-Sorted-Array.md
deleted file mode 100644
index 06fbd1a7d..000000000
--- a/website/content/ChapterFour/0977.Squares-of-a-Sorted-Array.md
+++ /dev/null
@@ -1,86 +0,0 @@
-# [977. Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/)
-
-## 题目
-
-Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.
-
-
-
-**Example 1**:
-
-```
-
-Input: [-4,-1,0,3,10]
-Output: [0,1,9,16,100]
-
-```
-
-**Example 2**:
-
-```
-
-Input: [-7,-3,2,3,11]
-Output: [4,9,9,49,121]
-
-```
-
-**Note**:
-
-1. 1 <= A.length <= 10000
-2. -10000 <= A[i] <= 10000
-3. A is sorted in non-decreasing order.
-
-## 题目大意
-
-给一个已经有序的数组,返回的数组也必须是有序的,且数组中的每个元素是由原数组中每个数字的平方得到的。
-
-## 解题思路
-
-这一题由于原数组是有序的,所以要尽量利用这一特点来减少时间复杂度。
-
-最终返回的数组,最后一位,是最大值,这个值应该是由原数组最大值,或者最小值得来的,所以可以从数组的最后一位开始排列最终数组。用 2 个指针分别指向原数组的首尾,分别计算平方值,然后比较两者大小,大的放在最终数组的后面。然后大的一个指针移动。直至两个指针相撞,最终数组就排列完成了。
-
-
-
-
-
-
-
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "sort"
-
-// 解法一
-func sortedSquares(A []int) []int {
- ans := make([]int, len(A))
- for i, k, j := 0, len(A)-1, len(ans)-1; i <= j; k-- {
- if A[i]*A[i] > A[j]*A[j] {
- ans[k] = A[i] * A[i]
- i++
- } else {
- ans[k] = A[j] * A[j]
- j--
- }
- }
- return ans
-}
-
-// 解法二
-func sortedSquares1(A []int) []int {
- for i, value := range A {
- A[i] = value * value
- }
- sort.Ints(A)
- return A
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0978.Longest-Turbulent-Subarray.md b/website/content/ChapterFour/0978.Longest-Turbulent-Subarray.md
deleted file mode 100755
index e4b8bea71..000000000
--- a/website/content/ChapterFour/0978.Longest-Turbulent-Subarray.md
+++ /dev/null
@@ -1,109 +0,0 @@
-# [978. Longest Turbulent Subarray](https://leetcode.com/problems/longest-turbulent-subarray/)
-
-## 题目
-
-A subarray `A[i], A[i+1], ..., A[j]` of `A` is said to be *turbulent* if and only if:
-
-- For `i <= k < j`, `A[k] > A[k+1]` when `k` is odd, and `A[k] < A[k+1]` when `k` is even;
-- **OR**, for `i <= k < j`, `A[k] > A[k+1]` when `k` is even, and `A[k] < A[k+1]` when `k` is odd.
-
-That is, the subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray.
-
-Return the **length** of a maximum size turbulent subarray of A.
-
-**Example 1**:
-
- Input: [9,4,2,10,7,8,8,1,9]
- Output: 5
- Explanation: (A[1] > A[2] < A[3] > A[4] < A[5])
-
-**Example 2**:
-
- Input: [4,8,12,16]
- Output: 2
-
-**Example 3**:
-
- Input: [100]
- Output: 1
-
-**Note**:
-
-1. `1 <= A.length <= 40000`
-2. `0 <= A[i] <= 10^9`
-
-
-## 题目大意
-
-
-当 A 的子数组 A[i], A[i+1], ..., A[j] 满足下列条件时,我们称其为湍流子数组:
-
-若 i <= k < j,当 k 为奇数时, A[k] > A[k+1],且当 k 为偶数时,A[k] < A[k+1];
-或 若 i <= k < j,当 k 为偶数时,A[k] > A[k+1] ,且当 k 为奇数时, A[k] < A[k+1]。
-也就是说,如果比较符号在子数组中的每个相邻元素对之间翻转,则该子数组是湍流子数组。
-
-返回 A 的最大湍流子数组的长度。
-
-提示:
-
-- 1 <= A.length <= 40000
-- 0 <= A[i] <= 10^9
-
-
-
-## 解题思路
-
-
-- 给出一个数组,要求找出“摆动数组”的最大长度。所谓“摆动数组”的意思是,元素一大一小间隔的。
-- 这一题可以用滑动窗口来解答。用一个变量记住下次出现的元素需要大于还是需要小于前一个元素。也可以用模拟的方法,用两个变量分别记录上升和下降数字的长度。一旦元素相等了,上升和下降数字长度都置为 1,其他时候按照上升和下降的关系增加队列长度即可,最后输出动态维护的最长长度。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 模拟法
-func maxTurbulenceSize(A []int) int {
- inc, dec := 1, 1
- maxLen := min(1, len(A))
- for i := 1; i < len(A); i++ {
- if A[i-1] < A[i] {
- inc = dec + 1
- dec = 1
- } else if A[i-1] > A[i] {
- dec = inc + 1
- inc = 1
- } else {
- inc = 1
- dec = 1
- }
- maxLen = max(maxLen, max(inc, dec))
- }
- return maxLen
-}
-
-// 解法二 滑动窗口
-func maxTurbulenceSize1(A []int) int {
- if len(A) == 1 {
- return 1
- }
- // flag > 0 代表下一个数要大于前一个数,flag < 0 代表下一个数要小于前一个数
- res, left, right, flag, lastNum := 0, 0, 0, A[1]-A[0], A[0]
- for left < len(A) {
- if right < len(A)-1 && ((A[right+1] > lastNum && flag > 0) || (A[right+1] < lastNum && flag < 0) || (right == left)) {
- right++
- flag = lastNum - A[right]
- lastNum = A[right]
- } else {
- if right != left && flag != 0 {
- res = max(res, right-left+1)
- }
- left++
- }
- }
- return max(res, 1)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0979.Distribute-Coins-in-Binary-Tree.md b/website/content/ChapterFour/0979.Distribute-Coins-in-Binary-Tree.md
deleted file mode 100755
index ac98a4523..000000000
--- a/website/content/ChapterFour/0979.Distribute-Coins-in-Binary-Tree.md
+++ /dev/null
@@ -1,96 +0,0 @@
-# [979. Distribute Coins in Binary Tree](https://leetcode.com/problems/distribute-coins-in-binary-tree/)
-
-
-## 题目
-
-Given the `root` of a binary tree with `N` nodes, each `node` in the tree has `node.val` coins, and there are `N` coins total.
-
-In one move, we may choose two adjacent nodes and move one coin from one node to another. (The move may be from parent to child, or from child to parent.)
-
-Return the number of moves required to make every node have exactly one coin.
-
-**Example 1**:
-
-
-
- Input: [3,0,0]
- Output: 2
- Explanation: From the root of the tree, we move one coin to its left child, and one coin to its right child.
-
-**Example 2**:
-
-
-
- Input: [0,3,0]
- Output: 3
- Explanation: From the left child of the root, we move two coins to the root [taking two moves]. Then, we move one coin from the root of the tree to the right child.
-
-**Example 3**:
-
-
-
- Input: [1,0,2]
- Output: 2
-
-**Example 4**:
-
-
-
- Input: [1,0,0,null,3]
- Output: 4
-
-**Note**:
-
-1. `1<= N <= 100`
-2. `0 <= node.val <= N`
-
-## 题目大意
-
-给定一个有 N 个结点的二叉树的根结点 root,树中的每个结点上都对应有 node.val 枚硬币,并且总共有 N 枚硬币。在一次移动中,我们可以选择两个相邻的结点,然后将一枚硬币从其中一个结点移动到另一个结点。(移动可以是从父结点到子结点,或者从子结点移动到父结点。)。返回使每个结点上只有一枚硬币所需的移动次数。
-
-提示:
-
-1. 1<= N <= 100
-2. 0 <= node.val <= N
-
-
-## 解题思路
-
-- 给出一棵树,有 N 个节点。有 N 个硬币分散在这 N 个节点中,问经过多少次移动以后,所有节点都有一枚硬币。
-- 这一题乍一看比较难分析,仔细一想,可以用贪心和分治的思想来解决。一个树的最小单元是一个根节点和两个孩子。在这种情况下,3 个节点谁的硬币多就可以分给没有硬币的那个节点,这种移动方法也能保证移动步数最少。不难证明,硬币由相邻的节点移动过来的步数是最少的。那么一棵树从最下一层开始往上推,逐步从下往上把硬币移动上去,直到最后根节点也都拥有硬币。多余 1 枚的节点记为 `n -1`,没有硬币的节点记为 -1 。例如,下图中左下角的 3 个节点,有 4 枚硬币的节点可以送出 3 枚硬币,叶子节点有 0 枚硬币的节点需要接收 1 枚硬币。根节点有 0 枚硬币,左孩子给了 3 枚,右孩子需要 1 枚,自己本身还要留一枚,所以最终还能剩 1 枚。
-
-
-
-- 所以每个节点移动的步数应该是 `left + right + root.Val - 1`。最后递归求解即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for a binary tree root.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-func distributeCoins(root *TreeNode) int {
- res := 0
- distributeCoinsDFS(root, &res)
- return res
-}
-
-func distributeCoinsDFS(root *TreeNode, res *int) int {
- if root == nil {
- return 0
- }
- left, right := distributeCoinsDFS(root.Left, res), distributeCoinsDFS(root.Right, res)
- *res += abs(left) + abs(right)
- return left + right + root.Val - 1
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0981.Time-Based-Key-Value-Store.md b/website/content/ChapterFour/0981.Time-Based-Key-Value-Store.md
deleted file mode 100755
index a598ed752..000000000
--- a/website/content/ChapterFour/0981.Time-Based-Key-Value-Store.md
+++ /dev/null
@@ -1,124 +0,0 @@
-# [981. Time Based Key-Value Store](https://leetcode.com/problems/time-based-key-value-store/)
-
-
-## 题目
-
-Create a timebased key-value store class `TimeMap`, that supports two operations.
-
-1. `set(string key, string value, int timestamp)`
-
-- Stores the `key` and `value`, along with the given `timestamp`.
-
-2. `get(string key, int timestamp)`
-
-- Returns a value such that `set(key, value, timestamp_prev)` was called previously, with `timestamp_prev <= timestamp`.
-- If there are multiple such values, it returns the one with the largest `timestamp_prev`.
-- If there are no values, it returns the empty string (`""`).
-
-**Example 1**:
-
- Input: inputs = ["TimeMap","set","get","get","set","get","get"], inputs = [[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]
- Output: [null,null,"bar","bar",null,"bar2","bar2"]
- Explanation:
- TimeMap kv;
- kv.set("foo", "bar", 1); // store the key "foo" and value "bar" along with timestamp = 1
- kv.get("foo", 1); // output "bar"
- kv.get("foo", 3); // output "bar" since there is no value corresponding to foo at timestamp 3 and timestamp 2, then the only value is at timestamp 1 ie "bar"
- kv.set("foo", "bar2", 4);
- kv.get("foo", 4); // output "bar2"
- kv.get("foo", 5); //output "bar2"
-
-**Example 2**:
-
- Input: inputs = ["TimeMap","set","set","get","get","get","get","get"], inputs = [[],["love","high",10],["love","low",20],["love",5],["love",10],["love",15],["love",20],["love",25]]
- Output: [null,null,null,"","high","high","low","low"]
-
-**Note**:
-
-1. All key/value strings are lowercase.
-2. All key/value strings have length in the range `[1, 100]`
-3. The `timestamps` for all `TimeMap.set` operations are strictly increasing.
-4. `1 <= timestamp <= 10^7`
-5. `TimeMap.set` and `TimeMap.get` functions will be called a total of `120000` times (combined) per test case.
-
-## 题目大意
-
-创建一个基于时间的键值存储类 TimeMap,它支持下面两个操作:
-
-1. set(string key, string value, int timestamp)
-
-- 存储键 key、值 value,以及给定的时间戳 timestamp。
-
-2. get(string key, int timestamp)
-
-- 返回先前调用 set(key, value, timestamp_prev) 所存储的值,其中 timestamp_prev <= timestamp。
-- 如果有多个这样的值,则返回对应最大的 timestamp_prev 的那个值。
-- 如果没有值,则返回空字符串("")。
-
-提示:
-
-1. 所有的键/值字符串都是小写的。
-2. 所有的键/值字符串长度都在 [1, 100] 范围内。
-3. 所有 TimeMap.set 操作中的时间戳 timestamps 都是严格递增的。
-4. 1 <= timestamp <= 10^7
-5. TimeMap.set 和 TimeMap.get 函数在每个测试用例中将(组合)调用总计 120000 次。
-
-
-## 解题思路
-
-- 要求设计一个基于时间戳的 `kv` 存储。`set()` 操作里面会会包含一个时间戳。get() 操作的时候查找时间戳小于等于 `timestamp` 的 `key` 对应的 `value`,如果有多个解,输出满足条件的最大时间戳对应的 `value` 值。
-- 这一题可以用二分搜索来解答,用 `map` 存储 `kv` 数据,`key` 对应的就是 `key`,`value` 对应一个结构体,里面包含 `value` 和 `timestamp`。执行 `get()` 操作的时候,先取出 `key` 对应的结构体数组,然后在这个数组里面根据 `timestamp` 进行二分搜索。由于题意是要找小于等于 `timestamp` 的最大 `timestamp` ,这会有很多满足条件的解,变换一下,先找 `> timestamp` 的最小解,然后下标减一即是满足题意的最大解。
-- 另外题目中提到“`TimeMap.set` 操作中的 `timestamp` 是严格递增的”。所以在 `map` 中存储 `value` 结构体的时候,不需要排序了,天然有序。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "sort"
-
-type data struct {
- time int
- value string
-}
-
-// TimeMap is a timebased key-value store
-// TimeMap define
-type TimeMap map[string][]data
-
-// Constructor981 define
-func Constructor981() TimeMap {
- return make(map[string][]data, 1024)
-}
-
-// Set define
-func (t TimeMap) Set(key string, value string, timestamp int) {
- if _, ok := t[key]; !ok {
- t[key] = make([]data, 1, 1024)
- }
- t[key] = append(t[key], data{
- time: timestamp,
- value: value,
- })
-}
-
-// Get define
-func (t TimeMap) Get(key string, timestamp int) string {
- d := t[key]
- i := sort.Search(len(d), func(i int) bool {
- return timestamp < d[i].time
- })
- i--
- return t[key][i].value
-}
-
-/**
- * Your TimeMap object will be instantiated and called as such:
- * obj := Constructor();
- * obj.Set(key,value,timestamp);
- * param_2 := obj.Get(key,timestamp);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0984.String-Without-AAA-or-BBB.md b/website/content/ChapterFour/0984.String-Without-AAA-or-BBB.md
deleted file mode 100755
index cccb67b22..000000000
--- a/website/content/ChapterFour/0984.String-Without-AAA-or-BBB.md
+++ /dev/null
@@ -1,93 +0,0 @@
-# [984. String Without AAA or BBB](https://leetcode.com/problems/string-without-aaa-or-bbb/)
-
-
-## 题目
-
-Given two integers `A` and `B`, return **any** string `S` such that:
-
-- `S` has length `A + B` and contains exactly `A` `'a'` letters, and exactly `B` `'b'`letters;
-- The substring `'aaa'` does not occur in `S`;
-- The substring `'bbb'` does not occur in `S`.
-
-**Example 1**:
-
- Input: A = 1, B = 2
- Output: "abb"
- Explanation: "abb", "bab" and "bba" are all correct answers.
-
-**Example 2**:
-
- Input: A = 4, B = 1
- Output: "aabaa"
-
-**Note**:
-
-1. `0 <= A <= 100`
-2. `0 <= B <= 100`
-3. It is guaranteed such an `S` exists for the given `A` and `B`.
-
-
-## 题目大意
-
-给定两个整数 A 和 B,返回任意字符串 S,要求满足:
-
-- S 的长度为 A + B,且正好包含 A 个 'a' 字母与 B 个 'b' 字母;
-- 子串 'aaa' 没有出现在 S 中;
-- 子串 'bbb' 没有出现在 S 中。
-
-
-提示:
-
-- 0 <= A <= 100
-- 0 <= B <= 100
-- 对于给定的 A 和 B,保证存在满足要求的 S。
-
-
-## 解题思路
-
-
-- 给出 A 和 B 的个数,要求组合出字符串,不能出现 3 个连续的 A 和 3 个连续的 B。这题由于只可能有 4 种情况,暴力枚举就可以了。假设 B 的个数比 A 多(如果 A 多,就交换一下 A 和 B),最终可能的情况只可能是这 4 种情况中的一种: `ba`,`bbabb`,`bbabbabb`,`bbabbabbabbabababa`。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func strWithout3a3b(A int, B int) string {
- ans, a, b := "", "a", "b"
- if B < A {
- A, B = B, A
- a, b = b, a
- }
- Dif := B - A
- if A == 1 && B == 1 { // ba
- ans = b + a
- } else if A == 1 && B < 5 { // bbabb
- for i := 0; i < B-2; i++ {
- ans = ans + b
- }
- ans = b + b + a + ans
- } else if (B-A)/A >= 1 { //bbabbabb
- for i := 0; i < A; i++ {
- ans = ans + b + b + a
- B = B - 2
- }
- for i := 0; i < B; i++ {
- ans = ans + b
- }
- } else { //bbabbabbabbabababa
- for i := 0; i < Dif; i++ {
- ans = ans + b + b + a
- B -= 2
- A--
- }
- for i := 0; i < B; i++ {
- ans = ans + b + a
- }
- }
- return ans
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0985.Sum-of-Even-Numbers-After-Queries.md b/website/content/ChapterFour/0985.Sum-of-Even-Numbers-After-Queries.md
deleted file mode 100644
index 8811079ba..000000000
--- a/website/content/ChapterFour/0985.Sum-of-Even-Numbers-After-Queries.md
+++ /dev/null
@@ -1,72 +0,0 @@
-# [985. Sum of Even Numbers After Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries/)
-
-## 题目
-
-We have an array `A` of integers, and an array `queries` of queries.
-
-For the `i`-th query `val = queries[i][0], index = queries[i][1]`, we add val to `A[index]`. Then, the answer to the `i`-th query is the sum of the even values of `A`.
-
-*(Here, the given `index = queries[i][1]` is a 0-based index, and each query permanently modifies the array `A`.)*
-
-Return the answer to all queries. Your `answer` array should have `answer[i]` as the answer to the `i`-th query.
-
-**Example 1**:
-
-```
-Input: A = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]
-Output: [8,6,2,4]
-Explanation:
-At the beginning, the array is [1,2,3,4].
-After adding 1 to A[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.
-After adding -3 to A[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.
-After adding -4 to A[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.
-After adding 2 to A[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.
-```
-
-**Note**:
-
-1. `1 <= A.length <= 10000`
-2. `-10000 <= A[i] <= 10000`
-3. `1 <= queries.length <= 10000`
-4. `-10000 <= queries[i][0] <= 10000`
-5. `0 <= queries[i][1] < A.length`
-
-## 题目大意
-
-给出一个整数数组 A 和一个查询数组 queries。
-
-对于第 i 次查询,有 val = queries[i][0], index = queries[i][1],我们会把 val 加到 A[index] 上。然后,第 i 次查询的答案是 A 中偶数值的和。(此处给定的 index = queries[i][1] 是从 0 开始的索引,每次查询都会永久修改数组 A。)返回所有查询的答案。你的答案应当以数组 answer 给出,answer[i] 为第 i 次查询的答案。
-
-
-## 解题思路
-
-- 给出一个数组 A 和 query 数组。要求每次 query 操作都改变数组 A 中的元素值,并计算此次操作结束数组 A 中偶数值之和。
-- 简单题,先计算 A 中所有偶数之和。再每次 query 操作的时候,动态维护这个偶数之和即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func sumEvenAfterQueries(A []int, queries [][]int) []int {
- cur, res := 0, []int{}
- for _, v := range A {
- if v%2 == 0 {
- cur += v
- }
- }
- for _, q := range queries {
- if A[q[1]]%2 == 0 {
- cur -= A[q[1]]
- }
- A[q[1]] += q[0]
- if A[q[1]]%2 == 0 {
- cur += A[q[1]]
- }
- res = append(res, cur)
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0986.Interval-List-Intersections.md b/website/content/ChapterFour/0986.Interval-List-Intersections.md
deleted file mode 100644
index d1a463415..000000000
--- a/website/content/ChapterFour/0986.Interval-List-Intersections.md
+++ /dev/null
@@ -1,73 +0,0 @@
-# [986. Interval List Intersections](https://leetcode.com/problems/interval-list-intersections/)
-
-## 题目
-
-Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
-
-Return the intersection of these two interval lists.
-
-(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b. The intersection of two closed intervals is a set of real numbers that is either empty, or can be represented as a closed interval. For example, the intersection of [1, 3] and [2, 4] is [2, 3].)
-
-
-
-
-**Example 1**:
-
-
-
-```
-Input: A = [[0,2],[5,10],[13,23],[24,25]], B = [[1,5],[8,12],[15,24],[25,26]]
-Output: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
-Reminder: The inputs and the desired output are lists of Interval objects, and not arrays or lists.
-```
-
-**Note**:
-
-- 0 <= A.length < 1000
-- 0 <= B.length < 1000
-- 0 <= A[i].start, A[i].end, B[i].start, B[i].end < 10^9
-
-**Note**: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.
-
-## 题目大意
-
-这道题考察的是滑动窗口的问题。
-
-给出 2 个数组 A 和数组 B。要求求出这 2 个数组的交集数组。题意见图。
-
-## 解题思路
-
-交集的左边界应该为,`start := max(A[i].Start, B[j].Start)`,右边界为,`end := min(A[i].End, B[j].End)`,如果 `start <= end`,那么这个就是一个满足条件的交集,放入最终数组中。如果 `A[i].End <= B[j].End`,代表 B 数组范围比 A 数组大,A 的游标右移。如果 `A[i].End > B[j].End`,代表 A 数组范围比 B 数组大,B 的游标右移。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for an interval.
- * type Interval struct {
- * Start int
- * End int
- * }
- */
-func intervalIntersection(A []Interval, B []Interval) []Interval {
- res := []Interval{}
- for i, j := 0, 0; i < len(A) && j < len(B); {
- start := max(A[i].Start, B[j].Start)
- end := min(A[i].End, B[j].End)
- if start <= end {
- res = append(res, Interval{Start: start, End: end})
- }
- if A[i].End <= B[j].End {
- i++
- } else {
- j++
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0990.Satisfiability-of-Equality-Equations.md b/website/content/ChapterFour/0990.Satisfiability-of-Equality-Equations.md
deleted file mode 100755
index 75f33db2c..000000000
--- a/website/content/ChapterFour/0990.Satisfiability-of-Equality-Equations.md
+++ /dev/null
@@ -1,99 +0,0 @@
-# [990. Satisfiability of Equality Equations](https://leetcode.com/problems/satisfiability-of-equality-equations/)
-
-
-## 题目
-
-Given an array equations of strings that represent relationships between variables, each string `equations[i]` has length `4` and takes one of two different forms: `"a==b"` or `"a!=b"`. Here, `a` and `b` are lowercase letters (not necessarily different) that represent one-letter variable names.
-
-Return `true` if and only if it is possible to assign integers to variable names so as to satisfy all the given equations.
-
-**Example 1**:
-
- Input: ["a==b","b!=a"]
- Output: false
- Explanation: If we assign say, a = 1 and b = 1, then the first equation is satisfied, but not the second. There is no way to assign the variables to satisfy both equations.
-
-**Example 2**:
-
- Input: ["b==a","a==b"]
- Output: true
- Explanation: We could assign a = 1 and b = 1 to satisfy both equations.
-
-**Example 3**:
-
- Input: ["a==b","b==c","a==c"]
- Output: true
-
-**Example 4**:
-
- Input: ["a==b","b!=c","c==a"]
- Output: false
-
-**Example 5**:
-
- Input: ["c==c","b==d","x!=z"]
- Output: true
-
-**Note**:
-
-1. `1 <= equations.length <= 500`
-2. `equations[i].length == 4`
-3. `equations[i][0]` and `equations[i][3]` are lowercase letters
-4. `equations[i][1]` is either `'='` or `'!'`
-5. `equations[i][2]` is `'='`
-
-
-
-## 题目大意
-
-给定一个由表示变量之间关系的字符串方程组成的数组,每个字符串方程 equations[i] 的长度为 4,并采用两种不同的形式之一:"a==b" 或 "a!=b"。在这里,a 和 b 是小写字母(不一定不同),表示单字母变量名。只有当可以将整数分配给变量名,以便满足所有给定的方程时才返回 true,否则返回 false。
-
-提示:
-
-1. 1 <= equations.length <= 500
-2. equations[i].length == 4
-3. equations[i][0] 和 equations[i][3] 是小写字母
-4. equations[i][1] 要么是 '=',要么是 '!'
-5. equations[i][2] 是 '='
-
-
-
-## 解题思路
-
-
-- 给出一个字符串数组,数组里面给出的是一些字母的关系,只有 `'=='` 和 `'! ='` 两种关系。问给出的这些关系中是否存在悖论?
-- 这一题是简单的并查集的问题。先将所有 `'=='` 关系的字母 `union()` 起来,然后再一一查看 `'! ='` 关系中是否有 `'=='` 关系的组合,如果有,就返回 `false`,如果遍历完都没有找到,则返回 `true`。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func equationsPossible(equations []string) bool {
- if len(equations) == 0 {
- return false
- }
- uf := template.UnionFind{}
- uf.Init(26)
- for _, equ := range equations {
- if equ[1] == '=' && equ[2] == '=' {
- uf.Union(int(equ[0]-'a'), int(equ[3]-'a'))
- }
- }
- for _, equ := range equations {
- if equ[1] == '!' && equ[2] == '=' {
- if uf.Find(int(equ[0]-'a')) == uf.Find(int(equ[3]-'a')) {
- return false
- }
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0992.Subarrays-with-K-Different-Integers.md b/website/content/ChapterFour/0992.Subarrays-with-K-Different-Integers.md
deleted file mode 100644
index 33155fa22..000000000
--- a/website/content/ChapterFour/0992.Subarrays-with-K-Different-Integers.md
+++ /dev/null
@@ -1,113 +0,0 @@
-# [992. Subarrays with K Different Integers](https://leetcode.com/problems/subarrays-with-k-different-integers/)
-
-## 题目
-
-Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
-
-(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
-
-Return the number of good subarrays of A.
-
-
-**Example 1**:
-
-```
-
-Input: A = [1,2,1,2,3], K = 2
-Output: 7
-Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
-
-```
-
-**Example 2**:
-
-```
-
-Input: A = [1,2,1,3,4], K = 3
-Output: 3
-Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
-
-```
-
-**Note**:
-
-- 1 <= A.length <= 20000
-- 1 <= A[i] <= A.length
-- 1 <= K <= A.length
-
-## 题目大意
-
-这道题考察的是滑动窗口的问题。
-
-给出一个数组 和 K,K 代表窗口能能包含的不同数字的个数。K = 2 代表窗口内只能有 2 个不同的数字。求数组中满足条件 K 的窗口个数。
-
-## 解题思路
-
-如果只是单纯的滑动窗口去做,会错过一些解。比如在例子 1 中,滑动窗口可以得到 [1,2], [1,2,1], [1,2,1,2], [2,1,2], [1,2], [2,3], 会少 [2,1] 这个解,原因是右边窗口滑动到最右边了,左边窗口在缩小的过程中,右边窗口不会再跟着动了。有同学可能会说,每次左边窗口移动的时候,右边窗口都再次从左边窗口的位置开始重新滑动。这样做确实可以,但是这样做完会发现超时。因为中间包含大量的重复计算。
-
-这道题就需要第 3 个指针。原有滑动窗口的 2 个指针,右窗口保留这个窗口里面最长的子数组,正好有 K 个元素,左窗口右移的逻辑不变。再多用一个指针用来标识正好有 K - 1 个元素的位置。那么正好有 K 个不同元素的解就等于 ans = atMostK(A, K) - atMostK(A, K - 1)。最多有 K 个元素减去最多有 K - 1 个元素得到的窗口中正好有 K 个元素的解。
-
-以例子 1 为例,先求最多有 K 个元素的窗口个数。
-
-```c
-[1]
-[1,2], [2]
-[1,2,1], [2,1], [1]
-[1,2,1,2], [2,1,2], [1,2], [2]
-[2,3], [3]
-```
-
-每当窗口滑动到把 K 消耗为 0 的时候,res = right - left + 1 。为什么要这么计算,right - left + 1 代表的含义是,终点为 right,至多为 K 个元素的窗口有多少个。[left,right], [left + 1,right], [left + 2,right] …… [right,right]。这样算出来的解是包含这道题最终求得的解的,还多出了一部分解。多出来的部分减掉即可,即减掉最多为 K - 1 个元素的解。
-
-最多为 K - 1 个元素的解如下:
-
-```c
-[1]
-[2]
-[1]
-[2]
-[3]
-```
-
-两者相减以后得到的结果就是最终结果:
-
-```c
-[1,2]
-[1,2,1], [2,1]
-[1,2,1,2], [2,1,2], [1,2]
-[2,3]
-```
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func subarraysWithKDistinct(A []int, K int) int {
- return subarraysWithKDistinctSlideWindow(A, K) - subarraysWithKDistinctSlideWindow(A, K-1)
-}
-
-func subarraysWithKDistinctSlideWindow(A []int, K int) int {
- left, right, counter, res, freq := 0, 0, K, 0, map[int]int{}
- for right = 0; right < len(A); right++ {
- if freq[A[right]] == 0 {
- counter--
- }
- freq[A[right]]++
- for counter < 0 {
- freq[A[left]]--
- if freq[A[left]] == 0 {
- counter++
- }
- left++
- }
- res += right - left + 1
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0993.Cousins-in-Binary-Tree.md b/website/content/ChapterFour/0993.Cousins-in-Binary-Tree.md
deleted file mode 100755
index 1fd4a366a..000000000
--- a/website/content/ChapterFour/0993.Cousins-in-Binary-Tree.md
+++ /dev/null
@@ -1,163 +0,0 @@
-# [993. Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree/)
-
-## 题目
-
-In a binary tree, the root node is at depth `0`, and children of each depth `k` node are at depth `k+1`.
-
-Two nodes of a binary tree are *cousins* if they have the same depth, but have **different parents**.
-
-We are given the `root` of a binary tree with unique values, and the values `x` and `y` of two different nodes in the tree.
-
-Return `true` if and only if the nodes corresponding to the values `x` and `y` are cousins.
-
-**Example 1**:
-
-
-
- Input: root = [1,2,3,4], x = 4, y = 3
- Output: false
-
-**Example 2**:
-
-
-
- Input: root = [1,2,3,null,4,null,5], x = 5, y = 4
- Output: true
-
-**Example 3**:
-
-
-
- Input: root = [1,2,3,null,4], x = 2, y = 3
- Output: false
-
-**Note**:
-
-1. The number of nodes in the tree will be between `2` and `100`.
-2. Each node has a unique integer value from `1` to `100`.
-
-
-## 题目大意
-
-在二叉树中,根节点位于深度 0 处,每个深度为 k 的节点的子节点位于深度 k+1 处。如果二叉树的两个节点深度相同,但父节点不同,则它们是一对堂兄弟节点。我们给出了具有唯一值的二叉树的根节点 root,以及树中两个不同节点的值 x 和 y。只有与值 x 和 y 对应的节点是堂兄弟节点时,才返回 true。否则,返回 false。
-
-
-
-## 解题思路
-
-
-- 给出一个二叉树,和 x ,y 两个值,要求判断这两个值是不是兄弟结点。兄弟结点的定义:都位于同一层,并且父结点是同一个结点。
-- 这一题有 3 种解题方法,DFS、BFS、递归。思路都不难。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-
-// 解法一 递归
-func isCousins(root *TreeNode, x int, y int) bool {
- if root == nil {
- return false
- }
- levelX, levelY := findLevel(root, x, 1), findLevel(root, y, 1)
- if levelX != levelY {
- return false
- }
- return !haveSameParents(root, x, y)
-}
-
-func findLevel(root *TreeNode, x, level int) int {
- if root == nil {
- return 0
- }
- if root.Val != x {
- leftLevel, rightLevel := findLevel(root.Left, x, level+1), findLevel(root.Right, x, level+1)
- if leftLevel == 0 {
- return rightLevel
- }
- return leftLevel
- }
- return level
-}
-
-func haveSameParents(root *TreeNode, x, y int) bool {
- if root == nil {
- return false
- }
- if (root.Left != nil && root.Right != nil && root.Left.Val == x && root.Right.Val == y) ||
- (root.Left != nil && root.Right != nil && root.Left.Val == y && root.Right.Val == x) {
- return true
- }
- return haveSameParents(root.Left, x, y) || haveSameParents(root.Right, x, y)
-}
-
-// 解法二 BFS
-type mark struct {
- prev int
- depth int
-}
-
-func isCousinsBFS(root *TreeNode, x int, y int) bool {
- if root == nil {
- return false
- }
- queue := []*TreeNode{root}
- visited := [101]*mark{}
- visited[root.Val] = &mark{prev: -1, depth: 1}
-
- for len(queue) > 0 {
- node := queue[0]
- queue = queue[1:]
- depth := visited[node.Val].depth
- if node.Left != nil {
- visited[node.Left.Val] = &mark{prev: node.Val, depth: depth + 1}
- queue = append(queue, node.Left)
- }
- if node.Right != nil {
- visited[node.Right.Val] = &mark{prev: node.Val, depth: depth + 1}
- queue = append(queue, node.Right)
- }
- }
- if visited[x] == nil || visited[y] == nil {
- return false
- }
- if visited[x].depth == visited[y].depth && visited[x].prev != visited[y].prev {
- return true
- }
- return false
-}
-
-// 解法三 DFS
-func isCousinsDFS(root *TreeNode, x int, y int) bool {
- var depth1, depth2, parent1, parent2 int
- dfsCousins(root, x, 0, -1, &parent1, &depth1)
- dfsCousins(root, y, 0, -1, &parent2, &depth2)
- return depth1 > 1 && depth1 == depth2 && parent1 != parent2
-}
-
-func dfsCousins(root *TreeNode, val, depth, last int, parent, res *int) {
- if root == nil {
- return
- }
- if root.Val == val {
- *res = depth
- *parent = last
- return
- }
- depth++
- dfsCousins(root.Left, val, depth, root.Val, parent, res)
- dfsCousins(root.Right, val, depth, root.Val, parent, res)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md b/website/content/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md
deleted file mode 100755
index 768d37be9..000000000
--- a/website/content/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md
+++ /dev/null
@@ -1,97 +0,0 @@
-# [995. Minimum Number of K Consecutive Bit Flips](https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips/)
-
-
-## 题目
-
-In an array `A` containing only 0s and 1s, a `K`-bit flip consists of choosing a (contiguous) subarray of length `K` and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
-
-Return the minimum number of `K`-bit flips required so that there is no 0 in the array. If it is not possible, return `-1`.
-
-**Example 1**:
-
- Input: A = [0,1,0], K = 1
- Output: 2
- Explanation: Flip A[0], then flip A[2].
-
-**Example 2**:
-
- Input: A = [1,1,0], K = 2
- Output: -1
- Explanation: No matter how we flip subarrays of size 2, we can't make the array become [1,1,1].
-
-**Example 3**:
-
- Input: A = [0,0,0,1,0,1,1,0], K = 3
- Output: 3
- Explanation:
- Flip A[0],A[1],A[2]: A becomes [1,1,1,1,0,1,1,0]
- Flip A[4],A[5],A[6]: A becomes [1,1,1,1,1,0,0,0]
- Flip A[5],A[6],A[7]: A becomes [1,1,1,1,1,1,1,1]
-
-**Note**:
-
-1. `1 <= A.length <= 30000`
-2. `1 <= K <= A.length`
-
-
-## 题目大意
-
-在仅包含 0 和 1 的数组 A 中,一次 K 位翻转包括选择一个长度为 K 的(连续)子数组,同时将子数组中的每个 0 更改为 1,而每个 1 更改为 0。返回所需的 K 位翻转的次数,以便数组没有值为 0 的元素。如果不可能,返回 -1。
-
-提示:
-
-1. 1 <= A.length <= 30000
-2. 1 <= K <= A.length
-
-
-## 解题思路
-
-
-- 给出一个数组,数组里面的元素只有 0 和 1。给一个长度为 K 的窗口,在这个窗口内的所有元素都会 0-1 翻转。问最后需要翻转几次,使得整个数组都为 1 。如果不能翻转使得最后数组元素都为 1,则输出 -1。
-- 拿到这一题首先想到的是贪心算法。例如第 765 题,这类题的描述都是这样的:在一个数组中或者环形数组中通过交换位置,或者翻转变换,达到最终结果,要求找到最少步数。贪心能保证是最小步数(证明略)。按照贪心的思想,这一题也这样做,从数组 0 下标开始往后扫,依次翻转每个 K 大小的窗口内元素。
-- 由于窗口大小限制了,所以这题滑动窗口只需要一个边界坐标,用左边界就可以判断了。每一个 `A[i]` 是否需要翻转,是由于 `[ i-k+1,i ]`、`[ i-k+2,i+1 ]`、`[ i-k+3,i+2 ]`……`[ i-1,i+k ]` 这一系列的窗口翻转`累积影响`的。那如何之前这些窗口`累积`到 `A[i]` 上翻转的次数呢?可以动态的维护一个翻转次数,当 `i` 摆脱了上一次翻转窗口 `K` 的时候,翻转次数就 `-1` 。举个例子:
-
- A = [0 0 0 1 0 1 1 0] K = 3
-
- A = [2 0 0 1 0 1 1 0] i = 0 flippedTime = 1
- A = [2 0 0 1 0 1 1 0] i = 1 flippedTime = 1
- A = [2 0 0 1 0 1 1 0] i = 2 flippedTime = 1
- A = [2 0 0 1 0 1 1 0] i = 3 flippedTime = 0
- A = [2 0 0 1 2 1 1 0] i = 4 flippedTime = 1
- A = [2 0 0 1 2 2 1 0] i = 5 flippedTime = 2
- A = [2 0 0 1 2 2 1 0] i = 6 flippedTime = 2
- A = [2 0 0 1 2 2 1 0] i = 7 flippedTime = 1
-
- 当判断 `A[i]` 是否需要翻转的时候,只需要留意每个宽度为 `K` 窗口的左边界。会影响到 A[i] 的窗口的左边界分别是 `i-k+1`、`i-k+2`、`i-k+3`、…… `i-1`,只需要分别看这些窗口有没有翻转就行。这里可以用特殊标记来记录这些窗口的左边界是否被翻转了。如果翻转过,则把窗口左边界的那个数字标记为 2 (为什么要标记为 2 呢?其实设置成什么都可以,只要不是 0 和 1 ,和原有的数字区分开就行)。当 `i≥k` 的时候,代表 `i` 已经脱离了 `i-k` 的这个窗口,因为能影响 `A[i]` 的窗口是从 `i-k+1` 开始的,如果 `A[i-k] == 2` 代表 `i-k` 窗口已经翻转过了,现在既然脱离了它的窗口影响,那么就要把累积的 `flippedTime - 1` 。这样就维护了累积 `flippedTime` 和滑动窗口中累积影响的关系。
-
-- 接下来还需要处理的是 `flippedTime` 与当前 `A[i]` 是否翻转的问题。如果 `flippedTime` 是偶数次,原来的 0 还是 0,就需要再次翻转,如果 `flippedTime` 是奇数次,原来的 0 变成了 1 就不需要翻转了。总结成一条结论就是 `A[i]` 与 `flippedTime` 同奇偶性的时候就要翻转。当 `i + K` 比 `len(A)` 大的时候,代表剩下的这些元素肯定不能在一个窗口里面翻转,则输出 -1 。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func minKBitFlips(A []int, K int) int {
- flippedTime, count := 0, 0
- for i := 0; i < len(A); i++ {
- if i >= K && A[i-K] == 2 {
- flippedTime--
- }
- // 下面这个判断包含了两种情况:
- // 如果 flippedTime 是奇数,且 A[i] == 1 就需要翻转
- // 如果 flippedTime 是偶数,且 A[i] == 0 就需要翻转
- if flippedTime%2 == A[i] {
- if i+K > len(A) {
- return -1
- }
- A[i] = 2
- flippedTime++
- count++
- }
- }
- return count
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0996.Number-of-Squareful-Arrays.md b/website/content/ChapterFour/0996.Number-of-Squareful-Arrays.md
deleted file mode 100755
index 5a420a2c0..000000000
--- a/website/content/ChapterFour/0996.Number-of-Squareful-Arrays.md
+++ /dev/null
@@ -1,107 +0,0 @@
-# [996. Number of Squareful Arrays](https://leetcode.com/problems/number-of-squareful-arrays/)
-
-
-
-## 题目
-
-Given an array `A` of non-negative integers, the array is *squareful* if for every pair of adjacent elements, their sum is a perfect square.
-
-Return the number of permutations of A that are squareful. Two permutations `A1` and `A2` differ if and only if there is some index `i` such that `A1[i] != A2[i]`.
-
-**Example 1**:
-
- Input: [1,17,8]
- Output: 2
- Explanation:
- [1,8,17] and [17,8,1] are the valid permutations.
-
-**Example 2**:
-
- Input: [2,2,2]
- Output: 1
-
-**Note**:
-
-1. `1 <= A.length <= 12`
-2. `0 <= A[i] <= 1e9`
-
-
-## 题目大意
-
-给定一个非负整数数组 A,如果该数组每对相邻元素之和是一个完全平方数,则称这一数组为正方形数组。
-
-返回 A 的正方形排列的数目。两个排列 A1 和 A2 不同的充要条件是存在某个索引 i,使得 A1[i] != A2[i]。
-
-
-
-## 解题思路
-
-
-- 这一题是第 47 题的加强版。第 47 题要求求出一个数组的所有不重复的排列。这一题要求求出一个数组的所有不重复,且相邻两个数字之和都为完全平方数的排列。
-- 思路和第 47 题完全一致,只不过增加判断相邻两个数字之和为完全平方数的判断,注意在 DFS 的过程中,需要剪枝,否则时间复杂度很高,会超时。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
- "sort"
-)
-
-func numSquarefulPerms(A []int) int {
- if len(A) == 0 {
- return 0
- }
- used, p, res := make([]bool, len(A)), []int{}, [][]int{}
- sort.Ints(A) // 这里是去重的关键逻辑
- generatePermutation996(A, 0, p, &res, &used)
- return len(res)
-}
-
-func generatePermutation996(nums []int, index int, p []int, res *[][]int, used *[]bool) {
- if index == len(nums) {
- checkSquareful := true
- for i := 0; i < len(p)-1; i++ {
- if !checkSquare(p[i] + p[i+1]) {
- checkSquareful = false
- break
- }
- }
- if checkSquareful {
- temp := make([]int, len(p))
- copy(temp, p)
- *res = append(*res, temp)
- }
- return
- }
- for i := 0; i < len(nums); i++ {
- if !(*used)[i] {
- if i > 0 && nums[i] == nums[i-1] && !(*used)[i-1] { // 这里是去重的关键逻辑
- continue
- }
- if len(p) > 0 && !checkSquare(nums[i]+p[len(p)-1]) { // 关键的剪枝条件
- continue
- }
- (*used)[i] = true
- p = append(p, nums[i])
- generatePermutation996(nums, index+1, p, res, used)
- p = p[:len(p)-1]
- (*used)[i] = false
- }
- }
- return
-}
-
-func checkSquare(num int) bool {
- tmp := math.Sqrt(float64(num))
- if int(tmp)*int(tmp) == num {
- return true
- }
- return false
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/0999.Available-Captures-for-Rook.md b/website/content/ChapterFour/0999.Available-Captures-for-Rook.md
deleted file mode 100644
index 47e6d127e..000000000
--- a/website/content/ChapterFour/0999.Available-Captures-for-Rook.md
+++ /dev/null
@@ -1,99 +0,0 @@
-# [999. Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook/)
-
-
-## 题目
-
-On an 8 x 8 chessboard, there is one white rook. There also may be empty squares, white bishops, and black pawns. These are given as characters 'R', '.', 'B', and 'p' respectively. Uppercase characters represent white pieces, and lowercase characters represent black pieces.
-
-The rook moves as in the rules of Chess: it chooses one of four cardinal directions (north, east, west, and south), then moves in that direction until it chooses to stop, reaches the edge of the board, or captures an opposite colored pawn by moving to the same square it occupies. Also, rooks cannot move into the same square as other friendly bishops.
-
-Return the number of pawns the rook can capture in one move.
-
-**Example 1**:
-
-
-
-```
-Input: [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
-Output: 3
-Explanation:
-In this example the rook is able to capture all the pawns.
-```
-
-**Example 2**:
-
-
-
-```
-Input: [[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
-Output: 0
-Explanation:
-Bishops are blocking the rook to capture any pawn.
-```
-
-**Example 3**:
-
-
-
-```
-Input: [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]
-Output: 3
-Explanation:
-The rook can capture the pawns at positions b5, d6 and f5.
-```
-
-**Note**:
-
-1. `board.length == board[i].length == 8`
-2. `board[i][j]` is either `'R'`, `'.'`, `'B'`, or `'p'`
-3. There is exactly one cell with `board[i][j] == 'R'`
-
-## 题目大意
-
-在一个 8 x 8 的棋盘上,有一个白色的车(Rook),用字符 'R' 表示。棋盘上还可能存在空方块,白色的象(Bishop)以及黑色的卒(pawn),分别用字符 '.','B' 和 'p' 表示。不难看出,大写字符表示的是白棋,小写字符表示的是黑棋。车按国际象棋中的规则移动。东,西,南,北四个基本方向任选其一,然后一直向选定的方向移动,直到满足下列四个条件之一:
-
-- 棋手选择主动停下来。
-- 棋子因到达棋盘的边缘而停下。
-- 棋子移动到某一方格来捕获位于该方格上敌方(黑色)的卒,停在该方格内。
-- 车不能进入/越过已经放有其他友方棋子(白色的象)的方格,停在友方棋子前。
-
-你现在可以控制车移动一次,请你统计有多少敌方的卒处于你的捕获范围内(即,可以被一步捕获的棋子数)。
-
-## 解题思路
-
-- 按照国际象棋的规则移动车,要求输出只移动一次,有多少个卒在车的捕获范围之内
-- 简单题,按照国际象棋车的移动规则, 4 个方向分别枚举即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func numRookCaptures(board [][]byte) int {
- num := 0
- for i := 0; i < len(board); i++ {
- for j := 0; j < len(board[i]); j++ {
- if board[i][j] == 'R' {
- num += caputure(board, i-1, j, -1, 0) // Up
- num += caputure(board, i+1, j, 1, 0) // Down
- num += caputure(board, i, j-1, 0, -1) // Left
- num += caputure(board, i, j+1, 0, 1) // Right
- }
- }
- }
- return num
-}
-
-func caputure(board [][]byte, x, y int, bx, by int) int {
- for x >= 0 && x < len(board) && y >= 0 && y < len(board[x]) && board[x][y] != 'B' {
- if board[x][y] == 'p' {
- return 1
- }
- x += bx
- y += by
- }
- return 0
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1002.Find-Common-Characters.md b/website/content/ChapterFour/1002.Find-Common-Characters.md
deleted file mode 100755
index 9b61e2050..000000000
--- a/website/content/ChapterFour/1002.Find-Common-Characters.md
+++ /dev/null
@@ -1,74 +0,0 @@
-# [1002. Find Common Characters](https://leetcode.com/problems/find-common-characters/)
-
-
-## 题目
-
-Given an array `A` of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list **(including duplicates)**. For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.
-
-You may return the answer in any order.
-
-**Example 1**:
-
- Input: ["bella","label","roller"]
- Output: ["e","l","l"]
-
-**Example 2**:
-
- Input: ["cool","lock","cook"]
- Output: ["c","o"]
-
-**Note**:
-
-1. `1 <= A.length <= 100`
-2. `1 <= A[i].length <= 100`
-3. `A[i][j]` is a lowercase letter
-
-## 题目大意
-
-给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表。例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次。你可以按任意顺序返回答案。
-
-
-## 解题思路
-
-- 简单题。给出一个字符串数组 A,要求找出这个数组中每个字符串都包含字符,如果字符出现多次,在最终结果中也需要出现多次。这一题可以用 map 来统计每个字符串的频次,但是如果用数组统计会更快。题目中说了只有小写字母,那么用 2 个 26 位长度的数组就可以统计出来了。遍历字符串数组的过程中,不过的缩小每个字符在每个字符串中出现的频次(因为需要找所有字符串公共的字符,公共的频次肯定就是最小的频次),得到了最终公共字符的频次数组以后,按顺序输出就可以了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "math"
-
-func commonChars(A []string) []string {
- cnt := [26]int{}
- for i := range cnt {
- cnt[i] = math.MaxUint16
- }
- cntInWord := [26]int{}
- for _, word := range A {
- for _, char := range []byte(word) { // compiler trick - here we will not allocate new memory
- cntInWord[char-'a']++
- }
- for i := 0; i < 26; i++ {
- // 缩小频次,使得统计的公共频次更加准确
- if cntInWord[i] < cnt[i] {
- cnt[i] = cntInWord[i]
- }
- }
- // 重置状态
- for i := range cntInWord {
- cntInWord[i] = 0
- }
- }
- result := make([]string, 0)
- for i := 0; i < 26; i++ {
- for j := 0; j < cnt[i]; j++ {
- result = append(result, string(i+'a'))
- }
- }
- return result
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md b/website/content/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md
deleted file mode 100644
index b423f1dc5..000000000
--- a/website/content/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md
+++ /dev/null
@@ -1,107 +0,0 @@
-# [1003. Check If Word Is Valid After Substitutions](https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/)
-
-## 题目
-
-We are given that the string "abc" is valid.
-
-From any valid string V, we may split V into two pieces X and Y such that X + Y (X concatenated with Y) is equal to V. (X or Y may be empty.) Then, X + "abc" + Y is also valid.
-
-If for example S = "abc", then examples of valid strings are: "abc", "aabcbc", "abcabc", "abcabcababcc". Examples of invalid strings are: "abccba", "ab", "cababc", "bac".
-
-Return true if and only if the given string S is valid.
-
-
-
-**Example 1**:
-
-```
-
-Input: "aabcbc"
-Output: true
-Explanation:
-We start with the valid string "abc".
-Then we can insert another "abc" between "a" and "bc", resulting in "a" + "abc" + "bc" which is "aabcbc".
-
-```
-
-**Example 2**:
-
-```
-
-Input: "abcabcababcc"
-Output: true
-Explanation:
-"abcabcabc" is valid after consecutive insertings of "abc".
-Then we can insert "abc" before the last letter, resulting in "abcabcab" + "abc" + "c" which is "abcabcababcc".
-
-```
-
-**Example 3**:
-
-```
-
-Input: "abccba"
-Output: false
-
-```
-
-**Example 4**:
-
-```
-
-Input: "cababc"
-Output: false
-
-```
-
-**Note**:
-
-1. 1 <= S.length <= 20000
-2. S[i] is 'a', 'b', or 'c'
-
-## 题目大意
-
-假设 abc 是有效的字符串,对于任何 字符串 V,如果用 abc 把字符串 V 切成 2 半,X 和 Y,组成 X + abc + Y 的字符串,X + abc + Y 的这个字符串依旧是有效的。X 和 Y 可以是空字符串。
-
-例如,"abc"( "" + "abc" + ""), "aabcbc"( "a" + "abc" + "bc"), "abcabc"( "" + "abc" + "abc"), "abcabcababcc"( "abc" + "abc" + "ababcc",其中 "ababcc" 也是有效的,"ab" + "abc" + "c") 都是有效的字符串。
-
-"abccba"( "" + "abc" + "cba","cba" 不是有效的字符串), "ab"("ab" 也不是有效字符串), "cababc"("c" + "abc" + "bc","c","bc" 都不是有效字符串), "bac" ("bac" 也不是有效字符串)这些都不是有效的字符串。
-
-任意给一个字符串 S ,要求判断它是否有效,如果有效则输出 true。
-
-## 解题思路
-
-这一题可以类似括号匹配问题,因为 "abc" 这样的组合就代表是有效的,类似于括号匹配,遇到 "a" 就入栈,当遇到 "b" 字符的时候判断栈顶是不是 "a",当遇到 "c" 字符的时候需要判断栈顶是不是 "a" 和 "b"。最后如果栈都清空了,就输出 true。
-
-## 代码
-
-```go
-
-package leetcode
-
-func isValid1003(S string) bool {
- if len(S) < 3 {
- return false
- }
- stack := []byte{}
- for i := 0; i < len(S); i++ {
- if S[i] == 'a' {
- stack = append(stack, S[i])
- } else if S[i] == 'b' {
- if len(stack) > 0 && stack[len(stack)-1] == 'a' {
- stack = append(stack, S[i])
- } else {
- return false
- }
- } else {
- if len(stack) > 1 && stack[len(stack)-1] == 'b' && stack[len(stack)-2] == 'a' {
- stack = stack[:len(stack)-2]
- } else {
- return false
- }
- }
- }
- return len(stack) == 0
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1004.Max-Consecutive-Ones-III.md b/website/content/ChapterFour/1004.Max-Consecutive-Ones-III.md
deleted file mode 100644
index ba6eb873d..000000000
--- a/website/content/ChapterFour/1004.Max-Consecutive-Ones-III.md
+++ /dev/null
@@ -1,80 +0,0 @@
-# [1004. Max Consecutive Ones III](https://leetcode.com/problems/max-consecutive-ones-iii/)
-
-## 题目
-
-Given an array A of 0s and 1s, we may change up to K values from 0 to 1.
-
-Return the length of the longest (contiguous) subarray that contains only 1s.
-
-
-**Example 1**:
-
-```
-
-Input: A = [1,1,1,0,0,0,1,1,1,1,0], K = 2
-Output: 6
-Explanation:
-[1,1,1,0,0,1,1,1,1,1,1]
-Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
-
-```
-
-**Example 2**:
-
-```
-
-Input: A = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], K = 3
-Output: 10
-Explanation:
-[0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]
-Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
-
-```
-
-
-**Note**:
-
-- 1 <= A.length <= 20000
-- 0 <= K <= A.length
-- A[i] is 0 or 1
-
-
-## 题目大意
-
-这道题考察的是滑动窗口的问题。
-
-给出一个数组,数组中元素只包含 0 和 1 。再给一个 K,代表能将 0 变成 1 的次数。要求出经过变换以后,1 连续的最长长度。
-
-## 解题思路
-
-按照滑动窗口的思路处理即可,不断的更新和维护最大长度。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func longestOnes(A []int, K int) int {
- res, left, right := 0, 0, 0
- for left < len(A) {
- if right < len(A) && ((A[right] == 0 && K > 0) || A[right] == 1) {
- if A[right] == 0 {
- K--
- }
- right++
- } else {
- if K == 0 || (right == len(A) && K > 0) {
- res = max(res, right-left)
- }
- if A[left] == 0 {
- K++
- }
- left++
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1005.Maximize-Sum-Of-Array-After-K-Negations.md b/website/content/ChapterFour/1005.Maximize-Sum-Of-Array-After-K-Negations.md
deleted file mode 100644
index 1293b74f0..000000000
--- a/website/content/ChapterFour/1005.Maximize-Sum-Of-Array-After-K-Negations.md
+++ /dev/null
@@ -1,83 +0,0 @@
-# [1005. Maximize Sum Of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations/)
-
-## 题目
-
-Given an array A of integers, we must modify the array in the following way: we choose an i and replace A[i] with -A[i], and we repeat this process K times in total. (We may choose the same index i multiple times.)
-
-Return the largest possible sum of the array after modifying it in this way.
-
-
-**Example 1**:
-
-```
-
-Input: A = [4,2,3], K = 1
-Output: 5
-Explanation: Choose indices (1,) and A becomes [4,-2,3].
-
-```
-
-**Example 2**:
-
-```
-
-Input: A = [3,-1,0,2], K = 3
-Output: 6
-Explanation: Choose indices (1, 2, 2) and A becomes [3,1,0,2].
-
-```
-
-**Example 3**:
-
-```
-
-Input: A = [2,-3,-1,5,-4], K = 2
-Output: 13
-Explanation: Choose indices (1, 4) and A becomes [2,3,-1,5,4].
-
-```
-
-**Note**:
-
-- 1 <= A.length <= 10000
-- 1 <= K <= 10000
-- -100 <= A[i] <= 100
-
-## 题目大意
-
-将数组中的元素变成它的相反数,这种操作执行 K 次之后,求出数组中所有元素的总和最大。
-
-## 解题思路
-
-这一题可以用最小堆来做,构建最小堆,每次将最小的元素变成它的相反数。然后最小堆调整,再将新的最小元素变成它的相反数。执行 K 次以后求数组中所有的值之和就是最大值。
-
-这道题也可以用排序来实现。排序一次,从最小值开始往后扫,依次将最小值变为相反数。这里需要注意一点,负数都改变成正数以后,接着不是再改变这些变成正数的负数,而是接着改变顺序的正数。因为这些正数是比较小的正数。负数越小,变成正数以后值越大。正数越小,变成负数以后对总和影响最小。具体实现见代码。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-func largestSumAfterKNegations(A []int, K int) int {
- sort.Ints(A)
- minIdx := 0
- for i := 0; i < K; i++ {
- A[minIdx] = -A[minIdx]
- if A[minIdx+1] < A[minIdx] {
- minIdx++
- }
- }
- sum := 0
- for _, a := range A {
- sum += a
- }
- return sum
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md b/website/content/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md
deleted file mode 100755
index 774c53d14..000000000
--- a/website/content/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md
+++ /dev/null
@@ -1,101 +0,0 @@
-# [1011. Capacity To Ship Packages Within D Days](https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/)
-
-
-## 题目
-
-A conveyor belt has packages that must be shipped from one port to another within `D` days.
-
-The `i`-th package on the conveyor belt has a weight of `weights[i]`. Each day, we load the ship with packages on the conveyor belt (in the order given by `weights`). We may not load more weight than the maximum weight capacity of the ship.
-
-Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within `D` days.
-
-**Example 1**:
-
- Input: weights = [1,2,3,4,5,6,7,8,9,10], D = 5
- Output: 15
- Explanation:
- A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:
- 1st day: 1, 2, 3, 4, 5
- 2nd day: 6, 7
- 3rd day: 8
- 4th day: 9
- 5th day: 10
-
- Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.
-
-**Example 2**:
-
- Input: weights = [3,2,2,4,1,4], D = 3
- Output: 6
- Explanation:
- A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:
- 1st day: 3, 2
- 2nd day: 2, 4
- 3rd day: 1, 4
-
-**Example 3**:
-
- Input: weights = [1,2,3,1,1], D = 4
- Output: 3
- Explanation:
- 1st day: 1
- 2nd day: 2
- 3rd day: 3
- 4th day: 1, 1
-
-**Note**:
-
-1. `1 <= D <= weights.length <= 50000`
-2. `1 <= weights[i] <= 500`
-
-
-## 题目大意
-
-传送带上的包裹必须在 D 天内从一个港口运送到另一个港口。
-
-传送带上的第 i 个包裹的重量为 weights[i]。每一天,我们都会按给出重量的顺序往传送带上装载包裹。我们装载的重量不会超过船的最大运载重量。
-
-返回能在 D 天内将传送带上的所有包裹送达的船的最低运载能力。
-
-提示:
-
-- 1 <= D <= weights.length <= 50000
-- 1 <= weights[i] <= 500
-
-
-## 解题思路
-
-- 给出一个数组和天数 D,要求正好在 D 天把数组中的货物都运完。求传输带上能承受的最小货物重量是多少。
-- 这一题和第 410 题完全一样,只不过换了一个题面。代码完全不变。思路解析见第 410 题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func shipWithinDays(weights []int, D int) int {
- maxNum, sum := 0, 0
- for _, num := range weights {
- sum += num
- if num > maxNum {
- maxNum = num
- }
- }
- if D == 1 {
- return sum
- }
- low, high := maxNum, sum
- for low < high {
- mid := low + (high-low)>>1
- if calSum(mid, D, weights) {
- high = mid
- } else {
- low = mid + 1
- }
- }
- return low
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1017.Convert-to-Base--2.md b/website/content/ChapterFour/1017.Convert-to-Base--2.md
deleted file mode 100755
index 77eec60f0..000000000
--- a/website/content/ChapterFour/1017.Convert-to-Base--2.md
+++ /dev/null
@@ -1,75 +0,0 @@
-# [1017. Convert to Base -2](https://leetcode.com/problems/convert-to-base-2/)
-
-
-## 题目
-
-Given a number `N`, return a string consisting of `"0"`s and `"1"`s that represents its value in base **`-2`** (negative two).
-
-The returned string must have no leading zeroes, unless the string is `"0"`.
-
-**Example 1**:
-
- Input: 2
- Output: "110"
- Explantion: (-2) ^ 2 + (-2) ^ 1 = 2
-
-**Example 2**:
-
- Input: 3
- Output: "111"
- Explantion: (-2) ^ 2 + (-2) ^ 1 + (-2) ^ 0 = 3
-
-**Example 3**:
-
- Input: 4
- Output: "100"
- Explantion: (-2) ^ 2 = 4
-
-**Note**:
-
-1. `0 <= N <= 10^9`
-
-
-## 题目大意
-
-给出数字 N,返回由若干 "0" 和 "1"组成的字符串,该字符串为 N 的负二进制(base -2)表示。除非字符串就是 "0",否则返回的字符串中不能含有前导零。
-
-提示:
-
-- 0 <= N <= 10^9
-
-
-
-## 解题思路
-
-- 给出一个十进制的数,要求转换成 -2 进制的数
-- 这一题仿造十进制转二进制的思路,短除法即可。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strconv"
-
-func baseNeg2(N int) string {
- if N == 0 {
- return "0"
- }
- res := ""
- for N != 0 {
- remainder := N % (-2)
- N = N / (-2)
- if remainder < 0 {
- remainder += 2
- N++
- }
- res = strconv.Itoa(remainder) + res
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md b/website/content/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md
deleted file mode 100644
index 944ca8e32..000000000
--- a/website/content/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md
+++ /dev/null
@@ -1,96 +0,0 @@
-# [1019. Next Greater Node In Linked List](https://leetcode.com/problems/next-greater-node-in-linked-list/)
-
-## 题目
-
-We are given a linked list with head as the first node. Let's number the nodes in the list: node\_1, node\_2, node\_3, ... etc.
-
-Each node may have a next larger value: for node_i, next\_larger(node\_i) is the node\_j.val such that j > i, node\_j.val > node\_i.val, and j is the smallest possible choice. If such a j does not exist, the next larger value is 0.
-
-Return an array of integers answer, where answer[i] = next\_larger(node\_{i+1}).
-
-Note that in the example inputs (not outputs) below, arrays such as [2,1,5] represent the serialization of a linked list with a head node value of 2, second node value of 1, and third node value of 5.
-
-
-
-**Example 1**:
-
-```
-
-Input: [2,1,5]
-Output: [5,5,0]
-
-```
-
-**Example 2**:
-
-```
-
-Input: [2,7,4,3,5]
-Output: [7,0,5,5,0]
-
-```
-
-**Example 3**:
-
-```
-
-Input: [1,7,5,1,9,2,5,1]
-Output: [7,9,9,9,0,5,0,0]
-
-```
-
-**Note**:
-
-- 1 <= node.val <= 10^9 for each node in the linked list.
-- The given list has length in the range [0, 10000].
-
-
-## 题目大意
-
-给出一个链表,要求找出每个结点后面比该结点值大的第一个结点,如果找不到这个结点,则输出 0 。
-
-
-## 解题思路
-
-这一题和第 739 题、第 496 题、第 503 题类似。也有 2 种解题方法。先把链表中的数字存到数组中,整道题的思路就和第 739 题完全一致了。普通做法就是 2 层循环。优化的做法就是用单调栈,维护一个单调递减的栈即可。
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for singly-linked list.
- * type ListNode struct {
- * Val int
- * Next *ListNode
- * }
- */
-// 解法一 单调栈
-func nextLargerNodes(head *ListNode) []int {
- res, indexes, nums := make([]int, 0), make([]int, 0), make([]int, 0)
- p := head
- for p != nil {
- nums = append(nums, p.Val)
- p = p.Next
- }
- for i := 0; i < len(nums); i++ {
- res = append(res, 0)
- }
- for i := 0; i < len(nums); i++ {
- num := nums[i]
- for len(indexes) > 0 && nums[indexes[len(indexes)-1]] < num {
- index := indexes[len(indexes)-1]
- res[index] = num
- indexes = indexes[:len(indexes)-1]
- }
- indexes = append(indexes, i)
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1020.Number-of-Enclaves.md b/website/content/ChapterFour/1020.Number-of-Enclaves.md
deleted file mode 100644
index 34b72b3de..000000000
--- a/website/content/ChapterFour/1020.Number-of-Enclaves.md
+++ /dev/null
@@ -1,93 +0,0 @@
-# [1020. Number of Enclaves](https://leetcode.com/problems/number-of-enclaves/)
-
-
-
-## 题目
-
-Given a 2D array `A`, each cell is 0 (representing sea) or 1 (representing land)
-
-A move consists of walking from one land square 4-directionally to another land square, or off the boundary of the grid.
-
-Return the number of land squares in the grid for which we **cannot** walk off the boundary of the grid in any number of moves.
-
-**Example 1**:
-
-```
-Input: [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]
-Output: 3
-Explanation:
-There are three 1s that are enclosed by 0s, and one 1 that isn't enclosed because its on the boundary.
-```
-
-**Example 2**:
-
-```
-Input: [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]
-Output: 0
-Explanation:
-All 1s are either on the boundary or can reach the boundary.
-```
-
-**Note**:
-
-1. `1 <= A.length <= 500`
-2. `1 <= A[i].length <= 500`
-3. `0 <= A[i][j] <= 1`
-4. All rows have the same size.
-
-## 题目大意
-
-给出一个二维数组 A,每个单元格为 0(代表海)或 1(代表陆地)。移动是指在陆地上从一个地方走到另一个地方(朝四个方向之一)或离开网格的边界。返回网格中无法在任意次数的移动中离开网格边界的陆地单元格的数量。
-
-提示:
-
-- 1 <= A.length <= 500
-- 1 <= A[i].length <= 500
-- 0 <= A[i][j] <= 1
-- 所有行的大小都相同
-
-
-## 解题思路
-
-- 给出一个地图,要求输出不和边界连通的 1 的个数。
-- 这一题可以用 DFS 也可以用并查集解答。DFS 的思路是深搜的过程中把和边界连通的点都覆盖成 0,最后遍历一遍地图,输出 1 的个数即可。并查集的思路就比较直接了,把能和边界连通的放在一个集合中,剩下的就是不能和边界连通的都在另外一个集合中,输出这个集合里面元素的个数即可。
-- 这一题和第 200 题,第 1254 题,第 695 题类似。可以放在一起练习。
-
-## 代码
-
-```go
-func numEnclaves(A [][]int) int {
- m, n := len(A), len(A[0])
- for i := 0; i < m; i++ {
- for j := 0; j < n; j++ {
- if i == 0 || i == m-1 || j == 0 || j == n-1 {
- if A[i][j] == 1 {
- dfsNumEnclaves(A, i, j)
- }
- }
- }
- }
- count := 0
- for i := 0; i < m; i++ {
- for j := 0; j < n; j++ {
- if A[i][j] == 1 {
- count++
- }
- }
- }
- return count
-}
-
-func dfsNumEnclaves(A [][]int, x, y int) {
- if !isInGrid(A, x, y) || A[x][y] == 0 {
- return
- }
- A[x][y] = 0
- for i := 0; i < 4; i++ {
- nx := x + dir[i][0]
- ny := y + dir[i][1]
- dfsNumEnclaves(A, nx, ny)
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1021.Remove-Outermost-Parentheses.md b/website/content/ChapterFour/1021.Remove-Outermost-Parentheses.md
deleted file mode 100644
index d43d1b224..000000000
--- a/website/content/ChapterFour/1021.Remove-Outermost-Parentheses.md
+++ /dev/null
@@ -1,123 +0,0 @@
-# [1021. Remove Outermost Parentheses](https://leetcode.com/problems/remove-outermost-parentheses/)
-
-## 题目
-
-A valid parentheses string is either empty (""), "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.
-
-A valid parentheses string S is primitive if it is nonempty, and there does not exist a way to split it into S = A+B, with A and B nonempty valid parentheses strings.
-
-Given a valid parentheses string S, consider its primitive decomposition: S = P\_1 + P\_2 + ... + P\_k, where P\_i are primitive valid parentheses strings.
-
-Return S after removing the outermost parentheses of every primitive string in the primitive decomposition of S.
-
-
-**Example 1**:
-
-```
-
-Input: "(()())(())"
-Output: "()()()"
-Explanation:
-The input string is "(()())(())", with primitive decomposition "(()())" + "(())".
-After removing outer parentheses of each part, this is "()()" + "()" = "()()()".
-
-```
-
-**Example 2**:
-
-```
-
-Input: "(()())(())(()(()))"
-Output: "()()()()(())"
-Explanation:
-The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))".
-After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())".
-
-```
-
-**Example 3**:
-
-```
-
-Input: "()()"
-Output: ""
-Explanation:
-The input string is "()()", with primitive decomposition "()" + "()".
-After removing outer parentheses of each part, this is "" + "" = "".
-
-```
-
-**Note**:
-
-- S.length <= 10000
-- S[i] is "(" or ")"
-- S is a valid parentheses string
-
-
-## 题目大意
-
-题目要求去掉最外层的括号。
-
-## 解题思路
-
-用栈模拟即可。
-
-
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一
-func removeOuterParentheses(S string) string {
- now, current, ans := 0, "", ""
- for _, char := range S {
- if string(char) == "(" {
- now++
- } else if string(char) == ")" {
- now--
- }
- current += string(char)
- if now == 0 {
- ans += current[1 : len(current)-1]
- current = ""
- }
- }
- return ans
-}
-
-// 解法二
-func removeOuterParentheses1(S string) string {
- stack, res, counter := []byte{}, "", 0
- for i := 0; i < len(S); i++ {
- if counter == 0 && len(stack) == 1 && S[i] == ')' {
- stack = stack[1:]
- continue
- }
- if len(stack) == 0 && S[i] == '(' {
- stack = append(stack, S[i])
- continue
- }
- if len(stack) > 0 {
- switch S[i] {
- case '(':
- {
- counter++
- res += "("
- }
- case ')':
- {
- counter--
- res += ")"
- }
- }
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1025.Divisor-Game.md b/website/content/ChapterFour/1025.Divisor-Game.md
deleted file mode 100755
index e6a45211d..000000000
--- a/website/content/ChapterFour/1025.Divisor-Game.md
+++ /dev/null
@@ -1,62 +0,0 @@
-# [1025. Divisor Game](https://leetcode.com/problems/divisor-game/)
-
-
-## 题目
-
-Alice and Bob take turns playing a game, with Alice starting first.
-
-Initially, there is a number `N` on the chalkboard. On each player's turn, that player makes a *move* consisting of:
-
-- Choosing any `x` with `0 < x < N` and `N % x == 0`.
-- Replacing the number `N` on the chalkboard with `N - x`.
-
-Also, if a player cannot make a move, they lose the game.
-
-Return `True` if and only if Alice wins the game, assuming both players play optimally.
-
-**Example 1**:
-
- Input: 2
- Output: true
- Explanation: Alice chooses 1, and Bob has no more moves.
-
-**Example 2**:
-
- Input: 3
- Output: false
- Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.
-
-**Note**:
-
-1. `1 <= N <= 1000`
-
-
-## 题目大意
-
-
-爱丽丝和鲍勃一起玩游戏,他们轮流行动。爱丽丝先手开局。最初,黑板上有一个数字 N 。在每个玩家的回合,玩家需要执行以下操作:
-
-- 选出任一 x,满足 0 < x < N 且 N % x == 0 。
-- 用 N - x 替换黑板上的数字 N 。
-
-如果玩家无法执行这些操作,就会输掉游戏。只有在爱丽丝在游戏中取得胜利时才返回 True,否则返回 false。假设两个玩家都以最佳状态参与游戏。
-
-
-## 解题思路
-
-
-- 两人相互玩一个游戏,游戏初始有一个数 N,开始游戏的时候,任一方选择一个数 x,满足 `0 < x < N` 并且 `N % x == 0` 的条件,然后 `N-x` 为下一轮开始的数。此轮结束,该另外一个人继续选择数字,两人相互轮流选择。直到某一方再也没法选择数字的时候,输掉游戏。问如果你先手开始游戏,给出 N 的时候,能否直到这局你是否会必胜或者必输?
-- 这一题当 `N = 1` 的时候,那一轮的人必输。因为没法找到一个数字能满足 `0 < x < N` 并且 `N % x == 0` 的条件了。必胜策略就是把对方逼至 `N = 1` 的情况。题目中假设了对手也是一个很有头脑的人。初始如果 `N 为偶数`,我就选择 x = 1,对手拿到的数字就是奇数。只要最终能让对手拿到奇数,他就会输。初始如果 `N 为奇数`,N = 1 的时候直接输了,N 为其他奇数的时候,我们也只能选择一个奇数 x,(因为 `N % x == 0` ,N 为奇数,x 一定不会是偶数,因为偶数就能被 2 整除了),对手由于是一个很有头脑的人,当我们选完 N - x 是偶数的时候,他就选择 1,那么轮到我们拿到的数字又是奇数。对手只要一直保证我们拿到奇数,最终肯定会逼着我们拿到 1,最终他就会获得胜利。所以经过分析可得,初始数字如果是偶数,有必胜策略,如果初始数字是奇数,有必输的策略。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func divisorGame(N int) bool {
- return N%2 == 0
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1026.Maximum-Difference-Between-Node-and-Ancestor.md b/website/content/ChapterFour/1026.Maximum-Difference-Between-Node-and-Ancestor.md
deleted file mode 100644
index b2c946172..000000000
--- a/website/content/ChapterFour/1026.Maximum-Difference-Between-Node-and-Ancestor.md
+++ /dev/null
@@ -1,74 +0,0 @@
-# [1026. Maximum Difference Between Node and Ancestor](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor/)
-
-
-
-## 题目
-
-Given the `root` of a binary tree, find the maximum value `V` for which there exists **different** nodes `A` and `B` where `V = |A.val - B.val|` and `A` is an ancestor of `B`.
-
-(A node A is an ancestor of B if either: any child of A is equal to B, or any child of A is an ancestor of B.)
-
-**Example 1**:
-
-
-
-```
-Input: [8,3,10,1,6,null,14,null,null,4,7,13]
-Output: 7
-Explanation:
-We have various ancestor-node differences, some of which are given below :
-|8 - 3| = 5
-|3 - 7| = 4
-|8 - 1| = 7
-|10 - 13| = 3
-Among all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.
-```
-
-**Note**:
-
-1. The number of nodes in the tree is between `2` and `5000`.
-2. Each node will have value between `0` and `100000`.
-
-## 题目大意
-
-给定二叉树的根节点 root,找出存在于不同节点 A 和 B 之间的最大值 V,其中 V = |A.val - B.val|,且 A 是 B 的祖先。(如果 A 的任何子节点之一为 B,或者 A 的任何子节点是 B 的祖先,那么我们认为 A 是 B 的祖先)
-
-提示:
-
-- 树中的节点数在 2 到 5000 之间。
-- 每个节点的值介于 0 到 100000 之间。
-
-
-
-## 解题思路
-
-- 给出一颗树,要求找出祖先和孩子的最大差值。
-- DPS 深搜即可。每个节点和其所有孩子的`最大值`来自于 3 个值,节点本身,递归遍历左子树的最大值,递归遍历右子树的最大值;每个节点和其所有孩子的`最小值`来自于 3 个值,节点本身,递归遍历左子树的最小值,递归遍历右子树的最小值。依次求出自身节点和其所有孩子节点的最大差值,深搜的过程中动态维护最大差值即可。
-
-## 代码
-
-```go
-func maxAncestorDiff(root *TreeNode) int {
- res := 0
- dfsAncestorDiff(root, &res)
- return res
-}
-
-func dfsAncestorDiff(root *TreeNode, res *int) (int, int) {
- if root == nil {
- return -1, -1
- }
- leftMax, leftMin := dfsAncestorDiff(root.Left, res)
- if leftMax == -1 && leftMin == -1 {
- leftMax = root.Val
- leftMin = root.Val
- }
- rightMax, rightMin := dfsAncestorDiff(root.Right, res)
- if rightMax == -1 && rightMin == -1 {
- rightMax = root.Val
- rightMin = root.Val
- }
- *res = max(*res, max(abs(root.Val-min(leftMin, rightMin)), abs(root.Val-max(leftMax, rightMax))))
- return max(leftMax, max(rightMax, root.Val)), min(leftMin, min(rightMin, root.Val))
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1028.Recover-a-Tree-From-Preorder-Traversal.md b/website/content/ChapterFour/1028.Recover-a-Tree-From-Preorder-Traversal.md
deleted file mode 100755
index f9c25238e..000000000
--- a/website/content/ChapterFour/1028.Recover-a-Tree-From-Preorder-Traversal.md
+++ /dev/null
@@ -1,135 +0,0 @@
-# [1028. Recover a Tree From Preorder Traversal](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/)
-
-
-## 题目
-
-We run a preorder depth first search on the `root` of a binary tree.
-
-At each node in this traversal, we output `D` dashes (where `D` is the *depth* of this node), then we output the value of this node. *(If the depth of a node is `D`, the depth of its immediate child is `D+1`. The depth of the root node is `0`.)*
-
-If a node has only one child, that child is guaranteed to be the left child.
-
-Given the output `S` of this traversal, recover the tree and return its `root`.
-
-**Example 1**:
-
-
-
- Input: "1-2--3--4-5--6--7"
- Output: [1,2,5,3,4,6,7]
-
-**Example 2**:
-
-
-
- Input: "1-2--3---4-5--6---7"
- Output: [1,2,5,3,null,6,null,4,null,7]
-
-**Example 3**:
-
-
-
- Input: "1-401--349---90--88"
- Output: [1,401,null,349,88,90]
-
-**Note**:
-
-- The number of nodes in the original tree is between `1` and `1000`.
-- Each node will have a value between `1` and `10^9`.
-
-## 题目大意
-
-我们从二叉树的根节点 root 开始进行深度优先搜索。
-
-在遍历中的每个节点处,我们输出 D 条短划线(其中 D 是该节点的深度),然后输出该节点的值。(如果节点的深度为 D,则其直接子节点的深度为 D + 1。根节点的深度为 0)。如果节点只有一个子节点,那么保证该子节点为左子节点。给出遍历输出 S,还原树并返回其根节点 root。
-
-
-提示:
-
-- 原始树中的节点数介于 1 和 1000 之间。
-- 每个节点的值介于 1 和 10 ^ 9 之间。
-
-
-## 解题思路
-
-- 给出一个字符串,字符串是一个树的先根遍历的结果,其中破折号的个数代表层数。请根据这个字符串生成对应的树。
-- 这一题解题思路比较明确,用 DFS 就可以解题。边深搜字符串,边根据破折号的个数判断当前节点是否属于本层。如果不属于本层,回溯到之前的根节点,添加叶子节点以后再继续深搜。需要注意的是每次深搜时,扫描字符串的 index 需要一直保留,回溯也需要用到这个 index。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "strconv"
-)
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-func recoverFromPreorder(S string) *TreeNode {
- if len(S) == 0 {
- return &TreeNode{}
- }
- root, index, level := &TreeNode{}, 0, 0
- cur := root
- dfsBuildPreorderTree(S, &index, &level, cur)
- return root.Right
-}
-
-func dfsBuildPreorderTree(S string, index, level *int, cur *TreeNode) (newIndex *int) {
- if *index == len(S) {
- return index
- }
- if *index == 0 && *level == 0 {
- i := 0
- for i = *index; i < len(S); i++ {
- if !isDigital(S[i]) {
- break
- }
- }
- num, _ := strconv.Atoi(S[*index:i])
- tmp := &TreeNode{Val: num, Left: nil, Right: nil}
- cur.Right = tmp
- nLevel := *level + 1
- index = dfsBuildPreorderTree(S, &i, &nLevel, tmp)
- index = dfsBuildPreorderTree(S, index, &nLevel, tmp)
- }
- i := 0
- for i = *index; i < len(S); i++ {
- if isDigital(S[i]) {
- break
- }
- }
- if *level == i-*index {
- j := 0
- for j = i; j < len(S); j++ {
- if !isDigital(S[j]) {
- break
- }
- }
- num, _ := strconv.Atoi(S[i:j])
- tmp := &TreeNode{Val: num, Left: nil, Right: nil}
- if cur.Left == nil {
- cur.Left = tmp
- nLevel := *level + 1
- index = dfsBuildPreorderTree(S, &j, &nLevel, tmp)
- index = dfsBuildPreorderTree(S, index, level, cur)
- } else if cur.Right == nil {
- cur.Right = tmp
- nLevel := *level + 1
- index = dfsBuildPreorderTree(S, &j, &nLevel, tmp)
- index = dfsBuildPreorderTree(S, index, level, cur)
- }
- }
- return index
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md b/website/content/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md
deleted file mode 100755
index ba60ec4dc..000000000
--- a/website/content/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md
+++ /dev/null
@@ -1,84 +0,0 @@
-# [1030. Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order/)
-
-
-## 题目
-
-We are given a matrix with `R` rows and `C` columns has cells with integer coordinates `(r, c)`, where `0 <= r < R` and `0 <= c < C`.
-
-Additionally, we are given a cell in that matrix with coordinates `(r0, c0)`.
-
-Return the coordinates of all cells in the matrix, sorted by their distance from `(r0, c0)` from smallest distance to largest distance. Here, the distance between two cells `(r1, c1)` and `(r2, c2)` is the Manhattan distance, `|r1 - r2| + |c1 - c2|`. (You may return the answer in any order that satisfies this condition.)
-
-**Example 1**:
-
- Input: R = 1, C = 2, r0 = 0, c0 = 0
- Output: [[0,0],[0,1]]
- Explanation: The distances from (r0, c0) to other cells are: [0,1]
-
-**Example 2**:
-
- Input: R = 2, C = 2, r0 = 0, c0 = 1
- Output: [[0,1],[0,0],[1,1],[1,0]]
- Explanation: The distances from (r0, c0) to other cells are: [0,1,1,2]
- The answer [[0,1],[1,1],[0,0],[1,0]] would also be accepted as correct.
-
-**Example 3**:
-
- Input: R = 2, C = 3, r0 = 1, c0 = 2
- Output: [[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]
- Explanation: The distances from (r0, c0) to other cells are: [0,1,1,2,2,3]
- There are other answers that would also be accepted as correct, such as [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]].
-
-**Note**:
-
-1. `1 <= R <= 100`
-2. `1 <= C <= 100`
-3. `0 <= r0 < R`
-4. `0 <= c0 < C`
-
-
-
-## 题目大意
-
-
-给出 R 行 C 列的矩阵,其中的单元格的整数坐标为 (r, c),满足 0 <= r < R 且 0 <= c < C。另外,我们在该矩阵中给出了一个坐标为 (r0, c0) 的单元格。
-
-返回矩阵中的所有单元格的坐标,并按到 (r0, c0) 的距离从最小到最大的顺序排,其中,两单元格(r1, c1) 和 (r2, c2) 之间的距离是曼哈顿距离,|r1 - r2| + |c1 - c2|。(你可以按任何满足此条件的顺序返回答案。)
-
-
-## 解题思路
-
-
-- 按照题意计算矩阵内给定点到其他每个点的距离即可
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func allCellsDistOrder(R int, C int, r0 int, c0 int) [][]int {
- longRow, longCol, result := max(abs(r0-0), abs(R-r0)), max(abs(c0-0), abs(C-c0)), make([][]int, 0)
- maxDistance := longRow + longCol
- bucket := make([][][]int, maxDistance+1)
- for i := 0; i <= maxDistance; i++ {
- bucket[i] = make([][]int, 0)
- }
- for r := 0; r < R; r++ {
- for c := 0; c < C; c++ {
- distance := abs(r-r0) + abs(c-c0)
- tmp := []int{r, c}
- bucket[distance] = append(bucket[distance], tmp)
- }
- }
- for i := 0; i <= maxDistance; i++ {
- for _, buk := range bucket[i] {
- result = append(result, buk)
- }
- }
- return result
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1037.Valid-Boomerang.md b/website/content/ChapterFour/1037.Valid-Boomerang.md
deleted file mode 100644
index 89a4000db..000000000
--- a/website/content/ChapterFour/1037.Valid-Boomerang.md
+++ /dev/null
@@ -1,49 +0,0 @@
-# [1037. Valid Boomerang](https://leetcode.com/problems/valid-boomerang/)
-
-
-## 题目
-
-A *boomerang* is a set of 3 points that are all distinct and **not** in a straight line.
-
-Given a list of three points in the plane, return whether these points are a boomerang.
-
-**Example 1**:
-
-```
-Input: [[1,1],[2,3],[3,2]]
-Output: true
-```
-
-**Example 2**:
-
-```
-Input: [[1,1],[2,2],[3,3]]
-Output: false
-```
-
-**Note**:
-
-1. `points.length == 3`
-2. `points[i].length == 2`
-3. `0 <= points[i][j] <= 100`
-
-## 题目大意
-
-回旋镖定义为一组三个点,这些点各不相同且不在一条直线上。给出平面上三个点组成的列表,判断这些点是否可以构成回旋镖。
-
-## 解题思路
-
-- 判断给出的 3 组点能否满足回旋镖。
-- 简单题。判断 3 个点组成的 2 条直线的斜率是否相等。由于斜率的计算是除法,还可能遇到分母为 0 的情况,那么可以转换成乘法,交叉相乘再判断是否相等,就可以省去判断分母为 0 的情况了,代码也简洁成一行了。
-
-## 代码
-
-```go
-
-package leetcode
-
-func isBoomerang(points [][]int) bool {
- return (points[0][0]-points[1][0])*(points[0][1]-points[2][1]) != (points[0][0]-points[2][0])*(points[0][1]-points[1][1])
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md b/website/content/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md
deleted file mode 100755
index 9c41121ef..000000000
--- a/website/content/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md
+++ /dev/null
@@ -1,121 +0,0 @@
-# [1040. Moving Stones Until Consecutive II](https://leetcode.com/problems/moving-stones-until-consecutive-ii/)
-
-
-## 题目
-
-On an **infinite** number line, the position of the i-th stone is given by `stones[i]`. Call a stone an *endpoint stone* if it has the smallest or largest position.
-
-Each turn, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.
-
-In particular, if the stones are at say, `stones = [1,2,5]`, you **cannot** move the endpoint stone at position 5, since moving it to any position (such as 0, or 3) will still keep that stone as an endpoint stone.
-
-The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.
-
-When the game ends, what is the minimum and maximum number of moves that you could have made? Return the answer as an length 2 array: `answer = [minimum_moves, maximum_moves]`
-
-**Example 1**:
-
- Input: [7,4,9]
- Output: [1,2]
- Explanation:
- We can move 4 -> 8 for one move to finish the game.
- Or, we can move 9 -> 5, 4 -> 6 for two moves to finish the game.
-
-**Example 2**:
-
- Input: [6,5,4,3,10]
- Output: [2,3]
- We can move 3 -> 8 then 10 -> 7 to finish the game.
- Or, we can move 3 -> 7, 4 -> 8, 5 -> 9 to finish the game.
- Notice we cannot move 10 -> 2 to finish the game, because that would be an illegal move.
-
-**Example 3**:
-
- Input: [100,101,104,102,103]
- Output: [0,0]
-
-**Note**:
-
-1. `3 <= stones.length <= 10^4`
-2. `1 <= stones[i] <= 10^9`
-3. `stones[i]` have distinct values.
-
-
-## 题目大意
-
-在一个长度无限的数轴上,第 i 颗石子的位置为 stones[i]。如果一颗石子的位置最小/最大,那么该石子被称作端点石子。每个回合,你可以将一颗端点石子拿起并移动到一个未占用的位置,使得该石子不再是一颗端点石子。值得注意的是,如果石子像 stones = [1,2,5] 这样,你将无法移动位于位置 5 的端点石子,因为无论将它移动到任何位置(例如 0 或 3),该石子都仍然会是端点石子。当你无法进行任何移动时,即,这些石子的位置连续时,游戏结束。
-
-要使游戏结束,你可以执行的最小和最大移动次数分别是多少? 以长度为 2 的数组形式返回答案:answer = [minimum\_moves, maximum\_moves] 。
-
-提示:
-
-1. 3 <= stones.length <= 10^4
-2. 1 <= stones[i] <= 10^9
-3. stones[i] 的值各不相同。
-
-
-## 解题思路
-
-
-- 给出一个数组,数组里面代表的是石头的坐标。要求移动石头,最终使得这些石头的坐标是一个连续的自然数列。但是规定,当一个石头是端点的时候,是不能移动的,例如 [1,2,5],5 是端点,不能把 5 移到 3 或者 0 的位置,因为移动之后,这个石头仍然是端点。最终输出将所有石头排成连续的自然数列所需的最小步数和最大步数。
-- 这道题的关键就是如何保证端点石头不能再次移动到端点的限制。例如,[5,6,8,9,20],20 是端点,但是 20 就可以移动到 7 的位置,最终形成 [5,6,7,8,9] 的连续序列。但是 [5,6,7,8,20],这种情况 20 就不能移动到 9 了,只能让 8 移动到 9,20 再移动到 8 的位置,最终还是形成了 [5,6,7,8,9],但是步数需要 2 步。经过上述分析,可以得到,端点石头只能往中间空挡的位置移动,如果中间没有空挡,那么需要借助一个石头先制造一个空挡,然后端点石头再插入到中间,这样最少是需要 2 步。
-- 再来考虑极值的情况。先看最大步数,最大步数肯定慢慢移动,一次移动一格,并且移动的格数最多。这里有两个极端情况,把数组里面的数全部都移动到最左端点,把数组里面的数全部都移动到最右端点。每次只移动一格。例如,全部都移到最右端点:
-
- [3,4,5,6,10] // 初始状态,连续的情况
- [4,5,6,7,10] // 第一步,把 3 挪到右边第一个可以插入的位置,即 7
- [5,6,7,8,10] // 第二步,把 4 挪到右边第一个可以插入的位置,即 8
- [6,7,8,9,10] // 第三步,把 5 挪到右边第一个可以插入的位置,即 9
-
-
- [1,3,5,7,10] // 初始状态,不连续的情况
- [3,4,5,7,10] // 第一步,把 1 挪到右边第一个可以插入的位置,即 4
- [4,5,6,7,10] // 第二步,把 3 挪到右边第一个可以插入的位置,即 6
- [5,6,7,8,10] // 第三步,把 4 挪到右边第一个可以插入的位置,即 8
- [6,7,8,9,10] // 第四步,把 5 挪到右边第一个可以插入的位置,即 9
-
- 挪动的过程类似翻滚,最左边的石头挪到右边第一个可以放下的地方。然后不断的往右翻滚。把数组中的数全部都移动到最左边也同理。对比这两种情况的最大值,即是移动的最大步数。
-
-- 再看最小步数。这里就涉及到了滑动窗口了。由于最终是要形成连续的自然数列,所以滑动窗口的大小已经固定成 n 了,从数组的 0 下标可以往右滑动窗口,这个窗口中能包含的数字越多,代表窗口外的数字越少,那么把这些数字放进窗口内的步数也最小。于是可以求得最小步数。这里有一个比较坑的地方就是题目中的那个`“端点不能移动以后还是端点”`的限制。针对这种情况,需要额外的判断。如果当前窗口内有 n-1 个元素了,即只有一个端点在窗口外,并且窗口右边界的值减去左边界的值也等于 n-1,代表这个窗口内已经都是连续数字了。这种情况端点想融合到这个连续数列中,最少需要 2 步(上文已经分析过了)。
-- 注意一些边界情况。如果窗口从左往右滑动,窗口右边界滑到最右边了,但是窗口右边界的数字减去左边界的数字还是小于窗口大小 n,代表已经滑到头了,可以直接 break 出去。为什么滑到头了呢?由于数组经过从小到大排序以后,数字越往右边越大,当前数字是小值,已经满足了 `stones[right]-stones[left] < n`,左边界继续往右移动只会使得 `stones[left]` 更大,就更加小于 n 了。而我们需要寻找的是 `stones[right]-stones[left] >= n` 的边界点,肯定再也找不到了。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "math"
- "sort"
-)
-
-func numMovesStonesII(stones []int) []int {
- if len(stones) == 0 {
- return []int{0, 0}
- }
- sort.Ints(stones)
- n := len(stones)
- maxStep, minStep, left, right := max(stones[n-1]-stones[1]-n+2, stones[n-2]-stones[0]-n+2), math.MaxInt64, 0, 0
- for left < n {
- if right+1 < n && stones[right]-stones[left] < n {
- right++
- } else {
- if stones[right]-stones[left] >= n {
- right--
- }
- if right-left+1 == n-1 && stones[right]-stones[left]+1 == n-1 {
- minStep = min(minStep, 2)
- } else {
- minStep = min(minStep, n-(right-left+1))
- }
- if right == n-1 && stones[right]-stones[left] < n {
- break
- }
- left++
- }
- }
- return []int{minStep, maxStep}
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md b/website/content/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md
deleted file mode 100644
index 1166355f8..000000000
--- a/website/content/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md
+++ /dev/null
@@ -1,57 +0,0 @@
-# [1047. Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/)
-
-## 题目
-
-Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.
-
-We repeatedly make duplicate removals on S until we no longer can.
-
-Return the final string after all such duplicate removals have been made. It is guaranteed the answer is unique.
-
-
-
-**Example 1**:
-
-```
-
-Input: "abbaca"
-Output: "ca"
-Explanation:
-For example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only possible move. The result of this move is that the string is "aaca", of which only "aa" is possible, so the final string is "ca".
-
-```
-
-**Note**:
-
-1. 1 <= S.length <= 20000
-2. S consists only of English lowercase letters.
-
-
-## 题目大意
-
-给出由小写字母组成的字符串 S,重复项删除操作会选择两个相邻且相同的字母,并删除它们。在 S 上反复执行重复项删除操作,直到无法继续删除。在完成所有重复项删除操作后返回最终的字符串。答案保证唯一。
-
-
-## 解题思路
-
-用栈模拟,类似“对对碰”,一旦新来的字符和栈顶的字符一样的话,就弹出栈顶字符,直至扫完整个字符串。栈中剩下的字符串就是最终要输出的结果。
-
-## 代码
-
-```go
-
-package leetcode
-
-func removeDuplicates1047(S string) string {
- stack := []rune{}
- for _, s := range S {
- if len(stack) == 0 || len(stack) > 0 && stack[len(stack)-1] != s {
- stack = append(stack, s)
- } else {
- stack = stack[:len(stack)-1]
- }
- }
- return string(stack)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1049.Last-Stone-Weight-II.md b/website/content/ChapterFour/1049.Last-Stone-Weight-II.md
deleted file mode 100755
index 4159bb504..000000000
--- a/website/content/ChapterFour/1049.Last-Stone-Weight-II.md
+++ /dev/null
@@ -1,79 +0,0 @@
-# [1049. Last Stone Weight II](https://leetcode.com/problems/last-stone-weight-ii/)
-
-## 题目
-
-We have a collection of rocks, each rock has a positive integer weight.
-
-Each turn, we choose **any two rocks** and smash them together. Suppose the stones have weights `x` and `y` with `x <= y`. The result of this smash is:
-
-- If `x == y`, both stones are totally destroyed;
-- If `x != y`, the stone of weight `x` is totally destroyed, and the stone of weight `y`has new weight `y-x`.
-
-At the end, there is at most 1 stone left. Return the **smallest possible** weight of this stone (the weight is 0 if there are no stones left.)
-
-**Example 1**:
-
- Input: [2,7,4,1,8,1]
- Output: 1
- Explanation:
- We can combine 2 and 4 to get 2 so the array converts to [2,7,1,8,1] then,
- we can combine 7 and 8 to get 1 so the array converts to [2,1,1,1] then,
- we can combine 2 and 1 to get 1 so the array converts to [1,1,1] then,
- we can combine 1 and 1 to get 0 so the array converts to [1] then that's the optimal value.
-
-**Note**:
-
-1. `1 <= stones.length <= 30`
-2. `1 <= stones[i] <= 100`
-
-
-
-## 题目大意
-
-有一堆石头,每块石头的重量都是正整数。每一回合,从中选出任意两块石头,然后将它们一起粉碎。假设石头的重量分别为 x 和 y,且 x <= y。那么粉碎的可能结果如下:
-
-如果 x == y,那么两块石头都会被完全粉碎;
-如果 x != y,那么重量为 x 的石头将会完全粉碎,而重量为 y 的石头新重量为 y-x。
-最后,最多只会剩下一块石头。返回此石头最小的可能重量。如果没有石头剩下,就返回 0。
-
-提示:
-
-1. 1 <= stones.length <= 30
-2. 1 <= stones[i] <= 1000
-
-
-## 解题思路
-
-
-- 给出一个数组,数组里面的元素代表的是石头的重量。现在要求两个石头对碰,如果重量相同,两个石头都消失,如果一个重一个轻,剩下的石头是两者的差值。问经过这样的多次碰撞以后,能剩下的石头的重量最轻是多少?
-- 由于两两石头要发生碰撞,所以可以将整个数组可以分为两部分,如果这两部分的石头重量总和相差不大,那么经过若干次碰撞以后,剩下的石头重量一定是最小的。现在就需要找到这样两堆总重量差不多的两堆石头。这个问题就可以转化为 01 背包问题。从数组中找到 `sum/2` 重量的石头集合,如果一半能尽量达到 `sum/2`,那么另外一半和 `sum/2` 的差是最小的,最好的情况就是两堆石头的重量都是 `sum/2`,那么两两石头对碰以后最后都能消失。01 背包的经典模板可以参考第 416 题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func lastStoneWeightII(stones []int) int {
- sum := 0
- for _, v := range stones {
- sum += v
- }
- n, C, dp := len(stones), sum/2, make([]int, sum/2+1)
- for i := 0; i <= C; i++ {
- if stones[0] <= i {
- dp[i] = stones[0]
- } else {
- dp[i] = 0
- }
- }
- for i := 1; i < n; i++ {
- for j := C; j >= stones[i]; j-- {
- dp[j] = max(dp[j], dp[j-stones[i]]+stones[i])
- }
- }
- return sum - 2*dp[C]
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1051.Height-Checker.md b/website/content/ChapterFour/1051.Height-Checker.md
deleted file mode 100644
index 10653f21f..000000000
--- a/website/content/ChapterFour/1051.Height-Checker.md
+++ /dev/null
@@ -1,72 +0,0 @@
-# [1051. Height Checker](https://leetcode.com/problems/height-checker/)
-
-
-## 题目
-
-Students are asked to stand in non-decreasing order of heights for an annual photo.
-
-Return the minimum number of students that must move in order for all students to be standing in non-decreasing order of height.
-
-Notice that when a group of students is selected they can reorder in any possible way between themselves and the non selected students remain on their seats.
-
-**Example 1**:
-
-```
-Input: heights = [1,1,4,2,1,3]
-Output: 3
-Explanation:
-Current array : [1,1,4,2,1,3]
-Target array : [1,1,1,2,3,4]
-On index 2 (0-based) we have 4 vs 1 so we have to move this student.
-On index 4 (0-based) we have 1 vs 3 so we have to move this student.
-On index 5 (0-based) we have 3 vs 4 so we have to move this student.
-```
-
-**Example 2**:
-
-```
-Input: heights = [5,1,2,3,4]
-Output: 5
-```
-
-**Example 3**:
-
-```
-Input: heights = [1,2,3,4,5]
-Output: 0
-```
-
-**Constraints**:
-
-- `1 <= heights.length <= 100`
-- `1 <= heights[i] <= 100`
-
-## 题目大意
-
-学校在拍年度纪念照时,一般要求学生按照 非递减 的高度顺序排列。请你返回能让所有学生以 非递减 高度排列的最小必要移动人数。注意,当一组学生被选中时,他们之间可以以任何可能的方式重新排序,而未被选中的学生应该保持不动。
-
-
-## 解题思路
-
-- 给定一个高度数组,要求输出把这个数组按照非递减高度排列所需移动的最少次数。
-- 简单题,最少次数意味着每次移动,一步到位,一步就移动到它所在的最终位置。那么用一个辅助排好序的数组,一一比对计数即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func heightChecker(heights []int) int {
- result, checker := 0, []int{}
- checker = append(checker, heights...)
- sort.Ints(checker)
- for i := 0; i < len(heights); i++ {
- if heights[i] != checker[i] {
- result++
- }
- }
- return result
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1052.Grumpy-Bookstore-Owner.md b/website/content/ChapterFour/1052.Grumpy-Bookstore-Owner.md
deleted file mode 100755
index b63f9479f..000000000
--- a/website/content/ChapterFour/1052.Grumpy-Bookstore-Owner.md
+++ /dev/null
@@ -1,106 +0,0 @@
-# [1052. Grumpy Bookstore Owner](https://leetcode.com/problems/grumpy-bookstore-owner/)
-
-
-## 题目
-
-Today, the bookstore owner has a store open for `customers.length`minutes. Every minute, some number of customers (`customers[i]`) enter the store, and all those customers leave after the end of that minute.
-
-On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, `grumpy[i] = 1`, otherwise `grumpy[i] = 0`. When the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise they are satisfied.
-
-The bookstore owner knows a secret technique to keep themselves not grumpy for `X` minutes straight, but can only use it once.
-
-Return the maximum number of customers that can be satisfied throughout the day.
-
-**Example 1**:
-
- Input: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], X = 3
- Output: 16
- Explanation: The bookstore owner keeps themselves not grumpy for the last 3 minutes.
- The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.
-
-**Note**:
-
-- `1 <= X <= customers.length == grumpy.length <= 20000`
-- `0 <= customers[i] <= 1000`
-- `0 <= grumpy[i] <= 1`
-
-
-## 题目大意
-
-今天,书店老板有一家店打算试营业 customers.length 分钟。每分钟都有一些顾客(customers[i])会进入书店,所有这些顾客都会在那一分钟结束后离开。在某些时候,书店老板会生气。 如果书店老板在第 i 分钟生气,那么 grumpy[i] = 1,否则 grumpy[i] = 0。 当书店老板生气时,那一分钟的顾客就会不满意,不生气则他们是满意的。书店老板知道一个秘密技巧,能抑制自己的情绪,可以让自己连续 X 分钟不生气,但却只能使用一次。请你返回这一天营业下来,最多有多少客户能够感到满意的数量。
-
-提示:
-
-1. 1 <= X <= customers.length == grumpy.length <= 20000
-2. 0 <= customers[i] <= 1000
-3. 0 <= grumpy[i] <= 1
-
-
-
-## 解题思路
-
-
-- 给出一个顾客入店时间表和书店老板发脾气的时间表。两个数组的时间是一一对应的,即相同下标对应的相同的时间。书店老板可以控制自己在 X 分钟内不发火,但是只能控制一次。问有多少顾客能在书店老板不发火的时候在书店里看书。抽象一下,给出一个价值数组和一个装着 0 和 1 的数组,当价值数组的下标对应另外一个数组相同下标的值是 0 的时候,那么这个价值可以累加,当对应是 1 的时候,就不能加上这个价值。现在可以让装着 0 和 1 的数组中连续 X 个数都变成 0,问最终价值最大是多少?
-- 这道题是典型的滑动窗口的题目。最暴力的解法是滑动窗口右边界,当与左边界的距离等于 X 的时候,计算此刻对应的数组的总价值。当整个宽度为 X 的窗口滑过整个数组以后,输出维护的最大值即可。这个方法耗时比较长。因为每次计算数组总价值的时候都要遍历整个数组。这里是可以优化的地方。
-- 每次计算数组总价值的时候,其实目的是为了找到宽度为 X 的窗口对应里面为 1 的数累加和最大,因为如果把这个窗口里面的 1 都变成 0 以后,那么对最终价值的影响也最大。所以用一个变量 `customer0` 专门记录脾气数组中为 0 的对应的价值,累加起来。因为不管怎么改变,为 0 的永远为 0,唯一变化的是 1 变成 0 。用 `customer1` 专门记录脾气数组中为 1 的对应的价值。在窗口滑动过程中找到 `customer1` 的最大值。最终要求的最大值就是 `customer0 + maxCustomer1`。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 滑动窗口优化版
-func maxSatisfied(customers []int, grumpy []int, X int) int {
- customer0, customer1, maxCustomer1, left, right := 0, 0, 0, 0, 0
- for ; right < len(customers); right++ {
- if grumpy[right] == 0 {
- customer0 += customers[right]
- } else {
- customer1 += customers[right]
- for right-left+1 > X {
- if grumpy[left] == 1 {
- customer1 -= customers[left]
- }
- left++
- }
- if customer1 > maxCustomer1 {
- maxCustomer1 = customer1
- }
- }
- }
- return maxCustomer1 + customer0
-}
-
-// 解法二 滑动窗口暴力版
-func maxSatisfied1(customers []int, grumpy []int, X int) int {
- left, right, res := 0, -1, 0
- for left < len(customers) {
- if right+1 < len(customers) && right-left < X-1 {
- right++
- } else {
- if right-left+1 == X {
- res = max(res, sumSatisfied(customers, grumpy, left, right))
- }
- left++
- }
- }
- return res
-}
-
-func sumSatisfied(customers []int, grumpy []int, start, end int) int {
- sum := 0
- for i := 0; i < len(customers); i++ {
- if i < start || i > end {
- if grumpy[i] == 0 {
- sum += customers[i]
- }
- } else {
- sum += customers[i]
- }
- }
- return sum
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1054.Distant-Barcodes.md b/website/content/ChapterFour/1054.Distant-Barcodes.md
deleted file mode 100755
index 522c4e835..000000000
--- a/website/content/ChapterFour/1054.Distant-Barcodes.md
+++ /dev/null
@@ -1,92 +0,0 @@
-# [1054. Distant Barcodes](https://leetcode.com/problems/distant-barcodes/)
-
-
-## 题目
-
-In a warehouse, there is a row of barcodes, where the `i`-th barcode is `barcodes[i]`.
-
-Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.
-
-**Example 1**:
-
- Input: [1,1,1,2,2,2]
- Output: [2,1,2,1,2,1]
-
-**Example 2**:
-
- Input: [1,1,1,1,2,2,3,3]
- Output: [1,3,1,3,2,1,2,1]
-
-**Note**:
-
-1. `1 <= barcodes.length <= 10000`
-2. `1 <= barcodes[i] <= 10000`
-
-
-## 题目大意
-
-在一个仓库里,有一排条形码,其中第 i 个条形码为 barcodes[i]。请你重新排列这些条形码,使其中两个相邻的条形码 不能 相等。 你可以返回任何满足该要求的答案,此题保证存在答案。
-
-
-
-## 解题思路
-
-
-- 这一题和第 767 题原理是完全一样的。第 767 题是 Google 的面试题。
-- 解题思路比较简单,先按照每个数字的频次从高到低进行排序,注意会有频次相同的数字。排序以后,分别从第 0 号位和中间的位置开始往后取数,取完以后即为最终解。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "sort"
-
-func rearrangeBarcodes(barcodes []int) []int {
- bfs := barcodesFrequencySort(barcodes)
- if len(bfs) == 0 {
- return []int{}
- }
- res := []int{}
- j := (len(bfs)-1)/2 + 1
- for i := 0; i <= (len(bfs)-1)/2; i++ {
- res = append(res, bfs[i])
- if j < len(bfs) {
- res = append(res, bfs[j])
- }
- j++
- }
- return res
-}
-
-func barcodesFrequencySort(s []int) []int {
- if len(s) == 0 {
- return []int{}
- }
- sMap := map[int]int{} // 统计每个数字出现的频次
- cMap := map[int][]int{} // 按照频次作为 key 排序
- for _, b := range s {
- sMap[b]++
- }
- for key, value := range sMap {
- cMap[value] = append(cMap[value], key)
- }
- var keys []int
- for k := range cMap {
- keys = append(keys, k)
- }
- sort.Sort(sort.Reverse(sort.IntSlice(keys)))
- res := make([]int, 0)
- for _, k := range keys {
- for i := 0; i < len(cMap[k]); i++ {
- for j := 0; j < k; j++ {
- res = append(res, cMap[k][i])
- }
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1073.Adding-Two-Negabinary-Numbers.md b/website/content/ChapterFour/1073.Adding-Two-Negabinary-Numbers.md
deleted file mode 100755
index b8380b335..000000000
--- a/website/content/ChapterFour/1073.Adding-Two-Negabinary-Numbers.md
+++ /dev/null
@@ -1,146 +0,0 @@
-# [1073. Adding Two Negabinary Numbers](https://leetcode.com/problems/adding-two-negabinary-numbers/)
-
-
-## 题目
-
-Given two numbers `arr1` and `arr2` in base **-2**, return the result of adding them together.
-
-Each number is given in *array format*: as an array of 0s and 1s, from most significant bit to least significant bit. For example, `arr = [1,1,0,1]`represents the number `(-2)^3 + (-2)^2 + (-2)^0 = -3`. A number `arr` in *array format* is also guaranteed to have no leading zeros: either `arr == [0]` or `arr[0] == 1`.
-
-Return the result of adding `arr1` and `arr2` in the same format: as an array of 0s and 1s with no leading zeros.
-
-**Example 1**:
-
- Input: arr1 = [1,1,1,1,1], arr2 = [1,0,1]
- Output: [1,0,0,0,0]
- Explanation: arr1 represents 11, arr2 represents 5, the output represents 16.
-
-**Note**:
-
-1. `1 <= arr1.length <= 1000`
-2. `1 <= arr2.length <= 1000`
-3. `arr1` and `arr2` have no leading zeros
-4. `arr1[i]` is `0` or `1`
-5. `arr2[i]` is `0` or `1`
-
-
-## 题目大意
-
-给出基数为 -2 的两个数 arr1 和 arr2,返回两数相加的结果。数字以 数组形式 给出:数组由若干 0 和 1 组成,按最高有效位到最低有效位的顺序排列。例如,arr = [1,1,0,1] 表示数字 (-2)^3 + (-2)^2 + (-2)^0 = -3。数组形式 的数字也同样不含前导零:以 arr 为例,这意味着要么 arr == [0],要么 arr[0] == 1。
-
-返回相同表示形式的 arr1 和 arr2 相加的结果。两数的表示形式为:不含前导零、由若干 0 和 1 组成的数组。
-
-提示:
-
-- 1 <= arr1.length <= 1000
-- 1 <= arr2.length <= 1000
-- arr1 和 arr2 都不含前导零
-- arr1[i] 为 0 或 1
-- arr2[i] 为 0 或 1
-
-
-
-## 解题思路
-
-- 给出两个 -2 进制的数,要求计算出这两个数的和,最终表示形式还是 -2 进制。
-- 这一题最先想到的思路是先把两个 -2 进制的数转成 10 进制以后做加法,然后把结果表示成 -2 进制。这个思路可行,但是在提交以后会发现数据溢出 int64 了。在第 257 / 267 组测试数据会出现 WA。测试数据见 test 文件。另外换成 big.Add 也不是很方便。所以考虑换一个思路。
-- 这道题实际上就是求两个 -2 进制数的加法,为什么还要先转到 10 进制再换回 -2 进制呢?为何不直接进行 -2 进制的加法。所以开始尝试直接进行加法运算。加法是从低位到高位依次累加,遇到进位要从低往高位进位。所以从两个数组的末尾往前扫,模拟低位相加的过程。关键的是进位问题。进位分 3 种情况,依次来讨论:
-
-1. 进位到高位 k ,高位 k 上的两个数数字分别是 0 和 0 。这种情况最终 k 位为 1 。
-```c
- 证明:由于进位是由 k - 1 位进过来的,所以 k - 1 位是 2 个 1 。现在 k 位是 2 个 0,
- 所以加起来的和是 2 * (-2)^(k - 1)。
- 当 k 为奇数的时候,2 * (-2)^(k - 1) = (-1)^(k - 1)* 2 * 2^(k - 1) = 2^k
- 当 k 为偶数的时候,2 * (-2)^(k - 1) = (-1)^(k - 1)* 2 * 2^(k - 1) = -2^k
- 综合起来就是 (-2)^k,所以最终 k 位上有一个 1
-```
-2. 进位到高位 k ,高位 k 上的两个数数字分别是 0 和 1 。这种情况最终 k 位为 0 。
-```c
- 证明:由于进位是由 k - 1 位进过来的,所以 k - 1 位是 2 个 1。现在 k 位是 1 个 0 和 1 个 1,
- 所以加起来的和是 (-2)^k + 2 * (-2)^(k - 1)。
- 当 k 为奇数的时候,(-2)^k + 2 * (-2)^(k - 1) = -2^k + 2^k = 0
- 当 k 为偶数的时候,(-2)^k + 2 * (-2)^(k - 1) = 2^k - 2^k = 0
- 综合起来就是 0,所以最终 k 位上有一个 0
-```
-3. 进位到高位 k ,高位 k 上的两个数数字分别是 1 和 1 。这种情况最终 k 位为 1 。
-```c
- 证明:由于进位是由 k - 1 位进过来的,所以 k - 1 位是 2 个 1 。现在 k 位是 2 个 1,
- 所以加起来的和是 2 * (-2)^k + 2 * (-2)^(k - 1)。
- 当 k 为奇数的时候,2 * (-2)^k + 2 * (-2)^(k - 1) = -2^(k + 1) + 2^k = 2^k*(1 - 2) = -2^k
- 当 k 为偶数的时候,2 * (-2)^k + 2 * (-2)^(k - 1) = 2^(k + 1) - 2^k = 2^k*(2 - 1) = 2^k
- 综合起来就是 (-2)^k,所以最终 k 位上有一个 1
-```
-
-- 所以综上所属,-2 进制的进位和 2 进制的进位原理是完全一致的,只不过 -2 进制的进位是 -1,而 2 进制的进位是 1 。由于进位可能在 -2 进制上出现前导 0 ,所以最终结果需要再去除前导 0 。
-
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 模拟进位
-func addNegabinary(arr1 []int, arr2 []int) []int {
- carry, ans := 0, []int{}
- for i, j := len(arr1)-1, len(arr2)-1; i >= 0 || j >= 0 || carry != 0; {
- if i >= 0 {
- carry += arr1[i]
- i--
- }
- if j >= 0 {
- carry += arr2[j]
- j--
- }
- ans = append([]int{carry & 1}, ans...)
- carry = -(carry >> 1)
- }
- for idx, num := range ans { // 去掉前导 0
- if num != 0 {
- return ans[idx:]
- }
- }
- return []int{0}
-}
-
-// 解法二 标准的模拟,但是这个方法不能 AC,因为测试数据超过了 64 位,普通数据类型无法存储
-func addNegabinary1(arr1 []int, arr2 []int) []int {
- return intToNegabinary(negabinaryToInt(arr1) + negabinaryToInt(arr2))
-}
-
-func negabinaryToInt(arr []int) int {
- if len(arr) == 0 {
- return 0
- }
- res := 0
- for i := 0; i < len(arr)-1; i++ {
- if res == 0 {
- res += (-2) * arr[i]
- } else {
- res = res * (-2)
- res += (-2) * arr[i]
- }
- }
- return res + 1*arr[len(arr)-1]
-}
-
-func intToNegabinary(num int) []int {
- if num == 0 {
- return []int{0}
- }
- res := []int{}
-
- for num != 0 {
- remainder := num % (-2)
- num = num / (-2)
- if remainder < 0 {
- remainder += 2
- num++
- }
- res = append([]int{remainder}, res...)
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md b/website/content/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md
deleted file mode 100755
index a9a66a85e..000000000
--- a/website/content/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md
+++ /dev/null
@@ -1,143 +0,0 @@
-# [1074. Number of Submatrices That Sum to Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target/)
-
-
-## 题目
-
-Given a `matrix`, and a `target`, return the number of non-empty submatrices that sum to target.
-
-A submatrix `x1, y1, x2, y2` is the set of all cells `matrix[y]` with `x1 <= x <= x2` and `y1 <= y <= y2`.
-
-Two submatrices `(x1, y1, x2, y2)` and `(x1', y1', x2', y2')` are different if they have some coordinate that is different: for example, if `x1 != x1'`.
-
-**Example 1**:
-
- Input: matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0
- Output: 4
- Explanation: The four 1x1 submatrices that only contain 0.
-
-**Example 2**:
-
- Input: matrix = [[1,-1],[-1,1]], target = 0
- Output: 5
- Explanation: The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.
-
-**Note**:
-
-1. `1 <= matrix.length <= 300`
-2. `1 <= matrix[0].length <= 300`
-3. `-1000 <= matrix[i] <= 1000`
-4. `-10^8 <= target <= 10^8`
-
-
-## 题目大意
-
-给出矩阵 matrix 和目标值 target,返回元素总和等于目标值的非空子矩阵的数量。
-
-子矩阵 x1, y1, x2, y2 是满足 x1 <= x <= x2 且 y1 <= y <= y2 的所有单元 matrix[x][y] 的集合。
-
-如果 (x1, y1, x2, y2) 和 (x1', y1', x2', y2') 两个子矩阵中部分坐标不同(如:x1 != x1'),那么这两个子矩阵也不同。
-
-
-提示:
-
-1. 1 <= matrix.length <= 300
-2. 1 <= matrix[0].length <= 300
-3. -1000 <= matrix[i] <= 1000
-4. -10^8 <= target <= 10^8
-
-
-
-
-## 解题思路
-
-- 给出一个矩阵,要求在这个矩阵中找出子矩阵的和等于 target 的矩阵个数。
-- 这一题读完题感觉是滑动窗口的二维版本。如果把它拍扁,在一维数组中,求连续的子数组和为 target,这样就很好做。如果这题不降维,纯暴力解是 O(n^6)。如何优化降低时间复杂度呢?
-- 联想到第 1 题 Two Sum 问题,可以把 2 个数求和的问题优化到 O(n)。这里也用类似的思想,用一个 map 来保存行方向上曾经出现过的累加和,相减就可以得到本行的和。这里可能读者会有疑惑,为什么不能每一行都单独保存呢?为什么一定要用累加和相减的方式来获取每一行的和呢?因为这一题要求子矩阵所有解,如果只单独保存每一行的和,只能求得小的子矩阵,子矩阵和子矩阵组成的大矩阵的情况会漏掉(当然再循环一遍,把子矩阵累加起来也可以,但是这样就多了一层循环了),例如子矩阵是 1*4 的,但是 2 个这样的子矩阵摞在一起形成 2 * 4 也能满足条件,如果不用累加和的办法,只单独存每一行的和,最终还要有组合的步骤。经过这样的优化,可以从 O(n^6) 优化到 O(n^4),能 AC 这道题,但是时间复杂度太高了。如何优化?
-- 首先,子矩阵需要上下左右 4 个边界,4 个变量控制循环就需要 O(n^4),行和列的区间累加还需要 O(n^2)。行和列的区间累加可以通过 preSum 来解决。例如 `sum[i,j] = sum[j] - sum[i - 1]`,其中 sum[k] 中存的是从 0 到 K 的累加和: 
-
- 那么一个区间内的累加和可以由这个区间的右边界减去区间左边界左边的那个累加和得到(由于是闭区间,所需要取左边界左边的和)。经过这样的处理,列方向的维度就被我们拍扁了。
-
-- 再来看看行方向的和,现在每一列的和都可以通过区间相减的方法得到。那么这道题就变成了第 1 题 Two Sum 的问题了。Two Sum 问题只需要 O(n) 的时间复杂度求解,这一题由于是二维的,所以两个列的边界还需要循环,所以最终优化下来的时间复杂度是 O(n^3)。计算 presum 可以直接用原数组,所以空间复杂度只有一个 O(n) 的字典。
-- 类似思路的题目有第 560 题,第 304 题。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func numSubmatrixSumTarget(matrix [][]int, target int) int {
- m, n, res := len(matrix), len(matrix[0]), 0
- for row := range matrix {
- for col := 1; col < len(matrix[row]); col++ {
- matrix[row][col] += matrix[row][col-1]
- }
- }
- for i := 0; i < n; i++ {
- for j := i; j < n; j++ {
- counterMap, sum := make(map[int]int, m), 0
- counterMap[0] = 1 // 题目保证一定有解,所以这里初始化是 1
- for row := 0; row < m; row++ {
- if i > 0 {
- sum += matrix[row][j] - matrix[row][i-1]
- } else {
- sum += matrix[row][j]
- }
- res += counterMap[sum-target]
- counterMap[sum]++
- }
- }
- }
- return res
-}
-
-// 暴力解法 O(n^4)
-func numSubmatrixSumTarget1(matrix [][]int, target int) int {
- m, n, res, sum := len(matrix), len(matrix[0]), 0, 0
- for i := 0; i < n; i++ {
- for j := i; j < n; j++ {
- counterMap := map[int]int{}
- counterMap[0] = 1 // 题目保证一定有解,所以这里初始化是 1
- sum = 0
- for row := 0; row < m; row++ {
- for k := i; k <= j; k++ {
- sum += matrix[row][k]
- }
- res += counterMap[sum-target]
- counterMap[sum]++
- }
- }
- }
- return res
-}
-
-// 暴力解法超时! O(n^6)
-func numSubmatrixSumTarget2(matrix [][]int, target int) int {
- res := 0
- for startx := 0; startx < len(matrix); startx++ {
- for starty := 0; starty < len(matrix[startx]); starty++ {
- for endx := startx; endx < len(matrix); endx++ {
- for endy := starty; endy < len(matrix[startx]); endy++ {
- if sumSubmatrix(matrix, startx, starty, endx, endy) == target {
- //fmt.Printf("startx = %v, starty = %v, endx = %v, endy = %v\n", startx, starty, endx, endy)
- res++
- }
- }
- }
- }
- }
- return res
-}
-
-func sumSubmatrix(matrix [][]int, startx, starty, endx, endy int) int {
- sum := 0
- for i := startx; i <= endx; i++ {
- for j := starty; j <= endy; j++ {
- sum += matrix[i][j]
- }
- }
- return sum
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1078.Occurrences-After-Bigram.md b/website/content/ChapterFour/1078.Occurrences-After-Bigram.md
deleted file mode 100755
index 6d1806e02..000000000
--- a/website/content/ChapterFour/1078.Occurrences-After-Bigram.md
+++ /dev/null
@@ -1,64 +0,0 @@
-# [1078. Occurrences After Bigram](https://leetcode.com/problems/occurrences-after-bigram/)
-
-
-## 题目
-
-Given words `first` and `second`, consider occurrences in some `text` of the form "`first second third`", where `second` comes immediately after `first`, and `third`comes immediately after `second`.
-
-For each such occurrence, add "`third`" to the answer, and return the answer.
-
-**Example 1**:
-
- Input: text = "alice is a good girl she is a good student", first = "a", second = "good"
- Output: ["girl","student"]
-
-**Example 2**:
-
- Input: text = "we will we will rock you", first = "we", second = "will"
- Output: ["we","rock"]
-
-**Note**:
-
-1. `1 <= text.length <= 1000`
-2. `text` consists of space separated words, where each word consists of lowercase English letters.
-3. `1 <= first.length, second.length <= 10`
-4. `first` and `second` consist of lowercase English letters.
-
-
-## 题目大意
-
-
-给出第一个词 first 和第二个词 second,考虑在某些文本 text 中可能以 "first second third" 形式出现的情况,其中 second 紧随 first 出现,third 紧随 second 出现。对于每种这样的情况,将第三个词 "third" 添加到答案中,并返回答案。
-
-
-
-
-## 解题思路
-
-
-- 简单题。给出一个 text,要求找出紧接在 first 和 second 后面的那个字符串,有多个就输出多个。解法很简单,先分解出 words 每个字符串,然后依次遍历进行字符串匹配。匹配到 first 和 second 以后,输出之后的那个字符串。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strings"
-
-func findOcurrences(text string, first string, second string) []string {
- var res []string
- words := strings.Split(text, " ")
- if len(words) < 3 {
- return []string{}
- }
- for i := 2; i < len(words); i++ {
- if words[i-2] == first && words[i-1] == second {
- res = append(res, words[i])
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1089.Duplicate-Zeros.md b/website/content/ChapterFour/1089.Duplicate-Zeros.md
deleted file mode 100644
index 3c8224749..000000000
--- a/website/content/ChapterFour/1089.Duplicate-Zeros.md
+++ /dev/null
@@ -1,58 +0,0 @@
-# [1089. Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/)
-
-
-## 题目
-
-Given a fixed length array `arr` of integers, duplicate each occurrence of zero, shifting the remaining elements to the right.
-
-Note that elements beyond the length of the original array are not written.
-
-Do the above modifications to the input array **in place**, do not return anything from your function.
-
-**Example 1**:
-
-```
-Input: [1,0,2,3,0,4,5,0]
-Output: null
-Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
-```
-
-**Example 2**:
-
-```
-Input: [1,2,3]
-Output: null
-Explanation: After calling your function, the input array is modified to: [1,2,3]
-```
-
-**Note**:
-
-1. `1 <= arr.length <= 10000`
-2. `0 <= arr[i] <= 9`
-
-## 题目大意
-
-给你一个长度固定的整数数组 arr,请你将该数组中出现的每个零都复写一遍,并将其余的元素向右平移。注意:请不要在超过该数组长度的位置写入元素。要求:请对输入的数组 就地 进行上述修改,不要从函数返回任何东西。
-
-
-## 解题思路
-
-- 给一个固定长度的数组,把数组元素为 0 的元素都往后复制一遍,后面的元素往后移,超出数组长度的部分删除。
-- 简单题,按照题意,用 append 和 slice 操作即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func duplicateZeros(arr []int) {
- for i := 0; i < len(arr); i++ {
- if arr[i] == 0 && i+1 < len(arr) {
- arr = append(arr[:i+1], arr[i:len(arr)-1]...)
- i++
- }
- }
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1093.Statistics-from-a-Large-Sample.md b/website/content/ChapterFour/1093.Statistics-from-a-Large-Sample.md
deleted file mode 100755
index 7ebf2a326..000000000
--- a/website/content/ChapterFour/1093.Statistics-from-a-Large-Sample.md
+++ /dev/null
@@ -1,95 +0,0 @@
-# [1093. Statistics from a Large Sample](https://leetcode.com/problems/statistics-from-a-large-sample/)
-
-
-## 题目
-
-We sampled integers between `0` and `255`, and stored the results in an array `count`: `count[k]` is the number of integers we sampled equal to `k`.
-
-Return the minimum, maximum, mean, median, and mode of the sample respectively, as an array of **floating point numbers**. The mode is guaranteed to be unique.
-
-*(Recall that the median of a sample is:*
-
-- *The middle element, if the elements of the sample were sorted and the number of elements is odd;*
-- *The average of the middle two elements, if the elements of the sample were sorted and the number of elements is even.)*
-
-**Example 1**:
-
- Input: count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- Output: [1.00000,3.00000,2.37500,2.50000,3.00000]
-
-**Example 2**:
-
- Input: count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- Output: [1.00000,4.00000,2.18182,2.00000,1.00000]
-
-**Constraints:**
-
-1. `count.length == 256`
-2. `1 <= sum(count) <= 10^9`
-3. The mode of the sample that count represents is unique.
-4. Answers within `10^-5` of the true value will be accepted as correct.
-
-
-## 题目大意
-
-我们对 0 到 255 之间的整数进行采样,并将结果存储在数组 count 中:count[k] 就是整数 k 的采样个数。
-
-我们以 浮点数 数组的形式,分别返回样本的最小值、最大值、平均值、中位数和众数。其中,众数是保证唯一的。我们先来回顾一下中位数的知识:
-
-- 如果样本中的元素有序,并且元素数量为奇数时,中位数为最中间的那个元素;
-- 如果样本中的元素有序,并且元素数量为偶数时,中位数为中间的两个元素的平均值。
-
-
-
-## 解题思路
-
-
-- 这个问题的关键需要理解题目的意思,什么是采样?`count[k]` 就是整数 `k` 的采样个数。
-- 题目要求返回样本的最小值、最大值、平均值、中位数和众数。最大值和最小值就很好处理,只需要遍历 count 判断最小的非 0 的 index 就是最小值,最大的非 0 的 index 就是最大值。平均值也非常好处理,对于所有非 0 的 count,我们通过累加 count[k] * index 得到所有数的和,然后除上所有非 0 的 count 的和。)
-
-- 众数也非常容易,只需统计 count 值最大时的 index 即可。
-- 中位数的处理相对麻烦一些,因为需要分非 0 的 count 之和是奇数还是偶数两种情况。先假设非 0 的 count 和为 cnt,那么如果 cnt 是奇数的话,只需要找到 cnt/2 的位置即可,通过不断累加 count 的值,直到累加和超过 ≥ cnt/2。如果 cnt 是偶数的话,需要找到 cnt/2 + 1 和 cnt/2 的位置,找法和奇数情况相同,不过需要找两次(可以放到一个循环中做两次判断)。
-
-## 代码
-
-```go
-
-package leetcode
-
-func sampleStats(count []int) []float64 {
- res := make([]float64, 5)
- res[0] = 255
- sum := 0
- for _, val := range count {
- sum += val
- }
- left, right := sum/2, sum/2
- if (sum % 2) == 0 {
- right++
- }
- pre, mode := 0, 0
- for i, val := range count {
- if val > 0 {
- if i < int(res[0]) {
- res[0] = float64(i)
- }
- res[1] = float64(i)
- }
- res[2] += float64(i*val) / float64(sum)
- if pre < left && pre+val >= left {
- res[3] += float64(i) / 2.0
- }
- if pre < right && pre+val >= right {
- res[3] += float64(i) / 2.0
- }
- pre += val
-
- if val > mode {
- mode = val
- res[4] = float64(i)
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1105.Filling-Bookcase-Shelves.md b/website/content/ChapterFour/1105.Filling-Bookcase-Shelves.md
deleted file mode 100755
index 5c248f89c..000000000
--- a/website/content/ChapterFour/1105.Filling-Bookcase-Shelves.md
+++ /dev/null
@@ -1,68 +0,0 @@
-# [1105. Filling Bookcase Shelves](https://leetcode.com/problems/filling-bookcase-shelves/)
-
-
-## 题目
-
-We have a sequence of `books`: the `i`-th book has thickness `books[i][0]`and height `books[i][1]`.
-
-We want to place these books **in order** onto bookcase shelves that have total width `shelf_width`.
-
-We choose some of the books to place on this shelf (such that the sum of their thickness is `<= shelf_width`), then build another level of shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down. We repeat this process until there are no more books to place.
-
-Note again that at each step of the above process, the order of the books we place is the same order as the given sequence of books. For example, if we have an ordered list of 5 books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.
-
-Return the minimum possible height that the total bookshelf can be after placing shelves in this manner.
-
-**Example 1**:
-
-
-
- Input: books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelf_width = 4
- Output: 6
- Explanation:
- The sum of the heights of the 3 shelves are 1 + 3 + 2 = 6.
- Notice that book number 2 does not have to be on the first shelf.
-
-**Constraints:**
-
-- `1 <= books.length <= 1000`
-- `1 <= books[i][0] <= shelf_width <= 1000`
-- `1 <= books[i][1] <= 1000`
-
-## 题目大意
-
-附近的家居城促销,你买回了一直心仪的可调节书架,打算把自己的书都整理到新的书架上。你把要摆放的书 books 都整理好,叠成一摞:从上往下,第 i 本书的厚度为 books[i][0],高度为 books[i][1]。按顺序将这些书摆放到总宽度为 shelf\_width 的书架上。
-
-先选几本书放在书架上(它们的厚度之和小于等于书架的宽度 shelf_width),然后再建一层书架。重复这个过程,直到把所有的书都放在书架上。
-
-需要注意的是,在上述过程的每个步骤中,摆放书的顺序与你整理好的顺序相同。 例如,如果这里有 5 本书,那么可能的一种摆放情况是:第一和第二本书放在第一层书架上,第三本书放在第二层书架上,第四和第五本书放在最后一层书架上。每一层所摆放的书的最大高度就是这一层书架的层高,书架整体的高度为各层高之和。以这种方式布置书架,返回书架整体可能的最小高度。
-
-
-
-## 解题思路
-
-- 给出一个数组,数组里面每个元素代表的是一个本书的宽度和高度。要求按照书籍的顺序,把书摆到宽度为 `shelf_width` 的书架上。问最终放下所有书籍以后,书架的最小高度。
-- 这一题的解题思路是动态规划。`dp[i]` 代表放置前 `i` 本书所需要的书架最小高度。初始值 dp[0] = 0,其他为最大值 1000*1000。遍历每一本书,把当前这本书作为书架最后一层的最后一本书,将这本书之前的书向后调整,看看是否可以减少之前的书架高度。状态转移方程为 `dp[i] = min(dp[i] , dp[j - 1] + h)`,其中 `j` 表示最后一层所能容下书籍的索引,`h` 表示最后一层最大高度。`j` 调整完一遍以后就能找出书架最小高度值了。时间复杂度 O(n^2)。
-
-## 代码
-
-```go
-
-package leetcode
-
-func minHeightShelves(books [][]int, shelfWidth int) int {
- dp := make([]int, len(books)+1)
- dp[0] = 0
- for i := 1; i <= len(books); i++ {
- width, height := books[i-1][0], books[i-1][1]
- dp[i] = dp[i-1] + height
- for j := i - 1; j > 0 && width+books[j-1][0] <= shelfWidth; j-- {
- height = max(height, books[j-1][1])
- width += books[j-1][0]
- dp[i] = min(dp[i], dp[j-1]+height)
- }
- }
- return dp[len(books)]
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1108.Defanging-an-IP-Address.md b/website/content/ChapterFour/1108.Defanging-an-IP-Address.md
deleted file mode 100755
index 0eb4a7f90..000000000
--- a/website/content/ChapterFour/1108.Defanging-an-IP-Address.md
+++ /dev/null
@@ -1,54 +0,0 @@
-# [1108. Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/)
-
-
-## 题目
-
-Given a valid (IPv4) IP `address`, return a defanged version of that IP address.
-
-A *defanged IP address* replaces every period `"."` with `"[.]"`.
-
-**Example 1**:
-
- Input: address = "1.1.1.1"
- Output: "1[.]1[.]1[.]1"
-
-**Example 2**:
-
- Input: address = "255.100.50.0"
- Output: "255[.]100[.]50[.]0"
-
-**Constraints:**
-
-- The given `address` is a valid IPv4 address.
-
-## 题目大意
-
-
-给你一个有效的 IPv4 地址 address,返回这个 IP 地址的无效化版本。所谓无效化 IP 地址,其实就是用 "[.]" 代替了每个 "."。
-
-
-提示:
-
-- 给出的 address 是一个有效的 IPv4 地址
-
-
-
-## 解题思路
-
-- 给出一个 IP 地址,要求把点替换成 `[.]`。
-- 简单题,按照题意替换即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strings"
-
-func defangIPaddr(address string) string {
- return strings.Replace(address, ".", "[.]", -1)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1110.Delete-Nodes-And-Return-Forest.md b/website/content/ChapterFour/1110.Delete-Nodes-And-Return-Forest.md
deleted file mode 100644
index 9d3c214c6..000000000
--- a/website/content/ChapterFour/1110.Delete-Nodes-And-Return-Forest.md
+++ /dev/null
@@ -1,82 +0,0 @@
-# [1110. Delete Nodes And Return Forest](https://leetcode.com/problems/delete-nodes-and-return-forest/)
-
-
-## 题目
-
-Given the `root` of a binary tree, each node in the tree has a distinct value.
-
-After deleting all nodes with a value in `to_delete`, we are left with a forest (a disjoint union of trees).
-
-Return the roots of the trees in the remaining forest. You may return the result in any order.
-
-**Example 1**:
-
-
-
-```
-Input: root = [1,2,3,4,5,6,7], to_delete = [3,5]
-Output: [[1,2,null,4],[6],[7]]
-```
-
-**Constraints**:
-
-- The number of nodes in the given tree is at most `1000`.
-- Each node has a distinct value between `1` and `1000`.
-- `to_delete.length <= 1000`
-- `to_delete` contains distinct values between `1` and `1000`.
-
-
-## 题目大意
-
-给出二叉树的根节点 root,树上每个节点都有一个不同的值。如果节点值在 to_delete 中出现,我们就把该节点从树上删去,最后得到一个森林(一些不相交的树构成的集合)。返回森林中的每棵树。你可以按任意顺序组织答案。
-
-
-提示:
-
-- 树中的节点数最大为 1000。
-- 每个节点都有一个介于 1 到 1000 之间的值,且各不相同。
-- to_delete.length <= 1000
-- to_delete 包含一些从 1 到 1000、各不相同的值。
-
-
-
-## 解题思路
-
-- 给出一棵树,再给出一个数组,要求删除数组中相同元素值的节点。输出最终删除以后的森林。
-- 简单题。边遍历树,边删除数组中的元素。这里可以先把数组里面的元素放入 map 中,加速查找。遇到相同的元素就删除节点。这里需要特殊判断的是当前删除的节点是否是根节点,如果是根节点需要根据条件置空它的左节点或者右节点。
-
-## 代码
-
-```go
-func delNodes(root *TreeNode, toDelete []int) []*TreeNode {
- if root == nil {
- return nil
- }
- res, deleteMap := []*TreeNode{}, map[int]bool{}
- for _, v := range toDelete {
- deleteMap[v] = true
- }
- dfsDelNodes(root, deleteMap, true, &res)
- return res
-}
-
-func dfsDelNodes(root *TreeNode, toDel map[int]bool, isRoot bool, res *[]*TreeNode) bool {
- if root == nil {
- return false
- }
- if isRoot && !toDel[root.Val] {
- *res = append(*res, root)
- }
- isRoot = false
- if toDel[root.Val] {
- isRoot = true
- }
- if dfsDelNodes(root.Left, toDel, isRoot, res) {
- root.Left = nil
- }
- if dfsDelNodes(root.Right, toDel, isRoot, res) {
- root.Right = nil
- }
- return isRoot
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings.md b/website/content/ChapterFour/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings.md
deleted file mode 100755
index 8f4d8f59d..000000000
--- a/website/content/ChapterFour/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings.md
+++ /dev/null
@@ -1,132 +0,0 @@
-# [1111. Maximum Nesting Depth of Two Valid Parentheses Strings](https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/)
-
-
-## 题目
-
-A string is a *valid parentheses string* (denoted VPS) if and only if it consists of `"("` and `")"` characters only, and:
-
-- It is the empty string, or
-- It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are VPS's, or
-- It can be written as `(A)`, where `A` is a VPS.
-
-We can similarly define the *nesting depth* `depth(S)` of any VPS `S` as follows:
-
-- `depth("") = 0`
-- `depth(A + B) = max(depth(A), depth(B))`, where `A` and `B` are VPS's
-- `depth("(" + A + ")") = 1 + depth(A)`, where `A` is a VPS.
-
-For example, `""`, `"()()"`, and `"()(()())"` are VPS's (with nesting depths 0, 1, and 2), and `")("` and `"(()"` are not VPS's.
-
-Given a VPS seq, split it into two disjoint subsequences `A` and `B`, such that `A` and `B` are VPS's (and `A.length + B.length = seq.length`).
-
-Now choose **any** such `A` and `B` such that `max(depth(A), depth(B))` is the minimum possible value.
-
-Return an `answer` array (of length `seq.length`) that encodes such a choice of `A` and `B`: `answer[i] = 0` if `seq[i]` is part of `A`, else `answer[i] = 1`. Note that even though multiple answers may exist, you may return any of them.
-
-**Example 1**:
-
- Input: seq = "(()())"
- Output: [0,1,1,1,1,0]
-
-**Example 2**:
-
- Input: seq = "()(())()"
- Output: [0,0,0,1,1,0,1,1]
-
-**Constraints:**
-
-- `1 <= seq.size <= 10000`
-
-
-## 题目大意
-
-
-有效括号字符串 仅由 "(" 和 ")" 构成,并符合下述几个条件之一:
-
-- 空字符串
-- 连接,可以记作 AB(A 与 B 连接),其中 A 和 B 都是有效括号字符串
-- 嵌套,可以记作 (A),其中 A 是有效括号字符串
-
-类似地,我们可以定义任意有效括号字符串 s 的 嵌套深度 depth(S):
-
-- s 为空时,depth("") = 0
-- s 为 A 与 B 连接时,depth(A + B) = max(depth(A), depth(B)),其中 A 和 B 都是有效括号字符串
-- s 为嵌套情况,depth("(" + A + ")") = 1 + depth(A),其中 A 是有效括号字符串
-
-
-例如:"","()()",和 "()(()())" 都是有效括号字符串,嵌套深度分别为 0,1,2,而 ")(" 和 "(()" 都不是有效括号字符串。
-
-
-
-给你一个有效括号字符串 seq,将其分成两个不相交的子序列 A 和 B,且 A 和 B 满足有效括号字符串的定义(注意:A.length + B.length = seq.length)。
-
-现在,你需要从中选出 任意 一组有效括号字符串 A 和 B,使 max(depth(A), depth(B)) 的可能取值最小。
-
-返回长度为 seq.length 答案数组 answer ,选择 A 还是 B 的编码规则是:如果 seq[i] 是 A 的一部分,那么 answer[i] = 0。否则,answer[i] = 1。即便有多个满足要求的答案存在,你也只需返回 一个。
-
-
-
-## 解题思路
-
-- 给出一个括号字符串。选出 A 部分和 B 部分,使得 `max(depth(A), depth(B))` 值最小。在最终的数组中输出 0 和 1,0 标识是 A 部分,1 标识是 B 部分。
-- 这一题想要 `max(depth(A), depth(B))` 值最小,可以使用贪心思想。如果 A 部分和 B 部分都尽快括号匹配,不深层次嵌套,那么总的层次就会变小。只要让嵌套的括号中属于 A 的和属于 B 的间隔排列即可。例如:“`(((())))`”,上面的字符串的嵌套深度是 4,按照上述的贪心思想,则标记为 0101 1010。
-- 这一题也可以用二分的思想来解答。把深度平分给 A 部分和 B 部分。
- - 第一次遍历,先计算最大深度
- - 第二次遍历,把深度小于等于最大深度一半的括号标记为 0(给 A 部分),否则标记为 1(给 B 部分)
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 二分思想
-func maxDepthAfterSplit(seq string) []int {
- stack, maxDepth, res := 0, 0, []int{}
- for _, v := range seq {
- if v == '(' {
- stack++
- maxDepth = max(stack, maxDepth)
- } else {
- stack--
- }
- }
- stack = 0
- for i := 0; i < len(seq); i++ {
- if seq[i] == '(' {
- stack++
- if stack <= maxDepth/2 {
- res = append(res, 0)
- } else {
- res = append(res, 1)
- }
- } else {
- if stack <= maxDepth/2 {
- res = append(res, 0)
- } else {
- res = append(res, 1)
- }
- stack--
- }
- }
- return res
-}
-
-// 解法二 模拟
-func maxDepthAfterSplit1(seq string) []int {
- stack, top, res := make([]int, len(seq)), -1, make([]int, len(seq))
- for i, r := range seq {
- if r == ')' {
- res[i] = res[stack[top]]
- top--
- continue
- }
- top++
- stack[top] = i
- res[i] = top % 2
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1122.Relative-Sort-Array.md b/website/content/ChapterFour/1122.Relative-Sort-Array.md
deleted file mode 100755
index 7a536881f..000000000
--- a/website/content/ChapterFour/1122.Relative-Sort-Array.md
+++ /dev/null
@@ -1,101 +0,0 @@
-# [1122. Relative Sort Array](https://leetcode.com/problems/relative-sort-array/)
-
-
-## 题目
-
-Given two arrays `arr1` and `arr2`, the elements of `arr2` are distinct, and all elements in `arr2` are also in `arr1`.
-
-Sort the elements of `arr1` such that the relative ordering of items in `arr1` are the same as in `arr2`. Elements that don't appear in `arr2` should be placed at the end of `arr1` in **ascending** order.
-
-**Example 1**:
-
- Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]
- Output: [2,2,2,1,4,3,3,9,6,7,19]
-
-**Constraints:**
-
-- `arr1.length, arr2.length <= 1000`
-- `0 <= arr1[i], arr2[i] <= 1000`
-- Each `arr2[i]` is distinct.
-- Each `arr2[i]` is in `arr1`.
-
-
-## 题目大意
-
-
-给你两个数组,arr1 和 arr2,
-
-- arr2 中的元素各不相同
-- arr2 中的每个元素都出现在 arr1 中
-
-对 arr1 中的元素进行排序,使 arr1 中项的相对顺序和 arr2 中的相对顺序相同。未在 arr2 中出现过的元素需要按照升序放在 arr1 的末尾。
-
-提示:
-
-- arr1.length, arr2.length <= 1000
-- 0 <= arr1[i], arr2[i] <= 1000
-- arr2 中的元素 arr2[i] 各不相同
-- arr2 中的每个元素 arr2[i] 都出现在 arr1 中
-
-
-
-## 解题思路
-
-- 给出 2 个数组 A 和 B,A 中包含 B 中的所有元素。要求 A 按照 B 的元素顺序排序,B 中没有的元素再接着排在后面,从小到大排序。
-- 这一题有多种解法。一种暴力的解法就是依照题意,先把 A 中的元素都统计频次放在 map 中,然后 按照 B 的顺序输出,接着再把剩下的元素排序接在后面。还有一种桶排序的思想,由于题目限定了 A 的大小是 1000,这个数量级很小,所以可以用 1001 个桶装所有的数,把数都放在桶里,这样默认就已经排好序了。接下来的做法和前面暴力解法差不多,按照频次输出。B 中以外的元素就按照桶的顺序依次输出即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "sort"
-
-// 解法一 桶排序,时间复杂度 O(n^2)
-func relativeSortArray(A, B []int) []int {
- count := [1001]int{}
- for _, a := range A {
- count[a]++
- }
- res := make([]int, 0, len(A))
- for _, b := range B {
- for count[b] > 0 {
- res = append(res, b)
- count[b]--
- }
- }
- for i := 0; i < 1001; i++ {
- for count[i] > 0 {
- res = append(res, i)
- count[i]--
- }
- }
- return res
-}
-
-// 解法二 模拟,时间复杂度 O(n^2)
-func relativeSortArray1(arr1 []int, arr2 []int) []int {
- leftover, m, res := []int{}, make(map[int]int), []int{}
- for _, v := range arr1 {
- m[v]++
- }
- for _, s := range arr2 {
- count := m[s]
- for i := 0; i < count; i++ {
- res = append(res, s)
- }
- m[s] = 0
- }
- for v, count := range m {
- for i := 0; i < count; i++ {
- leftover = append(leftover, v)
- }
- }
- sort.Ints(leftover)
- res = append(res, leftover...)
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1123.Lowest-Common-Ancestor-of-Deepest-Leaves.md b/website/content/ChapterFour/1123.Lowest-Common-Ancestor-of-Deepest-Leaves.md
deleted file mode 100755
index f2838c9d5..000000000
--- a/website/content/ChapterFour/1123.Lowest-Common-Ancestor-of-Deepest-Leaves.md
+++ /dev/null
@@ -1,101 +0,0 @@
-# [1123. Lowest Common Ancestor of Deepest Leaves](https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves/)
-
-
-## 题目
-
-Given a rooted binary tree, return the lowest common ancestor of its deepest leaves.
-
-Recall that:
-
-- The node of a binary tree is a *leaf* if and only if it has no children
-- The *depth* of the root of the tree is 0, and if the depth of a node is `d`, the depth of each of its children is `d+1`.
-- The *lowest common ancestor* of a set `S` of nodes is the node `A` with the largest depth such that every node in S is in the subtree with root `A`.
-
-**Example 1**:
-
- Input: root = [1,2,3]
- Output: [1,2,3]
- Explanation:
- The deepest leaves are the nodes with values 2 and 3.
- The lowest common ancestor of these leaves is the node with value 1.
- The answer returned is a TreeNode object (not an array) with serialization "[1,2,3]".
-
-**Example 2**:
-
- Input: root = [1,2,3,4]
- Output: [4]
-
-**Example 3**:
-
- Input: root = [1,2,3,4,5]
- Output: [2,4,5]
-
-**Constraints:**
-
-- The given tree will have between 1 and 1000 nodes.
-- Each node of the tree will have a distinct value between 1 and 1000.
-
-
-## 题目大意
-
-
-给你一个有根节点的二叉树,找到它最深的叶节点的最近公共祖先。
-
-回想一下:
-
-- 叶节点 是二叉树中没有子节点的节点
-- 树的根节点的 深度 为 0,如果某一节点的深度为 d,那它的子节点的深度就是 d+1
-- 如果我们假定 A 是一组节点 S 的 最近公共祖先,S 中的每个节点都在以 A 为根节点的子树中,且 A 的深度达到此条件下可能的最大值。
-
-
-提示:
-
-- 给你的树中将有 1 到 1000 个节点。
-- 树中每个节点的值都在 1 到 1000 之间。
-
-
-## 解题思路
-
-
-- 给出一颗树,找出最深的叶子节点的最近公共祖先 LCA。
-- 这一题思路比较直接。先遍历找到最深的叶子节点,如果左右子树的最深的叶子节点深度相同,那么当前节点就是它们的最近公共祖先。如果左右子树的最深的深度不等,那么需要继续递归往下找符合题意的 LCA。如果最深的叶子节点没有兄弟,那么公共父节点就是叶子本身,否则返回它的 LCA。
-- 有几个特殊的测试用例,见测试文件。特殊的点就是最深的叶子节点没有兄弟节点的情况。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
-func lcaDeepestLeaves(root *TreeNode) *TreeNode {
- if root == nil {
- return nil
- }
- lca, maxLevel := &TreeNode{}, 0
- lcaDeepestLeavesDFS(&lca, &maxLevel, 0, root)
- return lca
-}
-
-func lcaDeepestLeavesDFS(lca **TreeNode, maxLevel *int, depth int, root *TreeNode) int {
- *maxLevel = max(*maxLevel, depth)
- if root == nil {
- return depth
- }
- depthLeft := lcaDeepestLeavesDFS(lca, maxLevel, depth+1, root.Left)
- depthRight := lcaDeepestLeavesDFS(lca, maxLevel, depth+1, root.Right)
- if depthLeft == *maxLevel && depthRight == *maxLevel {
- *lca = root
- }
- return max(depthLeft, depthRight)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1128.Number-of-Equivalent-Domino-Pairs.md b/website/content/ChapterFour/1128.Number-of-Equivalent-Domino-Pairs.md
deleted file mode 100755
index cc946659c..000000000
--- a/website/content/ChapterFour/1128.Number-of-Equivalent-Domino-Pairs.md
+++ /dev/null
@@ -1,68 +0,0 @@
-# [1128. Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs/)
-
-
-## 题目
-
-Given a list of `dominoes`, `dominoes[i] = [a, b]` is *equivalent* to `dominoes[j] = [c, d]` if and only if either (`a==c` and `b==d`), or (`a==d` and `b==c`) - that is, one domino can be rotated to be equal to another domino.
-
-Return the number of pairs `(i, j)` for which `0 <= i < j < dominoes.length`, and `dominoes[i]` is equivalent to `dominoes[j]`.
-
-**Example 1**:
-
- Input: dominoes = [[1,2],[2,1],[3,4],[5,6]]
- Output: 1
-
-**Constraints:**
-
-- `1 <= dominoes.length <= 40000`
-- `1 <= dominoes[i][j] <= 9`
-
-
-## 题目大意
-
-给你一个由一些多米诺骨牌组成的列表 dominoes。如果其中某一张多米诺骨牌可以通过旋转 0 度或 180 度得到另一张多米诺骨牌,我们就认为这两张牌是等价的。形式上,dominoes[i] = [a, b] 和 dominoes[j] = [c, d] 等价的前提是 a==c 且 b==d,或是 a==d 且 b==c。
-
-在 0 <= i < j < dominoes.length 的前提下,找出满足 dominoes[i] 和 dominoes[j] 等价的骨牌对 (i, j) 的数量。
-
-提示:
-
-- 1 <= dominoes.length <= 40000
-- 1 <= dominoes[i][j] <= 9
-
-
-
-## 解题思路
-
-- 给出一组多米诺骨牌,求出这组牌中相同牌的个数。牌相同的定义是:牌的 2 个数字相同(正序或者逆序相同都算相同)
-- 简单题。由于牌是 2 个数,所以将牌的 2 个数 hash 成一个 2 位数,比较大小即可,正序和逆序都 hash 成 2 位数,然后在桶中比较是否已经存在,如果不存在,跳过,如果存在,计数。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func numEquivDominoPairs(dominoes [][]int) int {
- if dominoes == nil || len(dominoes) == 0 {
- return 0
- }
- result, buckets := 0, [100]int{}
- for _, dominoe := range dominoes {
- key, rotatedKey := dominoe[0]*10+dominoe[1], dominoe[1]*10+dominoe[0]
- if dominoe[0] != dominoe[1] {
- if buckets[rotatedKey] > 0 {
- result += buckets[rotatedKey]
- }
- }
- if buckets[key] > 0 {
- result += buckets[key]
- buckets[key]++
- } else {
- buckets[key]++
- }
- }
- return result
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1137.N-th-Tribonacci-Number.md b/website/content/ChapterFour/1137.N-th-Tribonacci-Number.md
deleted file mode 100755
index f897528da..000000000
--- a/website/content/ChapterFour/1137.N-th-Tribonacci-Number.md
+++ /dev/null
@@ -1,71 +0,0 @@
-# [1137. N-th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number/)
-
-
-## 题目
-
-The Tribonacci sequence Tn is defined as follows:
-
-T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
-
-Given `n`, return the value of Tn.
-
-**Example 1**:
-
- Input: n = 4
- Output: 4
- Explanation:
- T_3 = 0 + 1 + 1 = 2
- T_4 = 1 + 1 + 2 = 4
-
-**Example 2**:
-
- Input: n = 25
- Output: 1389537
-
-**Constraints:**
-
-- `0 <= n <= 37`
-- The answer is guaranteed to fit within a 32-bit integer, ie. `answer <= 2^31 - 1`.
-
-
-## 题目大意
-
-
-泰波那契序列 Tn 定义如下:
-
-T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
-
-给你整数 n,请返回第 n 个泰波那契数 Tn 的值。
-
-提示:
-
-- 0 <= n <= 37
-- 答案保证是一个 32 位整数,即 answer <= 2^31 - 1。
-
-
-
-## 解题思路
-
-- 求泰波那契数列中的第 n 个数。
-- 简单题,按照题意定义计算即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func tribonacci(n int) int {
- if n < 2 {
- return n
- }
- trib, prev, prev2 := 1, 1, 0
- for n > 2 {
- trib, prev, prev2 = trib+prev+prev2, trib, prev
- n--
- }
- return trib
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1145.Binary-Tree-Coloring-Game.md b/website/content/ChapterFour/1145.Binary-Tree-Coloring-Game.md
deleted file mode 100644
index 02fbc6824..000000000
--- a/website/content/ChapterFour/1145.Binary-Tree-Coloring-Game.md
+++ /dev/null
@@ -1,82 +0,0 @@
-# [1145. Binary Tree Coloring Game](https://leetcode.com/problems/binary-tree-coloring-game/)
-
-
-
-## 题目
-
-Two players play a turn based game on a binary tree. We are given the `root` of this binary tree, and the number of nodes `n` in the tree. `n` is odd, and each node has a distinct value from `1` to `n`.
-
-Initially, the first player names a value `x` with `1 <= x <= n`, and the second player names a value `y` with `1 <= y <= n` and `y != x`. The first player colors the node with value `x` red, and the second player colors the node with value `y` blue.
-
-Then, the players take turns starting with the first player. In each turn, that player chooses a node of their color (red if player 1, blue if player 2) and colors an **uncolored** neighbor of the chosen node (either the left child, right child, or parent of the chosen node.)
-
-If (and only if) a player cannot choose such a node in this way, they must pass their turn. If both players pass their turn, the game ends, and the winner is the player that colored more nodes.
-
-You are the second player. If it is possible to choose such a `y` to ensure you win the game, return `true`. If it is not possible, return `false`.
-
-**Example 1**:
-
-
-
-```
-Input: root = [1,2,3,4,5,6,7,8,9,10,11], n = 11, x = 3
-Output: true
-Explanation: The second player can choose the node with value 2.
-```
-
-**Constraints**:
-
-- `root` is the root of a binary tree with `n` nodes and distinct node values from `1` to `n`.
-- `n` is odd.
-- `1 <= x <= n <= 100`
-
-## 题目大意
-
-有两位极客玩家参与了一场「二叉树着色」的游戏。游戏中,给出二叉树的根节点 root,树上总共有 n 个节点,且 n 为奇数,其中每个节点上的值从 1 到 n 各不相同。游戏从「一号」玩家开始(「一号」玩家为红色,「二号」玩家为蓝色),最开始时,
-
-- 「一号」玩家从 [1, n] 中取一个值 x(1 <= x <= n);
-- 「二号」玩家也从 [1, n] 中取一个值 y(1 <= y <= n)且 y != x。
-- 「一号」玩家给值为 x 的节点染上红色,而「二号」玩家给值为 y 的节点染上蓝色。
-
-之后两位玩家轮流进行操作,每一回合,玩家选择一个他之前涂好颜色的节点,将所选节点一个 未着色 的邻节点(即左右子节点、或父节点)进行染色。如果当前玩家无法找到这样的节点来染色时,他的回合就会被跳过。若两个玩家都没有可以染色的节点时,游戏结束。着色节点最多的那位玩家获得胜利 ✌️。现在,假设你是「二号」玩家,根据所给出的输入,假如存在一个 y 值可以确保你赢得这场游戏,则返回 true;若无法获胜,就请返回 false。
-
-
-提示:
-
-- 二叉树的根节点为 root,树上由 n 个节点,节点上的值从 1 到 n 各不相同。
-- n 为奇数。
-- 1 <= x <= n <= 100
-
-## 解题思路
-
-- 2 个人参加二叉树着色游戏。二叉树节点数为奇数。1 号玩家和 2 号玩家分别在二叉树上选项一个点着色。每一回合,玩家选择一个他之前涂好颜色的节点,将所选节点一个 未着色 的邻节点(即左右子节点、或父节点)进行染色。当有人不能选点着色的时候,他的那个回合会被跳过。双方都没法继续着色的时候游戏结束。着色多的人获胜。问二号玩家是否存在必胜策略?
-
-
-
-- 如图所示,当一号玩家选择了一个红色的结点,可能会将二叉树切割为 3 个部分(连通分量),如果选择的是根结点,则可能是 2 个部分或 1 个部分,如果选择叶结点,则是 1 个部分。不过无论哪种情况都无关紧要,我们都可以当成 3 个部分来对待,例如一号玩家选择了一个叶结点,我们也可以把叶结点的左右两个空指针看成大小为 0 的两个部分。
-- 那么二号玩家怎样选择蓝色结点才是最优呢?答案是:选择离红色结点最近,且所属连通分量规模最大的那个点。也就是示例图中的 1 号结点。如果我们选择了 1 号结点为蓝色结点,那么可以染成红色的点就只剩下 6 号点和 7 号点了,而蓝色可以把根结点和其左子树全部占据。
-- 如何确定蓝色是否有必胜策略,就可以转换为,被红色点切割的三个连通分量中,是否存在一个连通分量,大小大于所有结点数目的一半。统计三个连通分量大小的过程,可以用深度优先搜索(DFS)来实现。当遍历到某一结点,其结点值等于选定的红色结点时,我们统计这个结点的左子树 `red_left` 和右子树 `red_right` 的大小,那么我们就已经找到两个连通分量的大小了,最后一个父结点连通分量的大小,可以用结点总数减去这两个连通分量大小,再减去红色所占结点,即 `parent = n - red_left - red_right - 1`。
-
-## 代码
-
-```go
-
-func btreeGameWinningMove(root *TreeNode, n int, x int) bool {
- var left, right int
- dfsBtreeGameWinningMove(root, &left, &right, x)
- up := n - left - right - 1
- n /= 2
- return left > n || right > n || up > n
-}
-
-func dfsBtreeGameWinningMove(node *TreeNode, left, right *int, x int) int {
- if node == nil {
- return 0
- }
- l, r := dfsBtreeGameWinningMove(node.Left, left, right, x), dfsBtreeGameWinningMove(node.Right, left, right, x)
- if node.Val == x {
- *left, *right = l, r
- }
- return l + r + 1
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1154.Day-of-the-Year.md b/website/content/ChapterFour/1154.Day-of-the-Year.md
deleted file mode 100755
index 6b1bc846b..000000000
--- a/website/content/ChapterFour/1154.Day-of-the-Year.md
+++ /dev/null
@@ -1,81 +0,0 @@
-# [1154. Day of the Year](https://leetcode.com/problems/day-of-the-year/)
-
-
-## 题目
-
-Given a string `date` representing a [Gregorian calendar](https://en.wikipedia.org/wiki/Gregorian_calendar) date formatted as `YYYY-MM-DD`, return the day number of the year.
-
-**Example 1**:
-
- Input: date = "2019-01-09"
- Output: 9
- Explanation: Given date is the 9th day of the year in 2019.
-
-**Example 2**:
-
- Input: date = "2019-02-10"
- Output: 41
-
-**Example 3**:
-
- Input: date = "2003-03-01"
- Output: 60
-
-**Example 4**:
-
- Input: date = "2004-03-01"
- Output: 61
-
-**Constraints:**
-
-- `date.length == 10`
-- `date[4] == date[7] == '-'`, and all other `date[i]`'s are digits
-- `date` represents a calendar date between Jan 1st, 1900 and Dec 31, 2019.
-
-## 题目大意
-
-
-实现一个 MajorityChecker 的类,它应该具有下述几个 API:
-
-- MajorityChecker(int[] arr) 会用给定的数组 arr 来构造一个 MajorityChecker 的实例。
-- int query(int left, int right, int threshold) 有这么几个参数:
- - 0 <= left <= right < arr.length 表示数组 arr 的子数组的长度。
- - 2 * threshold > right - left + 1,也就是说阈值 threshold 始终比子序列长度的一半还要大。
-
-每次查询 query(...) 会返回在 arr[left], arr[left+1], ..., arr[right] 中至少出现阈值次数 threshold 的元素,如果不存在这样的元素,就返回 -1。
-
-提示:
-
-- 1 <= arr.length <= 20000
-- 1 <= arr[i] <= 20000
-- 对于每次查询,0 <= left <= right < len(arr)
-- 对于每次查询,2 * threshold > right - left + 1
-- 查询次数最多为 10000
-
-
-
-
-
-## 解题思路
-
-- 给出一个时间字符串,求出这一天是这一年当中的第几天。
-- 简单题。依照题意处理即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "time"
-
-func dayOfYear(date string) int {
- first := date[:4] + "-01-01"
- firstDay, _ := time.Parse("2006-01-02", first)
- dateDay, _ := time.Parse("2006-01-02", date)
- duration := dateDay.Sub(firstDay)
- return int(duration.Hours())/24 + 1
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1157.Online-Majority-Element-In-Subarray.md b/website/content/ChapterFour/1157.Online-Majority-Element-In-Subarray.md
deleted file mode 100755
index ac7d539b9..000000000
--- a/website/content/ChapterFour/1157.Online-Majority-Element-In-Subarray.md
+++ /dev/null
@@ -1,196 +0,0 @@
-# [1157. Online Majority Element In Subarray](https://leetcode.com/problems/online-majority-element-in-subarray/)
-
-
-## 题目
-
-Implementing the class `MajorityChecker`, which has the following API:
-
-- `MajorityChecker(int[] arr)` constructs an instance of MajorityChecker with the given array `arr`;
-- `int query(int left, int right, int threshold)` has arguments such that:
- - `0 <= left <= right < arr.length` representing a subarray of `arr`;
- - `2 * threshold > right - left + 1`, ie. the threshold is always a strict majority of the length of the subarray
-
-Each `query(...)` returns the element in `arr[left], arr[left+1], ..., arr[right]` that occurs at least `threshold` times, or `-1` if no such element exists.
-
-**Example**:
-
- MajorityChecker majorityChecker = new MajorityChecker([1,1,2,2,1,1]);
- majorityChecker.query(0,5,4); // returns 1
- majorityChecker.query(0,3,3); // returns -1
- majorityChecker.query(2,3,2); // returns 2
-
-**Constraints:**
-
-- `1 <= arr.length <= 20000`
-- `1 <= arr[i] <= 20000`
-- For each query, `0 <= left <= right < len(arr)`
-- For each query, `2 * threshold > right - left + 1`
-- The number of queries is at most `10000`
-
-
-## 题目大意
-
-实现一个 MajorityChecker 的类,它应该具有下述几个 API:
-
-- MajorityChecker(int[] arr) 会用给定的数组 arr 来构造一个 MajorityChecker 的实例。
-- int query(int left, int right, int threshold) 有这么几个参数:
-- 0 <= left <= right < arr.length 表示数组 arr 的子数组的长度。
-- 2 * threshold > right - left + 1,也就是说阈值 threshold 始终比子序列长度的一半还要大。
-
-每次查询 query(...) 会返回在 arr[left], arr[left+1], ..., arr[right] 中至少出现阈值次数 threshold 的元素,如果不存在这样的元素,就返回 -1。
-
-提示:
-
-- 1 <= arr.length <= 20000
-- 1 <= arr[i] <= 20000
-- 对于每次查询,0 <= left <= right < len(arr)
-- 对于每次查询,2 * threshold > right - left + 1
-- 查询次数最多为 10000
-
-
-
-
-## 解题思路
-
-
-- 设计一个数据结构,能在任意的一个区间内,查找是否存在众数,众数的定义是:该数字出现的次数大于区间的一半。如果存在众数,一定唯一。如果在给定的区间内找不到众数,则输出 -1 。
-- 这一题有一个很显眼的“暗示”,`2 * threshold > right - left + 1`,这个条件就是摩尔投票算法的前提条件。摩尔投票的思想可以见第 169 题。这一题又要在区间内查询,所以选用线段树这个数据结构来实现。经过分析,可以确定此题的解题思路,摩尔投票 + 线段树。
-- 摩尔投票的思想是用两个变量,candidate 和 count,用来记录待被投票投出去的元素,和候选人累积没被投出去的轮数。如果候选人累积没有被投出去的轮数越多,那么最终成为众数的可能越大。从左往右扫描整个数组,先去第一个元素为 candidate,如果遇到相同的元素就累加轮数,如果遇到不同的元素,就把 candidate 和不同的元素一起投出去。当轮数变成 0 了,再选下一个元素作为 candidate。从左扫到右,就能找到众数了。那怎么和线段树结合起来呢?
-- 线段树是把一个大的区间拆分成很多个小区间,那么考虑这样一个问题。每个小区间内使用摩尔投票,最终把所有小区间合并起来再用一次摩尔投票,得到的结果和对整个区间使用一次摩尔投票的结果是一样的么?答案是一样的。可以这样想,众数总会在一个区间内被选出来,那么其他区间的摩尔投票都是起“中和”作用的,即两两元素一起出局。这个问题想通以后,说明摩尔投票具有可加的性质。既然满足可加,就可以和线段树结合,因为线段树每个线段就是加起来,最终合并成大区间的。
-- 举个例子,arr = [1,1,2,2,1,1],先构造线段树,如下左图。
-
- 
-
- 现在每个线段树的节点不是只存一个 int 数字了,而是存 candidate 和 count。每个节点的 candidate 和 count 分别代表的是该区间内摩尔投票的结果。初始化的时候,先把每个叶子都填满,candidate 是自己,count = 1 。即右图绿色节点。然后在 pushUp 的时候,进行摩尔投票:
-
- mc.merge = func(i, j segmentItem) segmentItem {
- if i.candidate == j.candidate {
- return segmentItem{candidate: i.candidate, count: i.count + j.count}
- }
- if i.count > j.count {
- return segmentItem{candidate: i.candidate, count: i.count - j.count}
- }
- return segmentItem{candidate: j.candidate, count: j.count - i.count}
- }
-
- 直到根节点的 candidate 和 count 都填满。**注意,这里的 count 并不是元素出现的总次数,而是摩尔投票中坚持没有被投出去的轮数**。当线段树构建完成以后,就可以开始查询任意区间内的众数了,candidate 即为众数。接下来还要确定众数是否满足 `threshold` 的条件。
-
-- 用一个字典记录每个元素在数组中出现位置的下标,例如上述这个例子,用 map 记录下标:count = map[1:[0 1 4 5] 2:[2 3]]。由于下标在记录过程中是递增的,所以满足二分查找的条件。利用这个字典就可以查出在任意区间内,指定元素出现的次数。例如这里要查找 1 在 [0,5] 区间内出现的个数,那么利用 2 次二分查找,分别找到 `lowerBound` 和 `upperBound`,在 [lowerBound,upperBound) 区间内,都是元素 1 ,那么区间长度即是该元素重复出现的次数,和 `threshold` 比较,如果 ≥ `threshold` 说明找到了答案,否则没有找到就输出 -1 。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-)
-
-type segmentItem struct {
- candidate int
- count int
-}
-
-// MajorityChecker define
-type MajorityChecker struct {
- segmentTree []segmentItem
- data []int
- merge func(i, j segmentItem) segmentItem
- count map[int][]int
-}
-
-// Constructor1157 define
-func Constructor1157(arr []int) MajorityChecker {
- data, tree, mc, count := make([]int, len(arr)), make([]segmentItem, 4*len(arr)), MajorityChecker{}, make(map[int][]int)
- // 这个 merge 函数就是摩尔投票算法
- mc.merge = func(i, j segmentItem) segmentItem {
- if i.candidate == j.candidate {
- return segmentItem{candidate: i.candidate, count: i.count + j.count}
- }
- if i.count > j.count {
- return segmentItem{candidate: i.candidate, count: i.count - j.count}
- }
- return segmentItem{candidate: j.candidate, count: j.count - i.count}
- }
- for i := 0; i < len(arr); i++ {
- data[i] = arr[i]
- }
- for i := 0; i < len(arr); i++ {
- if _, ok := count[arr[i]]; !ok {
- count[arr[i]] = []int{}
- }
- count[arr[i]] = append(count[arr[i]], i)
- }
- mc.data, mc.segmentTree, mc.count = data, tree, count
- if len(arr) > 0 {
- mc.buildSegmentTree(0, 0, len(arr)-1)
- }
- return mc
-}
-
-func (mc *MajorityChecker) buildSegmentTree(treeIndex, left, right int) {
- if left == right {
- mc.segmentTree[treeIndex] = segmentItem{candidate: mc.data[left], count: 1}
- return
- }
- leftTreeIndex, rightTreeIndex := mc.leftChild(treeIndex), mc.rightChild(treeIndex)
- midTreeIndex := left + (right-left)>>1
- mc.buildSegmentTree(leftTreeIndex, left, midTreeIndex)
- mc.buildSegmentTree(rightTreeIndex, midTreeIndex+1, right)
- mc.segmentTree[treeIndex] = mc.merge(mc.segmentTree[leftTreeIndex], mc.segmentTree[rightTreeIndex])
-}
-
-func (mc *MajorityChecker) leftChild(index int) int {
- return 2*index + 1
-}
-
-func (mc *MajorityChecker) rightChild(index int) int {
- return 2*index + 2
-}
-
-// Query define
-func (mc *MajorityChecker) query(left, right int) segmentItem {
- if len(mc.data) > 0 {
- return mc.queryInTree(0, 0, len(mc.data)-1, left, right)
- }
- return segmentItem{candidate: -1, count: -1}
-}
-
-func (mc *MajorityChecker) queryInTree(treeIndex, left, right, queryLeft, queryRight int) segmentItem {
- midTreeIndex, leftTreeIndex, rightTreeIndex := left+(right-left)>>1, mc.leftChild(treeIndex), mc.rightChild(treeIndex)
- if queryLeft <= left && queryRight >= right { // segment completely inside range
- return mc.segmentTree[treeIndex]
- }
- if queryLeft > midTreeIndex {
- return mc.queryInTree(rightTreeIndex, midTreeIndex+1, right, queryLeft, queryRight)
- } else if queryRight <= midTreeIndex {
- return mc.queryInTree(leftTreeIndex, left, midTreeIndex, queryLeft, queryRight)
- }
- // merge query results
- return mc.merge(mc.queryInTree(leftTreeIndex, left, midTreeIndex, queryLeft, midTreeIndex),
- mc.queryInTree(rightTreeIndex, midTreeIndex+1, right, midTreeIndex+1, queryRight))
-}
-
-// Query define
-func (mc *MajorityChecker) Query(left int, right int, threshold int) int {
- res := mc.query(left, right)
- if _, ok := mc.count[res.candidate]; !ok {
- return -1
- }
- start := sort.Search(len(mc.count[res.candidate]), func(i int) bool { return left <= mc.count[res.candidate][i] })
- end := sort.Search(len(mc.count[res.candidate]), func(i int) bool { return right < mc.count[res.candidate][i] }) - 1
- if (end - start + 1) >= threshold {
- return res.candidate
- }
- return -1
-}
-
-/**
- * Your MajorityChecker object will be instantiated and called as such:
- * obj := Constructor(arr);
- * param_1 := obj.Query(left,right,threshold);
- */
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1160.Find-Words-That-Can-Be-Formed-by-Characters.md b/website/content/ChapterFour/1160.Find-Words-That-Can-Be-Formed-by-Characters.md
deleted file mode 100755
index 5a73172da..000000000
--- a/website/content/ChapterFour/1160.Find-Words-That-Can-Be-Formed-by-Characters.md
+++ /dev/null
@@ -1,81 +0,0 @@
-# [1160. Find Words That Can Be Formed by Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/)
-
-
-## 题目
-
-You are given an array of strings `words` and a string `chars`.
-
-A string is *good* if it can be formed by characters from `chars` (each character can only be used once).
-
-Return the sum of lengths of all good strings in `words`.
-
-**Example 1**:
-
- Input: words = ["cat","bt","hat","tree"], chars = "atach"
- Output: 6
- Explanation:
- The strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.
-
-**Example 2**:
-
- Input: words = ["hello","world","leetcode"], chars = "welldonehoneyr"
- Output: 10
- Explanation:
- The strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.
-
-**Note**:
-
-1. `1 <= words.length <= 1000`
-2. `1 <= words[i].length, chars.length <= 100`
-3. All strings contain lowercase English letters only.
-
-
-## 题目大意
-
-
-给你一份『词汇表』(字符串数组) words 和一张『字母表』(字符串) chars。假如你可以用 chars 中的『字母』(字符)拼写出 words 中的某个『单词』(字符串),那么我们就认为你掌握了这个单词。注意:每次拼写时,chars 中的每个字母都只能用一次。返回词汇表 words 中你掌握的所有单词的 长度之和。
-
-提示:
-
-1. 1 <= words.length <= 1000
-2. 1 <= words[i].length, chars.length <= 100
-3. 所有字符串中都仅包含小写英文字母
-
-
-
-## 解题思路
-
-- 给出一个字符串数组 `words` 和一个字符串 `chars`,要求输出 `chars` 中能构成 `words` 字符串的字符数总数。
-- 简单题。先分别统计 `words` 和 `chars` 里面字符的频次。然后针对 `words` 中每个 `word` 判断能够能由 `chars` 构成,如果能构成,最终结果加上这个 `word` 的长度。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func countCharacters(words []string, chars string) int {
- count, res := make([]int, 26), 0
- for i := 0; i < len(chars); i++ {
- count[chars[i]-'a']++
- }
- for _, w := range words {
- if canBeFormed(w, count) {
- res += len(w)
- }
- }
- return res
-}
-func canBeFormed(w string, c []int) bool {
- count := make([]int, 26)
- for i := 0; i < len(w); i++ {
- count[w[i]-'a']++
- if count[w[i]-'a'] > c[w[i]-'a'] {
- return false
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md b/website/content/ChapterFour/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md
deleted file mode 100755
index be6dfc0d6..000000000
--- a/website/content/ChapterFour/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md
+++ /dev/null
@@ -1,86 +0,0 @@
-# [1170. Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/)
-
-## 题目
-
-Let's define a function `f(s)` over a non-empty string `s`, which calculates the frequency of the smallest character in `s`. For example, if `s = "dcce"` then `f(s) = 2` because the smallest character is `"c"` and its frequency is 2.
-
-Now, given string arrays `queries` and `words`, return an integer array `answer`, where each `answer[i]` is the number of words such that `f(queries[i])` < `f(W)`, where `W` is a word in `words`.
-
-**Example 1**:
-
- Input: queries = ["cbd"], words = ["zaaaz"]
- Output: [1]
- Explanation: On the first query we have f("cbd") = 1, f("zaaaz") = 3 so f("cbd") < f("zaaaz").
-
-**Example 2**:
-
- Input: queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"]
- Output: [1,2]
- Explanation: On the first query only f("bbb") < f("aaaa"). On the second query both f("aaa") and f("aaaa") are both > f("cc").
-
-**Constraints:**
-
-- `1 <= queries.length <= 2000`
-- `1 <= words.length <= 2000`
-- `1 <= queries[i].length, words[i].length <= 10`
-- `queries[i][j]`, `words[i][j]` are English lowercase letters.
-
-
-## 题目大意
-
-
-我们来定义一个函数 f(s),其中传入参数 s 是一个非空字符串;该函数的功能是统计 s 中(按字典序比较)最小字母的出现频次。
-
-例如,若 s = "dcce",那么 f(s) = 2,因为最小的字母是 "c",它出现了 2 次。
-
-现在,给你两个字符串数组待查表 queries 和词汇表 words,请你返回一个整数数组 answer 作为答案,其中每个 answer[i] 是满足 f(queries[i]) < f(W) 的词的数目,W 是词汇表 words 中的词。
-
-提示:
-
-- 1 <= queries.length <= 2000
-- 1 <= words.length <= 2000
-- 1 <= queries[i].length, words[i].length <= 10
-- queries[i][j], words[i][j] 都是小写英文字母
-
-
-
-
-## 解题思路
-
-- 给出 2 个数组,`queries` 和 `words`,针对每一个 `queries[i]` 统计在 `words[j]` 中满足 `f(queries[i]) < f(words[j])` 条件的 `words[j]` 的个数。`f(string)` 的定义是 `string` 中字典序最小的字母的频次。
-- 先依照题意,构造出 `f()` 函数,算出每个 `words[j]` 的 `f()` 值,然后排序。再依次计算 `queries[i]` 的 `f()` 值。针对每个 `f()` 值,在 `words[j]` 的 `f()` 值中二分搜索,查找比它大的值的下标 `k`,`n-k` 即是比 `queries[i]` 的 `f()` 值大的元素个数。依次输出到结果数组中即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "sort"
-
-func numSmallerByFrequency(queries []string, words []string) []int {
- ws, res := make([]int, len(words)), make([]int, len(queries))
- for i, w := range words {
- ws[i] = countFunc(w)
- }
- sort.Ints(ws)
- for i, q := range queries {
- fq := countFunc(q)
- res[i] = len(words) - sort.Search(len(words), func(i int) bool { return fq < ws[i] })
- }
- return res
-}
-
-func countFunc(s string) int {
- count, i := [26]int{}, 0
- for _, b := range s {
- count[b-'a']++
- }
- for count[i] == 0 {
- i++
- }
- return count[i]
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md b/website/content/ChapterFour/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md
deleted file mode 100755
index b71ad63b7..000000000
--- a/website/content/ChapterFour/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md
+++ /dev/null
@@ -1,140 +0,0 @@
-# [1171. Remove Zero Sum Consecutive Nodes from Linked List](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list/)
-
-
-## 题目
-
-Given the `head` of a linked list, we repeatedly delete consecutive sequences of nodes that sum to `0` until there are no such sequences.
-
-After doing so, return the head of the final linked list. You may return any such answer.
-
-(Note that in the examples below, all sequences are serializations of `ListNode` objects.)
-
-**Example 1**:
-
- Input: head = [1,2,-3,3,1]
- Output: [3,1]
- **Note**: The answer [1,2,1] would also be accepted.
-
-**Example 2**:
-
- Input: head = [1,2,3,-3,4]
- Output: [1,2,4]
-
-**Example 3**:
-
- Input: head = [1,2,3,-3,-2]
- Output: [1]
-
-**Constraints:**
-
-- The given linked list will contain between `1` and `1000` nodes.
-- Each node in the linked list has `-1000 <= node.val <= 1000`.
-
-
-## 题目大意
-
-
-给你一个链表的头节点 head,请你编写代码,反复删去链表中由 总和 值为 0 的连续节点组成的序列,直到不存在这样的序列为止。删除完毕后,请你返回最终结果链表的头节点。你可以返回任何满足题目要求的答案。
-
-(注意,下面示例中的所有序列,都是对 ListNode 对象序列化的表示。)
-
-提示:
-
-- 给你的链表中可能有 1 到 1000 个节点。
-- 对于链表中的每个节点,节点的值:-1000 <= node.val <= 1000.
-
-
-
-## 解题思路
-
-- 给出一个链表,要求把链表中和为 0 的结点都移除。
-- 由于链表的特性,不能随机访问。所以从链表的头开始往后扫,把累加和存到字典中。当再次出现相同的累加和的时候,代表这中间的一段和是 0,于是要删除这一段。删除这一段的过程中,也要删除这一段在字典中存过的累加和。有一个特殊情况需要处理,即整个链表的总和是 0,那么最终结果是空链表。针对这个特殊情况,字典中先预存入 0 值。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-/**
- * Definition for singly-linked list.
- * type ListNode struct {
- * Val int
- * Next *ListNode
- * }
- */
-
-// 解法一
-func removeZeroSumSublists(head *ListNode) *ListNode {
- // 计算累加和,和作为 key 存在 map 中,value 存那个节点的指针。如果字典中出现了重复的和,代表出现了和为 0 的段。
- sum, sumMap, cur := 0, make(map[int]*ListNode), head
- // 字典中增加 0 这个特殊值,是为了防止最终链表全部消除完
- sumMap[0] = nil
- for cur != nil {
- sum = sum + cur.Val
- if ptr, ok := sumMap[sum]; ok {
- // 在字典中找到了重复的和,代表 [ptr, tmp] 中间的是和为 0 的段,要删除的就是这一段。
- // 同时删除 map 中中间这一段的和
- if ptr != nil {
- iter := ptr.Next
- tmpSum := sum + iter.Val
- for tmpSum != sum {
- // 删除中间为 0 的那一段,tmpSum 不断的累加删除 map 中的和
- delete(sumMap, tmpSum)
- iter = iter.Next
- tmpSum = tmpSum + iter.Val
- }
- ptr.Next = cur.Next
- } else {
- head = cur.Next
- sumMap = make(map[int]*ListNode)
- sumMap[0] = nil
- }
- } else {
- sumMap[sum] = cur
- }
- cur = cur.Next
- }
- return head
-}
-
-// 解法二 暴力解法
-func removeZeroSumSublists1(head *ListNode) *ListNode {
- if head == nil {
- return nil
- }
- h, prefixSumMap, sum, counter, lastNode := head, map[int]int{}, 0, 0, &ListNode{Val: 1010}
- for h != nil {
- for h != nil {
- sum += h.Val
- counter++
- if v, ok := prefixSumMap[sum]; ok {
- lastNode, counter = h, v
- break
- }
- if sum == 0 {
- head = h.Next
- break
- }
- prefixSumMap[sum] = counter
- h = h.Next
- }
- if lastNode.Val != 1010 {
- h = head
- for counter > 1 {
- counter--
- h = h.Next
- }
- h.Next = lastNode.Next
- }
- if h == nil {
- break
- } else {
- h, prefixSumMap, sum, counter, lastNode = head, map[int]int{}, 0, 0, &ListNode{Val: 1010}
- }
- }
- return head
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1175.Prime-Arrangements.md b/website/content/ChapterFour/1175.Prime-Arrangements.md
deleted file mode 100755
index e5550e67a..000000000
--- a/website/content/ChapterFour/1175.Prime-Arrangements.md
+++ /dev/null
@@ -1,65 +0,0 @@
-# [1175. Prime Arrangements](https://leetcode.com/problems/prime-arrangements/)
-
-
-## 题目
-
-Return the number of permutations of 1 to `n` so that prime numbers are at prime indices (1-indexed.)
-
-*(Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers both smaller than it.)*
-
-Since the answer may be large, return the answer **modulo `10^9 + 7`**.
-
-**Example 1**:
-
- Input: n = 5
- Output: 12
- Explanation: For example [1,2,5,4,3] is a valid permutation, but [5,2,3,4,1] is not because the prime number 5 is at index 1.
-
-**Example 2**:
-
- Input: n = 100
- Output: 682289015
-
-**Constraints:**
-
-- `1 <= n <= 100`
-
-
-## 题目大意
-
-
-请你帮忙给从 1 到 n 的数设计排列方案,使得所有的「质数」都应该被放在「质数索引」(索引从 1 开始)上;你需要返回可能的方案总数。让我们一起来回顾一下「质数」:质数一定是大于 1 的,并且不能用两个小于它的正整数的乘积来表示。由于答案可能会很大,所以请你返回答案 模 mod 10^9 + 7 之后的结果即可。
-
-提示:
-
-- 1 <= n <= 100
-
-## 解题思路
-
-- 给出一个数 n,要求在 1-n 这 n 个数中,素数在素数索引下标位置上的全排列个数。
-- 由于这一题的 `n` 小于 100,所以可以用打表法。先把小于 100 个素数都打表打出来。然后对小于 n 的素数进行全排列,即 n!,然后再对剩下来的非素数进行全排列,即 (n-c)!。两个的乘积即为最终答案。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "sort"
-
-var primes = []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
-
-func numPrimeArrangements(n int) int {
- primeCount := sort.Search(25, func(i int) bool { return primes[i] > n })
- return factorial(primeCount) * factorial(n-primeCount) % 1000000007
-}
-
-func factorial(n int) int {
- if n == 1 || n == 0 {
- return 1
- }
- return n * factorial(n-1) % 1000000007
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1184.Distance-Between-Bus-Stops.md b/website/content/ChapterFour/1184.Distance-Between-Bus-Stops.md
deleted file mode 100755
index 4f5f6c64a..000000000
--- a/website/content/ChapterFour/1184.Distance-Between-Bus-Stops.md
+++ /dev/null
@@ -1,82 +0,0 @@
-# [1184. Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops/)
-
-## 题目
-
-A bus has `n` stops numbered from `0` to `n - 1` that form a circle. We know the distance between all pairs of neighboring stops where `distance[i]` is the distance between the stops number `i` and `(i + 1) % n`.
-
-The bus goes along both directions i.e. clockwise and counterclockwise.
-
-Return the shortest distance between the given `start` and `destination` stops.
-
-**Example 1**:
-
-
-
- Input: distance = [1,2,3,4], start = 0, destination = 1
- Output: 1
- Explanation: Distance between 0 and 1 is 1 or 9, minimum is 1.
-
-**Example 2**:
-
-
-
- Input: distance = [1,2,3,4], start = 0, destination = 2
- Output: 3
- Explanation: Distance between 0 and 2 is 3 or 7, minimum is 3.
-
-**Example 3**:
-
-
-
- Input: distance = [1,2,3,4], start = 0, destination = 3
- Output: 4
- Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.
-
-**Constraints:**
-
-- `1 <= n <= 10^4`
-- `distance.length == n`
-- `0 <= start, destination < n`
-- `0 <= distance[i] <= 10^4`
-
-
-## 题目大意
-
-环形公交路线上有 n 个站,按次序从 0 到 n - 1 进行编号。我们已知每一对相邻公交站之间的距离,distance[i] 表示编号为 i 的车站和编号为 (i + 1) % n 的车站之间的距离。环线上的公交车都可以按顺时针和逆时针的方向行驶。返回乘客从出发点 start 到目的地 destination 之间的最短距离。
-
-提示:
-
-- 1 <= n <= 10^4
-- distance.length == n
-- 0 <= start, destination < n
-- 0 <= distance[i] <= 10^4
-
-
-## 解题思路
-
-
-- 给出一个数组,代表的是公交车站每站直接的距离。距离是按照数组下标的顺序给出的,公交车可以按照顺时针行驶,也可以按照逆时针行驶。问行驶的最短距离是多少。
-- 按照题意,分别算出顺时针和逆时针的行驶距离,比较两者距离,取出小值就是结果。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func distanceBetweenBusStops(distance []int, start int, destination int) int {
- clockwiseDis, counterclockwiseDis, n := 0, 0, len(distance)
- for i := start; i != destination; i = (i + 1) % n {
- clockwiseDis += distance[i]
- }
- for i := destination; i != start; i = (i + 1) % n {
- counterclockwiseDis += distance[i]
- }
- if clockwiseDis < counterclockwiseDis {
- return clockwiseDis
- }
- return counterclockwiseDis
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1185.Day-of-the-Week.md b/website/content/ChapterFour/1185.Day-of-the-Week.md
deleted file mode 100755
index 0eef0bcf8..000000000
--- a/website/content/ChapterFour/1185.Day-of-the-Week.md
+++ /dev/null
@@ -1,61 +0,0 @@
-# [1185. Day of the Week](https://leetcode.com/problems/day-of-the-week/)
-
-
-## 题目
-
-Given a date, return the corresponding day of the week for that date.
-
-The input is given as three integers representing the `day`, `month` and `year` respectively.
-
-Return the answer as one of the following values `{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}`.
-
-**Example 1**:
-
- Input: day = 31, month = 8, year = 2019
- Output: "Saturday"
-
-**Example 2**:
-
- Input: day = 18, month = 7, year = 1999
- Output: "Sunday"
-
-**Example 3**:
-
- Input: day = 15, month = 8, year = 1993
- Output: "Sunday"
-
-**Constraints:**
-
-- The given dates are valid dates between the years `1971` and `2100`.
-
-
-## 题目大意
-
-给你一个日期,请你设计一个算法来判断它是对应一周中的哪一天。输入为三个整数:day、month 和 year,分别表示日、月、年。
-
-您返回的结果必须是这几个值中的一个 {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}。
-
-提示:
-
-- 给出的日期一定是在 1971 到 2100 年之间的有效日期。
-
-## 解题思路
-
-
-- 给出一个日期,要求算出这一天是星期几。
-- 简单题,按照常识计算即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "time"
-
-func dayOfTheWeek(day int, month int, year int) string {
- return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local).Weekday().String()
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1189.Maximum-Number-of-Balloons.md b/website/content/ChapterFour/1189.Maximum-Number-of-Balloons.md
deleted file mode 100755
index 9fdae8753..000000000
--- a/website/content/ChapterFour/1189.Maximum-Number-of-Balloons.md
+++ /dev/null
@@ -1,70 +0,0 @@
-# [1189. Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/)
-
-
-## 题目
-
-Given a string `text`, you want to use the characters of `text` to form as many instances of the word **"balloon"** as possible.
-
-You can use each character in `text` **at most once**. Return the maximum number of instances that can be formed.
-
-**Example 1**:
-
-
-
- Input: text = "nlaebolko"
- Output: 1
-
-**Example 2**:
-
-
-
- Input: text = "loonbalxballpoon"
- Output: 2
-
-**Example 3**:
-
- Input: text = "leetcode"
- Output: 0
-
-**Constraints:**
-
-- `1 <= text.length <= 10^4`
-- `text` consists of lower case English letters only.
-
-
-## 题目大意
-
-给你一个字符串 text,你需要使用 text 中的字母来拼凑尽可能多的单词 "balloon"(气球)。字符串 text 中的每个字母最多只能被使用一次。请你返回最多可以拼凑出多少个单词 "balloon"。
-
-提示:
-
-- 1 <= text.length <= 10^4
-- text 全部由小写英文字母组成
-
-## 解题思路
-
-
-- 给出一个字符串,问这个字符串里面的数组能组成多少个 **balloon** 这个单词。
-- 简单题,先统计 26 个字母每个字母的频次,然后取出 balloon 这 5 个字母出现频次最小的值就是结果。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func maxNumberOfBalloons(text string) int {
- fre := make([]int, 26)
- for _, t := range text {
- fre[t-'a']++
- }
- // 字符 b 的频次是数组下标 1 对应的元素值
- // 字符 a 的频次是数组下标 0 对应的元素值
- // 字符 l 的频次是数组下标 11 对应的元素值,这里有 2 个 l,所以元素值需要除以 2
- // 字符 o 的频次是数组下标 14 对应的元素值,这里有 2 个 o,所以元素值需要除以 2
- // 字符 n 的频次是数组下标 13 对应的元素值
- return min(fre[1], min(fre[0], min(fre[11]/2, min(fre[14]/2, fre[13]))))
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1200.Minimum-Absolute-Difference.md b/website/content/ChapterFour/1200.Minimum-Absolute-Difference.md
deleted file mode 100755
index c52b77995..000000000
--- a/website/content/ChapterFour/1200.Minimum-Absolute-Difference.md
+++ /dev/null
@@ -1,77 +0,0 @@
-# [1200. Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference/)
-
-
-## 题目
-
-Given an array of **distinct** integers `arr`, find all pairs of elements with the minimum absolute difference of any two elements.
-
-Return a list of pairs in ascending order(with respect to pairs), each pair `[a, b]` follows
-
-- `a, b` are from `arr`
-- `a < b`
-- `b - a` equals to the minimum absolute difference of any two elements in `arr`
-
-**Example 1**:
-
- Input: arr = [4,2,1,3]
- Output: [[1,2],[2,3],[3,4]]
- Explanation: The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order.
-
-**Example 2**:
-
- Input: arr = [1,3,6,10,15]
- Output: [[1,3]]
-
-**Example 3**:
-
- Input: arr = [3,8,-10,23,19,-4,-14,27]
- Output: [[-14,-10],[19,23],[23,27]]
-
-**Constraints:**
-
-- `2 <= arr.length <= 10^5`
-- `-10^6 <= arr[i] <= 10^6`
-
-
-## 题目大意
-
-给出一个数组,要求找出所有满足条件的数值对 [a,b]:`a>1
- if calNthCount(mid, int64(a), int64(b), int64(c)) < int64(n) {
- low = mid + 1
- } else {
- high = mid
- }
- }
- return int(low)
-}
-
-func calNthCount(num, a, b, c int64) int64 {
- ab, bc, ac := a*b/gcd(a, b), b*c/gcd(b, c), a*c/gcd(a, c)
- abc := a * bc / gcd(a, bc)
- return num/a + num/b + num/c - num/ab - num/bc - num/ac + num/abc
-}
-
-func gcd(a, b int64) int64 {
- for b != 0 {
- a, b = b, a%b
- }
- return a
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1202.Smallest-String-With-Swaps.md b/website/content/ChapterFour/1202.Smallest-String-With-Swaps.md
deleted file mode 100755
index 18527ba9d..000000000
--- a/website/content/ChapterFour/1202.Smallest-String-With-Swaps.md
+++ /dev/null
@@ -1,102 +0,0 @@
-# [1202. Smallest String With Swaps](https://leetcode.com/problems/smallest-string-with-swaps/)
-
-
-## 题目
-
-You are given a string `s`, and an array of pairs of indices in the string `pairs` where `pairs[i] = [a, b]` indicates 2 indices(0-indexed) of the string.
-
-You can swap the characters at any pair of indices in the given `pairs` **any number of times**.
-
-Return the lexicographically smallest string that `s` can be changed to after using the swaps.
-
-**Example 1**:
-
- Input: s = "dcab", pairs = [[0,3],[1,2]]
- Output: "bacd"
- Explaination:
- Swap s[0] and s[3], s = "bcad"
- Swap s[1] and s[2], s = "bacd"
-
-**Example 2**:
-
- Input: s = "dcab", pairs = [[0,3],[1,2],[0,2]]
- Output: "abcd"
- Explaination:
- Swap s[0] and s[3], s = "bcad"
- Swap s[0] and s[2], s = "acbd"
- Swap s[1] and s[2], s = "abcd"
-
-**Example 3**:
-
- Input: s = "cba", pairs = [[0,1],[1,2]]
- Output: "abc"
- Explaination:
- Swap s[0] and s[1], s = "bca"
- Swap s[1] and s[2], s = "bac"
- Swap s[0] and s[1], s = "abc"
-
-**Constraints:**
-
-- `1 <= s.length <= 10^5`
-- `0 <= pairs.length <= 10^5`
-- `0 <= pairs[i][0], pairs[i][1] < s.length`
-- `s` only contains lower case English letters.
-
-
-## 题目大意
-
-给你一个字符串 s,以及该字符串中的一些「索引对」数组 pairs,其中 pairs[i] = [a, b] 表示字符串中的两个索引(编号从 0 开始)。你可以 任意多次交换 在 pairs 中任意一对索引处的字符。返回在经过若干次交换后,s 可以变成的按字典序最小的字符串。
-
-提示:
-
-- 1 <= s.length <= 10^5
-- 0 <= pairs.length <= 10^5
-- 0 <= pairs[i][0], pairs[i][1] < s.length
-- s 中只含有小写英文字母
-
-
-
-## 解题思路
-
-
-- 给出一个字符串和一个字符串里可交换的下标。要求交换以后字典序最小的字符串。
-- 这一题可以用并查集来解题,先把可交换下标都 `Union()` 起来,每个集合内,按照字典序从小到大排列。最后扫描原有字符串,从左到右依次找到各自对应的集合里面最小的字符进行替换,每次替换完以后,删除集合中该字符(防止下次重复替换)。最终得到的字符就是最小字典序的字符。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import (
- "sort"
-
- "github.com/halfrost/LeetCode-Go/template"
-)
-
-func smallestStringWithSwaps(s string, pairs [][]int) string {
- uf, res, sMap := template.UnionFind{}, []byte(s), map[int][]byte{}
- uf.Init(len(s))
- for _, pair := range pairs {
- uf.Union(pair[0], pair[1])
- }
- for i := 0; i < len(s); i++ {
- r := uf.Find(i)
- sMap[r] = append(sMap[r], s[i])
- }
- for _, v := range sMap {
- sort.Slice(v, func(i, j int) bool {
- return v[i] < v[j]
- })
- }
- for i := 0; i < len(s); i++ {
- r := uf.Find(i)
- bytes := sMap[r]
- res[i] = bytes[0]
- sMap[r] = bytes[1:len(bytes)]
- }
- return string(res)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1207.Unique-Number-of-Occurrences.md b/website/content/ChapterFour/1207.Unique-Number-of-Occurrences.md
deleted file mode 100755
index 43e3c6f83..000000000
--- a/website/content/ChapterFour/1207.Unique-Number-of-Occurrences.md
+++ /dev/null
@@ -1,68 +0,0 @@
-# [1207. Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/)
-
-
-## 题目
-
-Given an array of integers `arr`, write a function that returns `true` if and only if the number of occurrences of each value in the array is unique.
-
-**Example 1**:
-
- Input: arr = [1,2,2,1,1,3]
- Output: true
- Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
-
-**Example 2**:
-
- Input: arr = [1,2]
- Output: false
-
-**Example 3**:
-
- Input: arr = [-3,0,1,-3,1,1,1,-3,10,0]
- Output: true
-
-**Constraints:**
-
-- `1 <= arr.length <= 1000`
-- `-1000 <= arr[i] <= 1000`
-
-
-
-## 题目大意
-
-给你一个整数数组 arr,请你帮忙统计数组中每个数的出现次数。如果每个数的出现次数都是独一无二的,就返回 true;否则返回 false。
-
-提示:
-
-- 1 <= arr.length <= 1000
-- -1000 <= arr[i] <= 1000
-
-## 解题思路
-
-
-- 给出一个数组,先统计每个数字出现的频次,判断在这个数组中是否存在相同的频次。
-- 简单题,先统计数组中每个数字的频次,然后用一个 map 判断频次是否重复。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func uniqueOccurrences(arr []int) bool {
- freq, m := map[int]int{}, map[int]bool{}
- for _, v := range arr {
- freq[v]++
- }
- for _, v := range freq {
- if _, ok := m[v]; !ok {
- m[v] = true
- } else {
- return false
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md b/website/content/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md
deleted file mode 100755
index 5d0474f57..000000000
--- a/website/content/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md
+++ /dev/null
@@ -1,77 +0,0 @@
-# [1208. Get Equal Substrings Within Budget](https://leetcode.com/problems/get-equal-substrings-within-budget/)
-
-
-## 题目
-
-You are given two strings `s` and `t` of the same length. You want to change `s` to `t`. Changing the `i`-th character of `s` to `i`-th character of `t` costs `|s[i] - t[i]|` that is, the absolute difference between the ASCII values of the characters.
-
-You are also given an integer `maxCost`.
-
-Return the maximum length of a substring of `s` that can be changed to be the same as the corresponding substring of `t`with a cost less than or equal to `maxCost`.
-
-If there is no substring from `s` that can be changed to its corresponding substring from `t`, return `0`.
-
-**Example 1**:
-
- Input: s = "abcd", t = "bcdf", maxCost = 3
- Output: 3
- Explanation: "abc" of s can change to "bcd". That costs 3, so the maximum length is 3.
-
-**Example 2**:
-
- Input: s = "abcd", t = "cdef", maxCost = 3
- Output: 1
- Explanation: Each character in s costs 2 to change to charactor in t, so the maximum length is 1.
-
-**Example 3**:
-
- Input: s = "abcd", t = "acde", maxCost = 0
- Output: 1
- Explanation: You can't make any change, so the maximum length is 1.
-
-**Constraints:**
-
-- `1 <= s.length, t.length <= 10^5`
-- `0 <= maxCost <= 10^6`
-- `s` and `t` only contain lower case English letters.
-
-## 题目大意
-
-给你两个长度相同的字符串,s 和 t。将 s 中的第 i 个字符变到 t 中的第 i 个字符需要 |s[i] - t[i]| 的开销(开销可能为 0),也就是两个字符的 ASCII 码值的差的绝对值。
-
-用于变更字符串的最大预算是 maxCost。在转化字符串时,总开销应当小于等于该预算,这也意味着字符串的转化可能是不完全的。如果你可以将 s 的子字符串转化为它在 t 中对应的子字符串,则返回可以转化的最大长度。如果 s 中没有子字符串可以转化成 t 中对应的子字符串,则返回 0。
-
-提示:
-
-- 1 <= s.length, t.length <= 10^5
-- 0 <= maxCost <= 10^6
-- s 和 t 都只含小写英文字母。
-
-## 解题思路
-
-- 给出 2 个字符串 `s` 和 `t` 和一个“预算”,要求把“预算”尽可能的花完,`s` 中最多连续有几个字母能变成 `t` 中的字母。“预算”的定义是:|s[i] - t[i]| 。
-- 这一题是滑动窗口的题目,滑动窗口右边界每移动一格,就减少一定的预算,直到预算不能减少,再移动滑动窗口的左边界,这个时候注意要把预算还原回去。当整个窗口把字符 `s` 或 `t` 都滑动完了的时候,取出滑动过程中窗口的最大值即为结果。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func equalSubstring(s string, t string, maxCost int) int {
- left, right, res := 0, -1, 0
- for left < len(s) {
- if right+1 < len(s) && maxCost-abs(int(s[right+1]-'a')-int(t[right+1]-'a')) >= 0 {
- right++
- maxCost -= abs(int(s[right]-'a') - int(t[right]-'a'))
- } else {
- res = max(res, right-left+1)
- maxCost += abs(int(s[left]-'a') - int(t[left]-'a'))
- left++
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1217.Play-with-Chips.md b/website/content/ChapterFour/1217.Play-with-Chips.md
deleted file mode 100755
index 29eec710c..000000000
--- a/website/content/ChapterFour/1217.Play-with-Chips.md
+++ /dev/null
@@ -1,76 +0,0 @@
-# [1217. Play with Chips](https://leetcode.com/problems/play-with-chips/)
-
-
-## 题目
-
-There are some chips, and the i-th chip is at position `chips[i]`.
-
-You can perform any of the two following types of moves **any number of times** (possibly zero) **on any chip**:
-
-- Move the `i`-th chip by 2 units to the left or to the right with a cost of **0**.
-- Move the `i`-th chip by 1 unit to the left or to the right with a cost of **1**.
-
-There can be two or more chips at the same position initially.
-
-Return the minimum cost needed to move all the chips to the same position (any position).
-
-**Example 1**:
-
- Input: chips = [1,2,3]
- Output: 1
- Explanation: Second chip will be moved to positon 3 with cost 1. First chip will be moved to position 3 with cost 0. Total cost is 1.
-
-**Example 2**:
-
- Input: chips = [2,2,2,3,3]
- Output: 2
- Explanation: Both fourth and fifth chip will be moved to position two with cost 1. Total minimum cost will be 2.
-
-**Constraints:**
-
-- `1 <= chips.length <= 100`
-- `1 <= chips[i] <= 10^9`
-
-
-## 题目大意
-
-
-数轴上放置了一些筹码,每个筹码的位置存在数组 chips 当中。你可以对 任何筹码 执行下面两种操作之一(不限操作次数,0 次也可以):
-
-- 将第 i 个筹码向左或者右移动 2 个单位,代价为 0。
-- 将第 i 个筹码向左或者右移动 1 个单位,代价为 1。
-
-最开始的时候,同一位置上也可能放着两个或者更多的筹码。返回将所有筹码移动到同一位置(任意位置)上所需要的最小代价。
-
-
-提示:
-
-- 1 <= chips.length <= 100
-- 1 <= chips[i] <= 10^9
-
-
-## 解题思路
-
-- 给出一个数组,数组的下标代表的是数轴上的坐标点,数组的元素代表的是砝码大小。砝码移动规则,左右移动 2 格,没有代价,左右移动 1 个,代价是 1 。问最终把砝码都移动到一个格子上,最小代价是多少。
-- 先解读砝码移动规则:偶数位置的到偶数位置的没有代价,奇数到奇数位置的没有代价。利用这个规则,我们可以把所有的砝码**无代价**的摞在一个奇数的位置上和一个偶数的位置上。这样我们只用关心这两个位置了。并且这两个位置可以连续在一起。最后一步即将相邻的这两摞砝码合并到一起。由于左右移动一个代价是 1,所以最小代价的操作是移动最少砝码的那一边。奇数位置上砝码少就移动奇数位置上的,偶数位置上砝码少就移动偶数位置上的。所以这道题解法变的异常简单,遍历一次数组,找到其中有多少个奇数和偶数位置的砝码,取其中比较少的,就是最终答案。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func minCostToMoveChips(chips []int) int {
- odd, even := 0, 0
- for _, c := range chips {
- if c%2 == 0 {
- even++
- } else {
- odd++
- }
- }
- return min(odd, even)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1221.Split-a-String-in-Balanced-Strings.md b/website/content/ChapterFour/1221.Split-a-String-in-Balanced-Strings.md
deleted file mode 100755
index 5a50681b3..000000000
--- a/website/content/ChapterFour/1221.Split-a-String-in-Balanced-Strings.md
+++ /dev/null
@@ -1,73 +0,0 @@
-# [1221. Split a String in Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings/)
-
-
-## 题目
-
-Balanced strings are those who have equal quantity of 'L' and 'R' characters.
-
-Given a balanced string `s` split it in the maximum amount of balanced strings.
-
-Return the maximum amount of splitted balanced strings.
-
-**Example 1**:
-
- Input: s = "RLRRLLRLRL"
- Output: 4
- Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.
-
-**Example 2**:
-
- Input: s = "RLLLLRRRLR"
- Output: 3
- Explanation: s can be split into "RL", "LLLRRR", "LR", each substring contains same number of 'L' and 'R'.
-
-**Example 3**:
-
- Input: s = "LLLLRRRR"
- Output: 1
- Explanation: s can be split into "LLLLRRRR".
-
-**Constraints:**
-
-- `1 <= s.length <= 1000`
-- `s[i] = 'L' or 'R'`
-
-## 题目大意
-
-
-在一个「平衡字符串」中,'L' 和 'R' 字符的数量是相同的。给出一个平衡字符串 s,请你将它分割成尽可能多的平衡字符串。返回可以通过分割得到的平衡字符串的最大数量。
-
-提示:
-
-- 1 <= s.length <= 1000
-- s[i] = 'L' 或 'R'
-
-
-## 解题思路
-
-- 给出一个字符串,要求把这个字符串切成一些子串,这些子串中 R 和 L 的字符数是相等的。问能切成多少个满足条件的子串。
-- 这道题是简单题,按照题意模拟即可。从左往右扫,遇到 `R` 就加一,遇到 `L` 就减一,当计数是 `0` 的时候就是平衡的时候,就切割。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func balancedStringSplit(s string) int {
- count, res := 0, 0
- for _, r := range s {
- if r == 'R' {
- count++
- } else {
- count--
- }
- if count == 0 {
- res++
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md b/website/content/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md
deleted file mode 100755
index a6bdd744c..000000000
--- a/website/content/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md
+++ /dev/null
@@ -1,71 +0,0 @@
-# [1232. Check If It Is a Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line/)
-
-
-## 题目
-
-You are given an array `coordinates`, `coordinates[i] = [x, y]`, where `[x, y]` represents the coordinate of a point. Check if these points make a straight line in the XY plane.
-
-**Example 1**:
-
-
-
- Input: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
- Output: true
-
-**Example 2**:
-
-
-
-
- Input: coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]
- Output: false
-
-**Constraints:**
-
-- `2 <= coordinates.length <= 1000`
-- `coordinates[i].length == 2`
-- `-10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4`
-- `coordinates` contains no duplicate point.
-
-## 题目大意
-
-
-在一个 XY 坐标系中有一些点,我们用数组 coordinates 来分别记录它们的坐标,其中 coordinates[i] = [x, y] 表示横坐标为 x、纵坐标为 y 的点。
-
-请你来判断,这些点是否在该坐标系中属于同一条直线上,是则返回 true,否则请返回 false。
-
-提示:
-
-- 2 <= coordinates.length <= 1000
-- coordinates[i].length == 2
-- -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
-- coordinates 中不含重复的点
-
-
-
-## 解题思路
-
-- 给出一组坐标点,要求判断这些点是否在同一直线上。
-- 按照几何原理,依次计算这些点的斜率是否相等即可。斜率需要做除法,这里采用一个技巧是换成乘法。例如 `a/b = c/d` 换成乘法是 `a*d = c*d` 。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func checkStraightLine(coordinates [][]int) bool {
- dx0 := coordinates[1][0] - coordinates[0][0]
- dy0 := coordinates[1][1] - coordinates[0][1]
- for i := 1; i < len(coordinates)-1; i++ {
- dx := coordinates[i+1][0] - coordinates[i][0]
- dy := coordinates[i+1][1] - coordinates[i][1]
- if dy*dx0 != dy0*dx { // check cross product
- return false
- }
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md b/website/content/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md
deleted file mode 100755
index f5584b74f..000000000
--- a/website/content/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md
+++ /dev/null
@@ -1,93 +0,0 @@
-# [1234. Replace the Substring for Balanced String](https://leetcode.com/problems/replace-the-substring-for-balanced-string/)
-
-
-## 题目
-
-You are given a string containing only 4 kinds of characters `'Q',` `'W', 'E'` and `'R'`.
-
-A string is said to be **balanced** **if each of its characters appears `n/4` times where `n` is the length of the string.
-
-Return the minimum length of the substring that can be replaced with **any** other string of the same length to make the original string `s` **balanced**.
-
-Return 0 if the string is already **balanced**.
-
-**Example 1**:
-
- Input: s = "QWER"
- Output: 0
- Explanation: s is already balanced.
-
-**Example 2**:
-
- Input: s = "QQWE"
- Output: 1
- Explanation: We need to replace a 'Q' to 'R', so that "RQWE" (or "QRWE") is balanced.
-
-**Example 3**:
-
- Input: s = "QQQW"
- Output: 2
- Explanation: We can replace the first "QQ" to "ER".
-
-**Example 4**:
-
- Input: s = "QQQQ"
- Output: 3
- Explanation: We can replace the last 3 'Q' to make s = "QWER".
-
-**Constraints:**
-
-- `1 <= s.length <= 10^5`
-- `s.length` is a multiple of `4`
-- `s` contains only `'Q'`, `'W'`, `'E'` and `'R'`.
-
-## 题目大意
-
-
-有一个只含有 'Q', 'W', 'E', 'R' 四种字符,且长度为 n 的字符串。假如在该字符串中,这四个字符都恰好出现 n/4 次,那么它就是一个「平衡字符串」。给你一个这样的字符串 s,请通过「替换一个子串」的方式,使原字符串 s 变成一个「平衡字符串」。你可以用和「待替换子串」长度相同的 任何 其他字符串来完成替换。请返回待替换子串的最小可能长度。如果原字符串自身就是一个平衡字符串,则返回 0。
-
-提示:
-
-- 1 <= s.length <= 10^5
-- s.length 是 4 的倍数
-- s 中只含有 'Q', 'W', 'E', 'R' 四种字符
-
-
-
-## 解题思路
-
-- 给出一个字符串,要求输出把这个字符串变成“平衡字符串”的最小替换字符串的长度(替换只能替换一串,不能单个字母替换)。“平衡字符串”的定义是:字符串中,`‘Q’`,`‘W’`,`‘E’`,`‘R’`,出现的次数当且仅当只有 `len(s)/4` 次。
-- 这一题是滑动窗口的题目。先统计 4 个字母的频次并计算出 `k = len(s)/4` 。滑动窗口向右滑动一次,对应右窗口的那个字母频次减 1,直到滑到所有字母的频次都 `≤ k` 的地方停止。此时,窗口外的字母的频次都 `≤ k` 了。这是只要变换窗口内字符串即可。但是这个窗口内还可能包含本来频次就小于 `k` 的字母,如果能把它们剔除掉,窗口可以进一步的减少。所以继续移动左边界,试探移动完左边界以后,是否所有字母频次都 `≤ k`。在所有窗口移动过程中取出最小值,即为最终答案。
-- 举个例子:`"WQWRQQQW"`。`w` 有 3 个,`Q` 有 4 个,`R` 有 1 个,`E` 有 0 个。最后平衡状态是每个字母 2 个,那么我们需要拿出 1 个 `W` 和 2 个 `Q` 替换掉。即要找到一个最短的字符串包含 1 个 `W` 和 2 个 `Q`。滑动窗口正好可以解决这个问题。向右滑到 `"WQWRQ"` 停止,这时窗口外的所有字母频次都 `≤ k` 了。这个窗口包含了多余的 1 个 `W`,和 1 个 `R`。`W` 可以踢除掉,那么要替换的字符串是 `"QWRQ"`。`R` 不能踢除了(因为要找包含 1 个 `W` 和 2 个 `Q` 的字符串) 。窗口不断的滑动,直到结束。这个例子中最小的字符串其实位于末尾,`"QQW"`。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func balancedString(s string) int {
- count, k := make([]int, 128), len(s)/4
- for _, v := range s {
- count[int(v)]++
- }
- left, right, res := 0, -1, len(s)
- for left < len(s) {
- if count['Q'] > k || count['W'] > k || count['E'] > k || count['R'] > k {
- if right+1 < len(s) {
- right++
- count[s[right]]--
- } else {
- break
- }
- } else {
- res = min(res, right-left+1)
- count[s[left]]++
- left++
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md b/website/content/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md
deleted file mode 100755
index 915b54335..000000000
--- a/website/content/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md
+++ /dev/null
@@ -1,118 +0,0 @@
-# [1235. Maximum Profit in Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling/)
-
-
-## 题目
-
-We have `n` jobs, where every job is scheduled to be done from `startTime[i]` to `endTime[i]`, obtaining a profit of `profit[i]`.
-
-You're given the `startTime` , `endTime` and `profit` arrays, you need to output the maximum profit you can take such that there are no 2 jobs in the subset with overlapping time range.
-
-If you choose a job that ends at time `X` you will be able to start another job that starts at time `X`.
-
-**Example 1**:
-
-
-
- Input: startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]
- Output: 120
- Explanation: The subset chosen is the first and fourth job.
- Time range [1-3]+[3-6] , we get profit of 120 = 50 + 70.
-
-**Example 2**:
-
-
-
- Input: startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]
- Output: 150
- Explanation: The subset chosen is the first, fourth and fifth job.
- Profit obtained 150 = 20 + 70 + 60.
-
-**Example 3**:
-
-
-
- Input: startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]
- Output: 6
-
-**Constraints:**
-
-- `1 <= startTime.length == endTime.length == profit.length <= 5 * 10^4`
-- `1 <= startTime[i] < endTime[i] <= 10^9`
-- `1 <= profit[i] <= 10^4`
-
-## 题目大意
-
-
-你打算利用空闲时间来做兼职工作赚些零花钱。这里有 n 份兼职工作,每份工作预计从 startTime[i] 开始到 endTime[i] 结束,报酬为 profit[i]。给你一份兼职工作表,包含开始时间 startTime,结束时间 endTime 和预计报酬 profit 三个数组,请你计算并返回可以获得的最大报酬。注意,时间上出现重叠的 2 份工作不能同时进行。如果你选择的工作在时间 X 结束,那么你可以立刻进行在时间 X 开始的下一份工作。
-
-
-提示:
-
-- 1 <= startTime.length == endTime.length == profit.length <= 5 * 10^4
-- 1 <= startTime[i] < endTime[i] <= 10^9
-- 1 <= profit[i] <= 10^4
-
-
-
-## 解题思路
-
-- 给出一组任务,任务有开始时间,结束时间,和任务收益。一个任务开始还没有结束,中间就不能再安排其他任务。问如何安排任务,能使得最后收益最大?
-- 一般任务的题目,区间的题目,都会考虑是否能排序。这一题可以先按照任务的结束时间从小到大排序,如果结束时间相同,则按照收益从小到大排序。`dp[i]` 代表前 `i` 份工作能获得的最大收益。初始值,`dp[0] = job[1].profit` 。对于任意一个任务 `i` ,看能否找到满足 `jobs[j].enTime <= jobs[j].startTime && j < i` 条件的 `j`,即查找 `upper_bound` 。由于 `jobs` 被我们排序了,所以这里可以使用二分搜索来查找。如果能找到满足条件的任务 j,那么状态转移方程是:`dp[i] = max(dp[i-1], jobs[i].profit)`。如果能找到满足条件的任务 j,那么状态转移方程是:`dp[i] = max(dp[i-1], dp[low]+jobs[i].profit)`。最终求得的解在 `dp[len(startTime)-1]` 中。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-import "sort"
-
-type job struct {
- startTime int
- endTime int
- profit int
-}
-
-func jobScheduling(startTime []int, endTime []int, profit []int) int {
- jobs, dp := []job{}, make([]int, len(startTime))
- for i := 0; i < len(startTime); i++ {
- jobs = append(jobs, job{startTime: startTime[i], endTime: endTime[i], profit: profit[i]})
- }
- sort.Sort(sortJobs(jobs))
- dp[0] = jobs[0].profit
- for i := 1; i < len(jobs); i++ {
- low, high := 0, i-1
- for low < high {
- mid := low + (high-low)>>1
- if jobs[mid+1].endTime <= jobs[i].startTime {
- low = mid + 1
- } else {
- high = mid
- }
- }
- if jobs[low].endTime <= jobs[i].startTime {
- dp[i] = max(dp[i-1], dp[low]+jobs[i].profit)
- } else {
- dp[i] = max(dp[i-1], jobs[i].profit)
- }
- }
- return dp[len(startTime)-1]
-}
-
-type sortJobs []job
-
-func (s sortJobs) Len() int {
- return len(s)
-}
-func (s sortJobs) Less(i, j int) bool {
- if s[i].endTime == s[j].endTime {
- return s[i].profit < s[j].profit
- }
- return s[i].endTime < s[j].endTime
-}
-func (s sortJobs) Swap(i, j int) {
- s[i], s[j] = s[j], s[i]
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1252.Cells-with-Odd-Values-in-a-Matrix.md b/website/content/ChapterFour/1252.Cells-with-Odd-Values-in-a-Matrix.md
deleted file mode 100755
index 14db287ae..000000000
--- a/website/content/ChapterFour/1252.Cells-with-Odd-Values-in-a-Matrix.md
+++ /dev/null
@@ -1,103 +0,0 @@
-# [1252. Cells with Odd Values in a Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/)
-
-
-## 题目
-
-Given `n` and `m` which are the dimensions of a matrix initialized by zeros and given an array `indices` where `indices[i] = [ri, ci]`. For each pair of `[ri, ci]` you have to increment all cells in row `ri` and column `ci` by 1.
-
-Return *the number of cells with odd values* in the matrix after applying the increment to all `indices`.
-
-**Example 1**:
-
-
-
- Input: n = 2, m = 3, indices = [[0,1],[1,1]]
- Output: 6
- Explanation: Initial matrix = [[0,0,0],[0,0,0]].
- After applying first increment it becomes [[1,2,1],[0,1,0]].
- The final matrix will be [[1,3,1],[1,3,1]] which contains 6 odd numbers.
-
-**Example 2**:
-
-
-
- Input: n = 2, m = 2, indices = [[1,1],[0,0]]
- Output: 0
- Explanation: Final matrix = [[2,2],[2,2]]. There is no odd number in the final matrix.
-
-**Constraints:**
-
-- `1 <= n <= 50`
-- `1 <= m <= 50`
-- `1 <= indices.length <= 100`
-- `0 <= indices[i][0] < n`
-- `0 <= indices[i][1] < m`
-
-## 题目大意
-
-
-给你一个 n 行 m 列的矩阵,最开始的时候,每个单元格中的值都是 0。另有一个索引数组 indices,indices[i] = [ri, ci] 中的 ri 和 ci 分别表示指定的行和列(从 0 开始编号)。你需要将每对 [ri, ci] 指定的行和列上的所有单元格的值加 1。请你在执行完所有 indices 指定的增量操作后,返回矩阵中 「奇数值单元格」 的数目。
-
-提示:
-
-- 1 <= n <= 50
-- 1 <= m <= 50
-- 1 <= indices.length <= 100
-- 0 <= indices[i][0] < n
-- 0 <= indices[i][1] < m
-
-
-## 解题思路
-
-- 给出一个 n * m 的矩阵,和一个数组,数组里面包含一些行列坐标,并在指定坐标上 + 1,问最后 n * m 的矩阵中奇数的总数。
-- 暴力方法按照题意模拟即可。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-// 解法一 暴力法
-func oddCells(n int, m int, indices [][]int) int {
- matrix, res := make([][]int, n), 0
- for i := range matrix {
- matrix[i] = make([]int, m)
- }
- for _, indice := range indices {
- for i := 0; i < m; i++ {
- matrix[indice[0]][i]++
- }
- for j := 0; j < n; j++ {
- matrix[j][indice[1]]++
- }
- }
- for _, m := range matrix {
- for _, v := range m {
- if v&1 == 1 {
- res++
- }
- }
- }
- return res
-}
-
-// 解法二 暴力法
-func oddCells1(n int, m int, indices [][]int) int {
- rows, cols, count := make([]int, n), make([]int, m), 0
- for _, pair := range indices {
- rows[pair[0]]++
- cols[pair[1]]++
- }
- for i := 0; i < n; i++ {
- for j := 0; j < m; j++ {
- if (rows[i]+cols[j])%2 == 1 {
- count++
- }
- }
- }
- return count
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1254.Number-of-Closed-Islands.md b/website/content/ChapterFour/1254.Number-of-Closed-Islands.md
deleted file mode 100755
index 3ff8da1a2..000000000
--- a/website/content/ChapterFour/1254.Number-of-Closed-Islands.md
+++ /dev/null
@@ -1,110 +0,0 @@
-# [1254. Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands/)
-
-
-## 题目
-
-Given a 2D `grid` consists of `0s` (land) and `1s` (water). An *island* is a maximal 4-directionally connected group of `0s` and a *closed island* is an island **totally** (all left, top, right, bottom) surrounded by `1s.`
-
-Return the number of *closed islands*.
-
-**Example 1**:
-
-
-
- Input: grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]
- Output: 2
- Explanation:
- Islands in gray are closed because they are completely surrounded by water (group of 1s).
-
-**Example 2**:
-
-
-
- Input: grid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]
- Output: 1
-
-**Example 3**:
-
- Input: grid = [[1,1,1,1,1,1,1],
- [1,0,0,0,0,0,1],
- [1,0,1,1,1,0,1],
- [1,0,1,0,1,0,1],
- [1,0,1,1,1,0,1],
- [1,0,0,0,0,0,1],
- [1,1,1,1,1,1,1]]
- Output: 2
-
-**Constraints**:
-
-- `1 <= grid.length, grid[0].length <= 100`
-- `0 <= grid[i][j] <=1`
-
-## 题目大意
-
-有一个二维矩阵 grid ,每个位置要么是陆地(记号为 0 )要么是水域(记号为 1 )。我们从一块陆地出发,每次可以往上下左右 4 个方向相邻区域走,能走到的所有陆地区域,我们将其称为一座「岛屿」。如果一座岛屿 完全 由水域包围,即陆地边缘上下左右所有相邻区域都是水域,那么我们将其称为 「封闭岛屿」。请返回封闭岛屿的数目。
-
-提示:
-
-- 1 <= grid.length, grid[0].length <= 100
-- 0 <= grid[i][j] <=1
-
-
-## 解题思路
-
-- 给出一个地图,1 代表海水,0 代表陆地。要求找出四周都是海水的陆地的总个数。
-- 这一题和第 200 题解题思路完全一致。只不过这一题要求必须四周都是海水,第 200 题的陆地可以是靠着地图边缘的。在此题中,靠着地图边缘的陆地不能最终计数到结果中。
-
-## 代码
-
-```go
-
-package leetcode
-
-func closedIsland(grid [][]int) int {
- m := len(grid)
- if m == 0 {
- return 0
- }
- n := len(grid[0])
- if n == 0 {
- return 0
- }
- res, visited := 0, make([][]bool, m)
- for i := 0; i < m; i++ {
- visited[i] = make([]bool, n)
- }
- for i := 0; i < m; i++ {
- for j := 0; j < n; j++ {
- isEdge := false
- if grid[i][j] == 0 && !visited[i][j] {
- checkIslands(grid, &visited, i, j, &isEdge)
- if !isEdge {
- res++
- }
-
- }
- }
- }
- return res
-}
-
-func checkIslands(grid [][]int, visited *[][]bool, x, y int, isEdge *bool) {
- if (x == 0 || x == len(grid)-1 || y == 0 || y == len(grid[0])-1) && grid[x][y] == 0 {
- *isEdge = true
- }
- (*visited)[x][y] = true
- for i := 0; i < 4; i++ {
- nx := x + dir[i][0]
- ny := y + dir[i][1]
- if isIntInBoard(grid, nx, ny) && !(*visited)[nx][ny] && grid[nx][ny] == 0 {
- checkIslands(grid, visited, nx, ny, isEdge)
- }
- }
- *isEdge = *isEdge || false
-}
-
-func isIntInBoard(board [][]int, x, y int) bool {
- return x >= 0 && x < len(board) && y >= 0 && y < len(board[0])
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1260.Shift-2D-Grid.md b/website/content/ChapterFour/1260.Shift-2D-Grid.md
deleted file mode 100644
index a63d3e771..000000000
--- a/website/content/ChapterFour/1260.Shift-2D-Grid.md
+++ /dev/null
@@ -1,90 +0,0 @@
-# [1260. Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid/)
-
-
-## 题目
-
-Given a 2D `grid` of size `m x n` and an integer `k`. You need to shift the `grid` `k` times.
-
-In one shift operation:
-
-- Element at `grid[i][j]` moves to `grid[i][j + 1]`.
-- Element at `grid[i][n - 1]` moves to `grid[i + 1][0]`.
-- Element at `grid[m - 1][n - 1]` moves to `grid[0][0]`.
-
-Return the *2D grid* after applying shift operation `k` times.
-
-**Example 1**:
-
-
-
-```
-Input: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1
-Output: [[9,1,2],[3,4,5],[6,7,8]]
-```
-
-**Example 2**:
-
-
-
-```
-Input: grid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4
-Output: [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]
-```
-
-**Example 3**:
-
-```
-Input: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 9
-Output: [[1,2,3],[4,5,6],[7,8,9]]
-```
-
-**Constraints**:
-
-- `m == grid.length`
-- `n == grid[i].length`
-- `1 <= m <= 50`
-- `1 <= n <= 50`
-- `-1000 <= grid[i][j] <= 1000`
-- `0 <= k <= 100`
-
-## 题目大意
-
-给你一个 m 行 n 列的二维网格 grid 和一个整数 k。你需要将 grid 迁移 k 次。每次「迁移」操作将会引发下述活动:
-
-- 位于 grid[i][j] 的元素将会移动到 grid[i][j + 1]。
-- 位于 grid[i][n - 1] 的元素将会移动到 grid[i + 1][0]。
-- 位于 grid[m - 1][n - 1] 的元素将会移动到 grid[0][0]。
-
-请你返回 k 次迁移操作后最终得到的 二维网格。
-
-
-## 解题思路
-
-- 给一个矩阵和一个移动步数 k,要求把矩阵每个元素往后移动 k 步,最后的元素移动头部,循环移动,最后输出移动结束的矩阵。
-- 简单题,按照题意循环移动即可,注意判断边界情况。
-
-## 代码
-
-```go
-
-package leetcode
-
-func shiftGrid(grid [][]int, k int) [][]int {
- x, y := len(grid[0]), len(grid)
- newGrid := make([][]int, y)
- for i := 0; i < y; i++ {
- newGrid[i] = make([]int, x)
- }
- for i := 0; i < y; i++ {
- for j := 0; j < x; j++ {
- ny := (k / x) + i
- if (j + (k % x)) >= x {
- ny++
- }
- newGrid[ny%y][(j+(k%x))%x] = grid[i][j]
- }
- }
- return newGrid
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1266.Minimum-Time-Visiting-All-Points.md b/website/content/ChapterFour/1266.Minimum-Time-Visiting-All-Points.md
deleted file mode 100755
index 5fe48f070..000000000
--- a/website/content/ChapterFour/1266.Minimum-Time-Visiting-All-Points.md
+++ /dev/null
@@ -1,75 +0,0 @@
-# [1266. Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points/)
-
-
-## 题目
-
-On a plane there are `n` points with integer coordinates `points[i] = [xi, yi]`. Your task is to find the minimum time in seconds to visit all points.
-
-You can move according to the next rules:
-
-- In one second always you can either move vertically, horizontally by one unit or diagonally (it means to move one unit vertically and one unit horizontally in one second).
-- You have to visit the points in the same order as they appear in the array.
-
-**Example 1**:
-
-
-
- Input: points = [[1,1],[3,4],[-1,0]]
- Output: 7
- Explanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]
- Time from [1,1] to [3,4] = 3 seconds
- Time from [3,4] to [-1,0] = 4 seconds
- Total time = 7 seconds
-
-**Example 2**:
-
- Input: points = [[3,2],[-2,2]]
- Output: 5
-
-**Constraints:**
-
-- `points.length == n`
-- `1 <= n <= 100`
-- `points[i].length == 2`
-- `-1000 <= points[i][0], points[i][1] <= 1000`
-
-## 题目大意
-
-
-平面上有 n 个点,点的位置用整数坐标表示 points[i] = [xi, yi]。请你计算访问所有这些点需要的最小时间(以秒为单位)。你可以按照下面的规则在平面上移动:
-
-- 每一秒沿水平或者竖直方向移动一个单位长度,或者跨过对角线(可以看作在一秒内向水平和竖直方向各移动一个单位长度)。
-- 必须按照数组中出现的顺序来访问这些点。
-
-提示:
-
-- points.length == n
-- 1 <= n <= 100
-- points[i].length == 2
-- -1000 <= points[i][0], points[i][1] <= 1000
-
-
-
-
-
-## 解题思路
-
-- 在直角坐标系上给出一个数组,数组里面的点是飞机飞行经过的点。飞机飞行只能沿着水平方向、垂直方向、45°方向飞行。问飞机经过所有点的最短时间。
-- 简单的数学问题。依次遍历数组,分别计算 x 轴和 y 轴上的差值,取最大值即是这两点之间飞行的最短时间。最后累加每次计算的最大值就是最短时间。
-
-
-## 代码
-
-```go
-
-package leetcode
-
-func minTimeToVisitAllPoints(points [][]int) int {
- res := 0
- for i := 1; i < len(points); i++ {
- res += max(abs(points[i][0]-points[i-1][0]), abs(points[i][1]-points[i-1][1]))
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1275.Find-Winner-on-a-Tic-Tac-Toe-Game.md b/website/content/ChapterFour/1275.Find-Winner-on-a-Tic-Tac-Toe-Game.md
deleted file mode 100644
index d019be1cb..000000000
--- a/website/content/ChapterFour/1275.Find-Winner-on-a-Tic-Tac-Toe-Game.md
+++ /dev/null
@@ -1,154 +0,0 @@
-# [1275. Find Winner on a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game/)
-
-
-## 题目
-
-Tic-tac-toe is played by two players *A* and *B* on a 3 x 3 grid.
-
-Here are the rules of Tic-Tac-Toe:
-
-- Players take turns placing characters into empty squares (" ").
-- The first player *A* always places "X" characters, while the second player *B* always places "O" characters.
-- "X" and "O" characters are always placed into empty squares, never on filled ones.
-- The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal.
-- The game also ends if all squares are non-empty.
-- No more moves can be played if the game is over.
-
-Given an array `moves` where each element is another array of size 2 corresponding to the row and column of the grid where they mark their respective character in the order in which *A* and *B* play.
-
-Return the winner of the game if it exists (*A* or *B*), in case the game ends in a draw return "Draw", if there are still movements to play return "Pending".
-
-You can assume that `moves` is **valid** (It follows the rules of Tic-Tac-Toe), the grid is initially empty and *A* will play **first**.
-
-**Example 1**:
-
-```
-Input: moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]
-Output: "A"
-Explanation: "A" wins, he always plays first.
-"X " "X " "X " "X " "X "
-" " -> " " -> " X " -> " X " -> " X "
-" " "O " "O " "OO " "OOX"
-
-```
-
-**Example 2**:
-
-```
-Input: moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]
-Output: "B"
-Explanation: "B" wins.
-"X " "X " "XX " "XXO" "XXO" "XXO"
-" " -> " O " -> " O " -> " O " -> "XO " -> "XO "
-" " " " " " " " " " "O "
-
-```
-
-**Example 3**:
-
-```
-Input: moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]
-Output: "Draw"
-Explanation: The game ends in a draw since there are no moves to make.
-"XXO"
-"OOX"
-"XOX"
-
-```
-
-**Example 4**:
-
-```
-Input: moves = [[0,0],[1,1]]
-Output: "Pending"
-Explanation: The game has not finished yet.
-"X "
-" O "
-" "
-
-```
-
-**Constraints:**
-
-- `1 <= moves.length <= 9`
-- `moves[i].length == 2`
-- `0 <= moves[i][j] <= 2`
-- There are no repeated elements on `moves`.
-- `moves` follow the rules of tic tac toe.
-
-
-## 题目大意
-
-A 和 B 在一个 3 x 3 的网格上玩井字棋。井字棋游戏的规则如下:
-
-- 玩家轮流将棋子放在空方格 (" ") 上。
-- 第一个玩家 A 总是用 "X" 作为棋子,而第二个玩家 B 总是用 "O" 作为棋子。
-- "X" 和 "O" 只能放在空方格中,而不能放在已经被占用的方格上。
-- 只要有 3 个相同的(非空)棋子排成一条直线(行、列、对角线)时,游戏结束。
-- 如果所有方块都放满棋子(不为空),游戏也会结束。
-- 游戏结束后,棋子无法再进行任何移动。
-
-给你一个数组 moves,其中每个元素是大小为 2 的另一个数组(元素分别对应网格的行和列),它按照 A 和 B 的行动顺序(先 A 后 B)记录了两人各自的棋子位置。如果游戏存在获胜者(A 或 B),就返回该游戏的获胜者;如果游戏以平局结束,则返回 "Draw";如果仍会有行动(游戏未结束),则返回 "Pending"。你可以假设 moves 都 有效(遵循井字棋规则),网格最初是空的,A 将先行动。
-
-提示:
-
-- 1 <= moves.length <= 9
-- moves[i].length == 2
-- 0 <= moves[i][j] <= 2
-- moves 里没有重复的元素。
-- moves 遵循井字棋的规则。
-
-
-## 解题思路
-
-- 两人玩 3*3 井字棋,A 先走,B 再走。谁能获胜就输出谁,如果平局输出 “Draw”,如果游戏还未结束,输出 “Pending”。游戏规则:谁能先占满行、列或者对角线任意一条线,谁就赢。
-- 简单题。题目给定 move 数组最多 3 步,而要赢得比赛,必须走满 3 步,所以可以先模拟,按照给的步数数组把 A 和 B 的步数都放在棋盘上。然后依次判断行、列,对角线的三种情况。如果都判完了,剩下的情况就是平局和死局的情况。
-
-## 代码
-
-```go
-
-package leetcode
-
-func tictactoe(moves [][]int) string {
- board := [3][3]byte{}
- for i := 0; i < len(moves); i++ {
- if i%2 == 0 {
- board[moves[i][0]][moves[i][1]] = 'X'
- } else {
- board[moves[i][0]][moves[i][1]] = 'O'
- }
- }
- for i := 0; i < 3; i++ {
- if board[i][0] == 'X' && board[i][1] == 'X' && board[i][2] == 'X' {
- return "A"
- }
- if board[i][0] == 'O' && board[i][1] == 'O' && board[i][2] == 'O' {
- return "B"
- }
- if board[0][i] == 'X' && board[1][i] == 'X' && board[2][i] == 'X' {
- return "A"
- }
- if board[0][i] == 'O' && board[1][i] == 'O' && board[2][i] == 'O' {
- return "B"
- }
- }
- if board[0][0] == 'X' && board[1][1] == 'X' && board[2][2] == 'X' {
- return "A"
- }
- if board[0][0] == 'O' && board[1][1] == 'O' && board[2][2] == 'O' {
- return "B"
- }
- if board[0][2] == 'X' && board[1][1] == 'X' && board[2][0] == 'X' {
- return "A"
- }
- if board[0][2] == 'O' && board[1][1] == 'O' && board[2][0] == 'O' {
- return "B"
- }
- if len(moves) < 9 {
- return "Pending"
- }
- return "Draw"
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer.md b/website/content/ChapterFour/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer.md
deleted file mode 100644
index 96cc347d9..000000000
--- a/website/content/ChapterFour/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer.md
+++ /dev/null
@@ -1,59 +0,0 @@
-# [1281. Subtract the Product and Sum of Digits of an Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/)
-
-
-
-## 题目
-
-Given an integer number `n`, return the difference between the product of its digits and the sum of its digits.
-
-**Example 1**:
-
-```
-Input: n = 234
-Output: 15
-Explanation:
-Product of digits = 2 * 3 * 4 = 24
-Sum of digits = 2 + 3 + 4 = 9
-Result = 24 - 9 = 15
-```
-
-**Example 2**:
-
-```
-Input: n = 4421
-Output: 21
-Explanation:
-Product of digits = 4 * 4 * 2 * 1 = 32
-Sum of digits = 4 + 4 + 2 + 1 = 11
-Result = 32 - 11 = 21
-```
-
-**Constraints**:
-
-- `1 <= n <= 10^5`
-
-## 题目大意
-
-给你一个整数 n,请你帮忙计算并返回该整数「各位数字之积」与「各位数字之和」的差。
-
-提示:
-
-- 1 <= n <= 10^5
-
-## 解题思路
-
-- 给出一个数,计算这个数每位数字乘积减去每位数字累加的差值。
-- 简单题,按照题意输入输出即可。
-
-## 代码
-
-```go
-func subtractProductAndSum(n int) int {
- sum, product := 0, 1
- for ; n > 0; n /= 10 {
- sum += n % 10
- product *= n % 10
- }
- return product - sum
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md b/website/content/ChapterFour/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md
deleted file mode 100644
index f0359723b..000000000
--- a/website/content/ChapterFour/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md
+++ /dev/null
@@ -1,87 +0,0 @@
-# [1283. Find the Smallest Divisor Given a Threshold](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold/)
-
-
-
-## 题目
-
-Given an array of integers `nums` and an integer `threshold`, we will choose a positive integer divisor and divide all the array by it and sum the result of the division. Find the **smallest** divisor such that the result mentioned above is less than or equal to `threshold`.
-
-Each result of division is rounded to the nearest integer greater than or equal to that element. (For example: 7/3 = 3 and 10/2 = 5).
-
-It is guaranteed that there will be an answer.
-
-**Example 1**:
-
-```
-Input: nums = [1,2,5,9], threshold = 6
-Output: 5
-Explanation: We can get a sum to 17 (1+2+5+9) if the divisor is 1.
-If the divisor is 4 we can get a sum to 7 (1+1+2+3) and if the divisor is 5 the sum will be 5 (1+1+1+2).
-```
-
-**Example 2**:
-
-```
-Input: nums = [2,3,5,7,11], threshold = 11
-Output: 3
-```
-
-**Example 3**:
-
-```
-Input: nums = [19], threshold = 5
-Output: 4
-```
-
-**Constraints**:
-
-- `1 <= nums.length <= 5 * 10^4`
-- `1 <= nums[i] <= 10^6`
-- `nums.length <= threshold <= 10^6`
-
-## 题目大意
-
-给你一个整数数组 nums 和一个正整数 threshold ,你需要选择一个正整数作为除数,然后将数组里每个数都除以它,并对除法结果求和。请你找出能够使上述结果小于等于阈值 threshold 的除数中 最小 的那个。每个数除以除数后都向上取整,比方说 7/3 = 3 , 10/2 = 5 。题目保证一定有解。
-
-提示:
-
-- 1 <= nums.length <= 5 * 10^4
-- 1 <= nums[i] <= 10^6
-- nums.length <= threshold <= 10^6
-
-## 解题思路
-
-- 给出一个数组和一个阈值,要求找到一个除数,使得数组里面每个数和这个除数的商之和不超过这个阈值。求除数的最小值。
-- 这一题是典型的二分搜索的题目。根据题意,在 [1, 1000000] 区间内搜索除数,针对每次 `mid`,计算一次商的累加和。如果和比 `threshold` 小,说明除数太大,所以缩小右区间;如果和比 `threshold` 大,说明除数太小,所以缩小左区间。最终找到的 `low` 值就是最求的最小除数。
-
-## 代码
-
-```go
-func smallestDivisor(nums []int, threshold int) int {
- low, high := 1, 1000000
- for low < high {
- mid := low + (high-low)>>1
- if calDivisor(nums, mid, threshold) {
- high = mid
- } else {
- low = mid + 1
- }
- }
- return low
-}
-
-func calDivisor(nums []int, mid, threshold int) bool {
- sum := 0
- for i := range nums {
- if nums[i]%mid != 0 {
- sum += nums[i]/mid + 1
- } else {
- sum += nums[i] / mid
- }
- }
- if sum <= threshold {
- return true
- }
- return false
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1287.Element-Appearing-More-Than-25-In-Sorted-Array.md b/website/content/ChapterFour/1287.Element-Appearing-More-Than-25-In-Sorted-Array.md
deleted file mode 100644
index f9714a4dd..000000000
--- a/website/content/ChapterFour/1287.Element-Appearing-More-Than-25-In-Sorted-Array.md
+++ /dev/null
@@ -1,49 +0,0 @@
-# [1287. Element Appearing More Than 25% In Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/)
-
-
-
-## 题目
-
-Given an integer array **sorted** in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time.
-
-Return that integer.
-
-**Example 1**:
-
-```
-Input: arr = [1,2,2,6,6,6,6,7,10]
-Output: 6
-```
-
-**Constraints**:
-
-- `1 <= arr.length <= 10^4`
-- `0 <= arr[i] <= 10^5`
-
-## 题目大意
-
-给你一个非递减的 有序 整数数组,已知这个数组中恰好有一个整数,它的出现次数超过数组元素总数的 25%。请你找到并返回这个整数。
-
-提示:
-
-- 1 <= arr.length <= 10^4
-- 0 <= arr[i] <= 10^5
-
-## 解题思路
-
-- 给出一个非递减的有序数组,要求输出出现次数超过数组元素总数 25% 的元素。
-- 简单题,由于已经非递减有序了,所以只需要判断 `arr[i] == arr[i+n/4]` 是否相等即可。
-
-## 代码
-
-```go
-func findSpecialInteger(arr []int) int {
- n := len(arr)
- for i := 0; i < n-n/4; i++ {
- if arr[i] == arr[i+n/4] {
- return arr[i]
- }
- }
- return -1
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md b/website/content/ChapterFour/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md
deleted file mode 100644
index 1c0f9be17..000000000
--- a/website/content/ChapterFour/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md
+++ /dev/null
@@ -1,81 +0,0 @@
-# [1290. Convert Binary Number in a Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/)
-
-
-
-## 题目
-
-Given `head` which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.
-
-Return the *decimal value* of the number in the linked list.
-
-**Example 1**:
-
-
-
-```
-Input: head = [1,0,1]
-Output: 5
-Explanation: (101) in base 2 = (5) in base 10
-```
-
-**Example 2**:
-
-```
-Input: head = [0]
-Output: 0
-```
-
-**Example 3**:
-
-```
-Input: head = [1]
-Output: 1
-```
-
-**Example 4**:
-
-```
-Input: head = [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0]
-Output: 18880
-```
-
-**Example 5**:
-
-```
-Input: head = [0,0]
-Output: 0
-```
-
-**Constraints**:
-
-- The Linked List is not empty.
-- Number of nodes will not exceed `30`.
-- Each node's value is either `0` or `1`.
-
-## 题目大意
-
-给你一个单链表的引用结点 head。链表中每个结点的值不是 0 就是 1。已知此链表是一个整数数字的二进制表示形式。请你返回该链表所表示数字的 十进制值 。
-
-提示:
-
-- 链表不为空。
-- 链表的结点总数不超过 30。
-- 每个结点的值不是 0 就是 1。
-
-## 解题思路
-
-- 给出一个链表,链表从头到尾表示的数是一个整数的二进制形式,要求输出这个整数的十进制。
-- 简单题,从头到尾遍历一次链表,边遍历边累加二进制位。
-
-## 代码
-
-```go
-func getDecimalValue(head *ListNode) int {
- sum := 0
- for head != nil {
- sum = sum*2 + head.Val
- head = head.Next
- }
- return sum
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1295.Find-Numbers-with-Even-Number-of-Digits.md b/website/content/ChapterFour/1295.Find-Numbers-with-Even-Number-of-Digits.md
deleted file mode 100644
index ccaa6c492..000000000
--- a/website/content/ChapterFour/1295.Find-Numbers-with-Even-Number-of-Digits.md
+++ /dev/null
@@ -1,63 +0,0 @@
-# [1295. Find Numbers with Even Number of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits/)
-
-
-
-## 题目
-
-Given an array `nums` of integers, return how many of them contain an **even number** of digits.
-
-**Example 1**:
-
-```
-Input: nums = [12,345,2,6,7896]
-Output: 2
-Explanation:
-12 contains 2 digits (even number of digits).
-345 contains 3 digits (odd number of digits).
-2 contains 1 digit (odd number of digits).
-6 contains 1 digit (odd number of digits).
-7896 contains 4 digits (even number of digits).
-Therefore only 12 and 7896 contain an even number of digits.
-```
-
-**Example 2**:
-
-```
-Input: nums = [555,901,482,1771]
-Output: 1
-Explanation:
-Only 1771 contains an even number of digits.
-```
-
-**Constraints**:
-
-- `1 <= nums.length <= 500`
-- `1 <= nums[i] <= 10^5`
-
-## 题目大意
-
-给你一个整数数组 nums,请你返回其中位数为 偶数 的数字的个数。
-
-提示:
-
-- 1 <= nums.length <= 500
-- 1 <= nums[i] <= 10^5
-
-
-
-## 解题思路
-
-- 给你一个整数数组,要求输出位数为偶数的数字的个数。
-- 简单题,把每个数字转换为字符串判断长度是否是偶数即可。
-
-## 代码
-
-```go
-func findNumbers(nums []int) int {
- res := 0
- for _, n := range nums {
- res += 1 - len(strconv.Itoa(n))%2
- }
- return res
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1299.Replace-Elements-with-Greatest-Element-on-Right-Side.md b/website/content/ChapterFour/1299.Replace-Elements-with-Greatest-Element-on-Right-Side.md
deleted file mode 100644
index 633c65761..000000000
--- a/website/content/ChapterFour/1299.Replace-Elements-with-Greatest-Element-on-Right-Side.md
+++ /dev/null
@@ -1,51 +0,0 @@
-# [1299. Replace Elements with Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/)
-
-
-
-## 题目
-
-Given an array `arr`, replace every element in that array with the greatest element among the elements to its right, and replace the last element with `-1`.
-
-After doing so, return the array.
-
-**Example 1**:
-
-```
-Input: arr = [17,18,5,4,6,1]
-Output: [18,6,6,6,1,-1]
-```
-
-**Constraints**:
-
-- `1 <= arr.length <= 10^4`
-- `1 <= arr[i] <= 10^5`
-
-
-## 题目大意
-
-给你一个数组 arr ,请你将每个元素用它右边最大的元素替换,如果是最后一个元素,用 -1 替换。完成所有替换操作后,请你返回这个数组。
-
-提示:
-
-- 1 <= arr.length <= 10^4
-- 1 <= arr[i] <= 10^5
-
-
-## 解题思路
-
-- 给出一个数组,要求把所有元素都替换成自己右边最大的元素,最后一位补上 -1 。最后输出变化以后的数组。
-- 简单题,按照题意操作即可。
-
-## 代码
-
-```go
-func replaceElements(arr []int) []int {
- j, temp := -1, 0
- for i := len(arr) - 1; i >= 0; i-- {
- temp = arr[i]
- arr[i] = j
- j = max(j, temp)
- }
- return arr
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1302.Deepest-Leaves-Sum.md b/website/content/ChapterFour/1302.Deepest-Leaves-Sum.md
deleted file mode 100644
index 70482634f..000000000
--- a/website/content/ChapterFour/1302.Deepest-Leaves-Sum.md
+++ /dev/null
@@ -1,58 +0,0 @@
-# [1302. Deepest Leaves Sum](https://leetcode.com/problems/deepest-leaves-sum/)
-
-
-
-## 题目
-
-Given a binary tree, return the sum of values of its deepest leaves.
-
-**Example 1**:
-
-
-
-```
-Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]
-Output: 15
-```
-
-**Constraints**:
-
-- The number of nodes in the tree is between `1` and `10^4`.
-- The value of nodes is between `1` and `100`.
-
-## 题目大意
-
-给你一棵二叉树,请你返回层数最深的叶子节点的和。
-
-提示:
-
-- 树中节点数目在 1 到 10^4 之间。
-- 每个节点的值在 1 到 100 之间。
-
-## 解题思路
-
-- 给你一棵二叉树,请你返回层数最深的叶子节点的和。
-- 这一题不难,DFS 遍历把最底层的叶子节点和都加起来即可。
-
-## 代码
-
-```go
-func deepestLeavesSum(root *TreeNode) int {
- maxLevel, sum := 0, 0
- dfsDeepestLeavesSum(root, 0, &maxLevel, &sum)
- return sum
-}
-
-func dfsDeepestLeavesSum(root *TreeNode, level int, maxLevel, sum *int) {
- if root == nil {
- return
- }
- if level > *maxLevel {
- *maxLevel, *sum = level, root.Val
- } else if level == *maxLevel {
- *sum += root.Val
- }
- dfsDeepestLeavesSum(root.Left, level+1, maxLevel, sum)
- dfsDeepestLeavesSum(root.Right, level+1, maxLevel, sum)
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1304.Find-N-Unique-Integers-Sum-up-to-Zero.md b/website/content/ChapterFour/1304.Find-N-Unique-Integers-Sum-up-to-Zero.md
deleted file mode 100644
index 1e15836e3..000000000
--- a/website/content/ChapterFour/1304.Find-N-Unique-Integers-Sum-up-to-Zero.md
+++ /dev/null
@@ -1,62 +0,0 @@
-# [1304. Find N Unique Integers Sum up to Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/)
-
-
-
-## 题目
-
-Given an integer `n`, return **any** array containing `n` **unique** integers such that they add up to 0.
-
-**Example 1**:
-
-```
-Input: n = 5
-Output: [-7,-1,1,3,4]
-Explanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].
-```
-
-**Example 2**:
-
-```
-Input: n = 3
-Output: [-1,0,1]
-```
-
-**Example 3**:
-
-```
-Input: n = 1
-Output: [0]
-```
-
-**Constraints**:
-
-- `1 <= n <= 1000`
-
-## 题目大意
-
-给你一个整数 n,请你返回 任意 一个由 n 个 各不相同 的整数组成的数组,并且这 n 个数相加和为 0 。
-
-提示:
-
-- 1 <= n <= 1000
-
-## 解题思路
-
-- 给出一个数 n,输出一个有 n 个数的数组,里面元素之和为 0 。
-- 简单题,简单循环即可。
-
-## 代码
-
-```go
-func sumZero(n int) []int {
- res, left, right, start := make([]int, n), 0, n-1, 1
- for left < right {
- res[left] = start
- res[right] = -start
- start++
- left = left + 1
- right = right - 1
- }
- return res
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1305.All-Elements-in-Two-Binary-Search-Trees.md b/website/content/ChapterFour/1305.All-Elements-in-Two-Binary-Search-Trees.md
deleted file mode 100644
index 247bbfbbe..000000000
--- a/website/content/ChapterFour/1305.All-Elements-in-Two-Binary-Search-Trees.md
+++ /dev/null
@@ -1,90 +0,0 @@
-# [1305. All Elements in Two Binary Search Trees](https://leetcode.com/problems/all-elements-in-two-binary-search-trees/)
-
-
-
-## 题目
-
-Given two binary search trees `root1` and `root2`.
-
-Return a list containing *all the integers* from *both trees* sorted in **ascending** order.
-
-**Example 1**:
-
-
-
-```
-Input: root1 = [2,1,4], root2 = [1,0,3]
-Output: [0,1,1,2,3,4]
-```
-
-**Example 2**:
-
-```
-Input: root1 = [0,-10,10], root2 = [5,1,7,0,2]
-Output: [-10,0,0,1,2,5,7,10]
-```
-
-**Example 3**:
-
-```
-Input: root1 = [], root2 = [5,1,7,0,2]
-Output: [0,1,2,5,7]
-```
-
-**Example 4**:
-
-```
-Input: root1 = [0,-10,10], root2 = []
-Output: [-10,0,10]
-```
-
-**Example 5**:
-
-
-
-```
-Input: root1 = [1,null,8], root2 = [8,1]
-Output: [1,1,8,8]
-```
-
-**Constraints**:
-
-- Each tree has at most `5000` nodes.
-- Each node's value is between `[-10^5, 10^5]`.
-
-## 题目大意
-
-给你 root1 和 root2 这两棵二叉搜索树。请你返回一个列表,其中包含 两棵树 中的所有整数并按 升序 排序。.
-
-提示:
-
-- 每棵树最多有 5000 个节点。
-- 每个节点的值在 [-10^5, 10^5] 之间。
-
-
-## 解题思路
-
-- 给出 2 棵二叉排序树,要求将 2 棵树所有节点的值按照升序排序。
-- 这一题最暴力简单的方法就是把 2 棵树的节点都遍历出来,然后放在一个数组里面从小到大排序即可。这样做虽然能 AC,但是时间复杂度高。因为题目中给的二叉排序树这一条件没有用上。由于树中节点本来已经有序了,所以题目实质想要我们合并 2 个有序数组。利用中根遍历,把 2 个二叉排序树的所有节点值都遍历出来,遍历出来以后就是有序的。接下来再合并这两个有序数组即可。合并 2 个有序数组是第 88 题。
-
-## 代码
-
-```go
-// 解法一 合并排序
-func getAllElements(root1 *TreeNode, root2 *TreeNode) []int {
- arr1 := inorderTraversal(root1)
- arr2 := inorderTraversal(root2)
- arr1 = append(arr1, make([]int, len(arr2))...)
- merge(arr1, len(arr1)-len(arr2), arr2, len(arr2))
- return arr1
-}
-
-// 解法二 暴力遍历排序,时间复杂度高
-func getAllElements1(root1 *TreeNode, root2 *TreeNode) []int {
- arr := []int{}
- arr = append(arr, preorderTraversal(root1)...)
- arr = append(arr, preorderTraversal(root2)...)
- sort.Ints(arr)
- return arr
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1306.Jump-Game-III.md b/website/content/ChapterFour/1306.Jump-Game-III.md
deleted file mode 100644
index 63f26345a..000000000
--- a/website/content/ChapterFour/1306.Jump-Game-III.md
+++ /dev/null
@@ -1,80 +0,0 @@
-# [1306. Jump Game III](https://leetcode.com/problems/jump-game-iii/)
-
-
-## 题目
-
-Given an array of non-negative integers `arr`, you are initially positioned at `start` index of the array. When you are at index `i`, you can jump to `i + arr[i]` or `i - arr[i]`, check if you can reach to **any** index with value 0.
-
-Notice that you can not jump outside of the array at any time.
-
-**Example 1**:
-
-```
-Input: arr = [4,2,3,0,3,1,2], start = 5
-Output: true
-Explanation:
-All possible ways to reach at index 3 with value 0 are:
-index 5 -> index 4 -> index 1 -> index 3
-index 5 -> index 6 -> index 4 -> index 1 -> index 3
-```
-
-**Example 2**:
-
-```
-Input: arr = [4,2,3,0,3,1,2], start = 0
-Output: true
-Explanation:
-One possible way to reach at index 3 with value 0 is:
-index 0 -> index 4 -> index 1 -> index 3
-```
-
-**Example 3**:
-
-```
-Input: arr = [3,0,2,1,2], start = 2
-Output: false
-Explanation: There is no way to reach at index 1 with value 0.
-```
-
-**Constraints**:
-
-- `1 <= arr.length <= 5 * 10^4`
-- `0 <= arr[i] < arr.length`
-- `0 <= start < arr.length`
-
-
-## 题目大意
-
-这里有一个非负整数数组 arr,你最开始位于该数组的起始下标 start 处。当你位于下标 i 处时,你可以跳到 i + arr[i] 或者 i - arr[i]。请你判断自己是否能够跳到对应元素值为 0 的 任一 下标处。注意,不管是什么情况下,你都无法跳到数组之外。
-
-提示:
-
-- 1 <= arr.length <= 5 * 10^4
-- 0 <= arr[i] < arr.length
-- 0 <= start < arr.length
-
-
-## 解题思路
-
-- 给出一个非负数组和一个起始下标 `start`。站在 `start`,每次可以跳到 `i + arr[i]` 或者 `i - arr[i]` 。要求判断能否跳到元素值为 0 的下标处。
-- 这一题考察的是递归。每一步都需要判断 3 种可能:
- 1. 当前是否站在元素值为 0 的目标点上。
- 2. 往前跳 arr[start],是否能站在元素值为 0 的目标点上。
- 3. 往后跳 arr[start],是否能站在元素值为 0 的目标点上。
-
- 第 2 种可能和第 3 种可能递归即可,每一步都判断这 3 种可能是否有一种能跳到元素值为 0 的下标处。
-
-- `arr[start] += len(arr)` 这一步仅仅只是为了标记此下标已经用过了,下次判断的时候该下标会被 `if` 条件筛选掉。
-
-## 代码
-
-```go
-func canReach(arr []int, start int) bool {
- if start >= 0 && start < len(arr) && arr[start] < len(arr) {
- jump := arr[start]
- arr[start] += len(arr)
- return jump == 0 || canReach(arr, start+jump) || canReach(arr, start-jump)
- }
- return false
-}
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1313.Decompress-Run-Length-Encoded-List.md b/website/content/ChapterFour/1313.Decompress-Run-Length-Encoded-List.md
deleted file mode 100644
index 645d90578..000000000
--- a/website/content/ChapterFour/1313.Decompress-Run-Length-Encoded-List.md
+++ /dev/null
@@ -1,60 +0,0 @@
-# [1313. Decompress Run-Length Encoded List](https://leetcode.com/problems/decompress-run-length-encoded-list/)
-
-
-## 题目
-
-We are given a list `nums` of integers representing a list compressed with run-length encoding.
-
-Consider each adjacent pair of elements `[freq, val] = [nums[2*i], nums[2*i+1]]` (with `i >= 0`). For each such pair, there are `freq` elements with value `val` concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.
-
-Return the decompressed list.
-
-**Example 1**:
-
-```
-Input: nums = [1,2,3,4]
-Output: [2,4,4,4]
-Explanation: The first pair [1,2] means we have freq = 1 and val = 2 so we generate the array [2].
-The second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4].
-At the end the concatenation [2] + [4,4,4] is [2,4,4,4].
-```
-
-**Example 2**:
-
-```
-Input: nums = [1,1,2,3]
-Output: [1,3,3]
-```
-
-**Constraints**:
-
-- `2 <= nums.length <= 100`
-- `nums.length % 2 == 0`
-- `1 <= nums[i] <= 100`
-
-## 题目大意
-
-给你一个以行程长度编码压缩的整数列表 nums 。考虑每对相邻的两个元素 [freq, val] = [nums[2*i], nums[2*i+1]] (其中 i >= 0 ),每一对都表示解压后子列表中有 freq 个值为 val 的元素,你需要从左到右连接所有子列表以生成解压后的列表。请你返回解压后的列表。
-
-## 解题思路
-
-- 给定一个带编码长度的数组,要求解压这个数组。
-- 简单题。按照题目要求,下标从 0 开始,奇数位下标为前一个下标对应元素重复次数,那么就把这个元素 append 几次。最终输出解压后的数组即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func decompressRLElist(nums []int) []int {
- res := []int{}
- for i := 0; i < len(nums); i += 2 {
- for j := 0; j < nums[i]; j++ {
- res = append(res, nums[i+1])
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers.md b/website/content/ChapterFour/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers.md
deleted file mode 100644
index b7871908f..000000000
--- a/website/content/ChapterFour/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers.md
+++ /dev/null
@@ -1,96 +0,0 @@
-# [1317. Convert Integer to the Sum of Two No-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/)
-
-
-## 题目
-
-Given an integer `n`. No-Zero integer is a positive integer which **doesn't contain any 0** in its decimal representation.
-
-Return *a list of two integers* `[A, B]` where:
-
-- `A` and `B` are No-Zero integers.
-- `A + B = n`
-
-It's guarateed that there is at least one valid solution. If there are many valid solutions you can return any of them.
-
-**Example 1**:
-
-```
-Input: n = 2
-Output: [1,1]
-Explanation: A = 1, B = 1. A + B = n and both A and B don't contain any 0 in their decimal representation.
-```
-
-**Example 2**:
-
-```
-Input: n = 11
-Output: [2,9]
-```
-
-**Example 3**:
-
-```
-Input: n = 10000
-Output: [1,9999]
-```
-
-**Example 4**:
-
-```
-Input: n = 69
-Output: [1,68]
-```
-
-**Example 5**:
-
-```
-Input: n = 1010
-Output: [11,999]
-```
-
-**Constraints**:
-
-- `2 <= n <= 10^4`
-
-## 题目大意
-
-「无零整数」是十进制表示中 不含任何 0 的正整数。给你一个整数 n,请你返回一个 由两个整数组成的列表 [A, B],满足:
-
-- A 和 B 都是无零整数
-- A + B = n
-
-题目数据保证至少有一个有效的解决方案。如果存在多个有效解决方案,你可以返回其中任意一个。
-
-## 解题思路
-
-- 给定一个整数 n,要求把它分解为 2 个十进制位中不含 0 的正整数且这两个正整数之和为 n。
-- 简单题。在 [1, n/2] 区间内搜索,只要有一组满足条件的解就 break。题目保证了至少有一组解,并且多组解返回任意一组即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func getNoZeroIntegers(n int) []int {
- noZeroPair := []int{}
- for i := 1; i <= n/2; i++ {
- if isNoZero(i) && isNoZero(n-i) {
- noZeroPair = append(noZeroPair, []int{i, n - i}...)
- break
- }
- }
- return noZeroPair
-}
-
-func isNoZero(n int) bool {
- for n != 0 {
- if n%10 == 0 {
- return false
- }
- n /= 10
- }
- return true
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1380.Lucky-Numbers-in-a-Matrix.md b/website/content/ChapterFour/1380.Lucky-Numbers-in-a-Matrix.md
deleted file mode 100644
index 01d97eb82..000000000
--- a/website/content/ChapterFour/1380.Lucky-Numbers-in-a-Matrix.md
+++ /dev/null
@@ -1,87 +0,0 @@
-# [1380. Lucky Numbers in a Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix/)
-
-
-## 题目
-
-Given a `m * n` matrix of **distinct** numbers, return all lucky numbers in the matrix in **any** order.
-
-A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.
-
-**Example 1**:
-
-```
-Input: matrix = [[3,7,8],[9,11,13],[15,16,17]]
-Output: [15]
-Explanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column
-```
-
-**Example 2**:
-
-```
-Input: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
-Output: [12]
-Explanation: 12 is the only lucky number since it is the minimum in its row and the maximum in its column.
-```
-
-**Example 3**:
-
-```
-Input: matrix = [[7,8],[1,2]]
-Output: [7]
-```
-
-**Constraints**:
-
-- `m == mat.length`
-- `n == mat[i].length`
-- `1 <= n, m <= 50`
-- `1 <= matrix[i][j] <= 10^5`.
-- All elements in the matrix are distinct.
-
-## 题目大意
-
-给你一个 m * n 的矩阵,矩阵中的数字 各不相同 。请你按 任意 顺序返回矩阵中的所有幸运数。幸运数是指矩阵中满足同时下列两个条件的元素:
-
-- 在同一行的所有元素中最小
-- 在同一列的所有元素中最大
-
-
-
-## 解题思路
-
-- 找出矩阵中的幸运数。幸运数的定义:同时满足 2 个条件,在同一行的所有元素中最小并且在同一列的所有元素中最大。
-- 简单题。按照题意遍历矩阵,找到同时满足 2 个条件的数输出即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func luckyNumbers(matrix [][]int) []int {
- t, r, res := make([]int, len(matrix[0])), make([]int, len(matrix[0])), []int{}
- for _, val := range matrix {
- m, k := val[0], 0
- for j := 0; j < len(matrix[0]); j++ {
- if val[j] < m {
- m = val[j]
- k = j
- }
- if t[j] < val[j] {
- t[j] = val[j]
- }
- }
-
- if t[k] == m {
- r[k] = m
- }
- }
- for k, v := range r {
- if v > 0 && v == t[k] {
- res = append(res, v)
- }
- }
- return res
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1385.Find-the-Distance-Value-Between-Two-Arrays.md b/website/content/ChapterFour/1385.Find-the-Distance-Value-Between-Two-Arrays.md
deleted file mode 100644
index 9d6042469..000000000
--- a/website/content/ChapterFour/1385.Find-the-Distance-Value-Between-Two-Arrays.md
+++ /dev/null
@@ -1,98 +0,0 @@
-# [1385. Find the Distance Value Between Two Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays/)
-
-
-## 题目
-
-Given two integer arrays `arr1` and `arr2`, and the integer `d`, *return the distance value between the two arrays*.
-
-The distance value is defined as the number of elements `arr1[i]` such that there is not any element `arr2[j]` where `|arr1[i]-arr2[j]| <= d`.
-
-**Example 1**:
-
-```
-Input: arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2
-Output: 2
-Explanation:
-For arr1[0]=4 we have:
-|4-10|=6 > d=2
-|4-9|=5 > d=2
-|4-1|=3 > d=2
-|4-8|=4 > d=2
-For arr1[1]=5 we have:
-|5-10|=5 > d=2
-|5-9|=4 > d=2
-|5-1|=4 > d=2
-|5-8|=3 > d=2
-For arr1[2]=8 we have:
-|8-10|=2 <= d=2
-|8-9|=1 <= d=2
-|8-1|=7 > d=2
-|8-8|=0 <= d=2
-```
-
-**Example 2**:
-
-```
-Input: arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3
-Output: 2
-```
-
-**Example 3**:
-
-```
-Input: arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6
-Output: 1
-```
-
-**Constraints**:
-
-- `1 <= arr1.length, arr2.length <= 500`
-- `-10^3 <= arr1[i], arr2[j] <= 10^3`
-- `0 <= d <= 100`
-
-
-## 题目大意
-
-给你两个整数数组 arr1 , arr2 和一个整数 d ,请你返回两个数组之间的 距离值 。「距离值」 定义为符合此距离要求的元素数目:对于元素 arr1[i] ,不存在任何元素 arr2[j] 满足 |arr1[i]-arr2[j]| <= d 。
-
-提示:
-
-- 1 <= arr1.length, arr2.length <= 500
-- -10^3 <= arr1[i], arr2[j] <= 10^3
-- 0 <= d <= 100
-
-
-## 解题思路
-
-- 计算两个数组之间的距离,距离值的定义:满足对于元素 arr1[i] ,不存在任何元素 arr2[j] 满足 |arr1[i]-arr2[j]| <= d 这一条件的元素数目。
-- 简单题,按照距离值的定义,双层循环计数即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func findTheDistanceValue(arr1 []int, arr2 []int, d int) int {
- res := 0
- for i := range arr1 {
- for j := range arr2 {
- if abs(arr1[i]-arr2[j]) <= d {
- break
- }
- if j == len(arr2)-1 {
- res++
- }
- }
- }
- return res
-}
-
-func abs(a int) int {
- if a < 0 {
- return -1 * a
- }
- return a
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1389.Create-Target-Array-in-the-Given-Order.md b/website/content/ChapterFour/1389.Create-Target-Array-in-the-Given-Order.md
deleted file mode 100644
index 45f4acf6a..000000000
--- a/website/content/ChapterFour/1389.Create-Target-Array-in-the-Given-Order.md
+++ /dev/null
@@ -1,90 +0,0 @@
-# [1389. Create Target Array in the Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order/)
-
-## 题目
-
-Given two arrays of integers `nums` and `index`. Your task is to create *target* array under the following rules:
-
-- Initially *target* array is empty.
-- From left to right read nums[i] and index[i], insert at index `index[i]` the value `nums[i]` in *target* array.
-- Repeat the previous step until there are no elements to read in `nums` and `index.`
-
-Return the *target* array.
-
-It is guaranteed that the insertion operations will be valid.
-
-**Example 1**:
-
-```
-Input: nums = [0,1,2,3,4], index = [0,1,2,2,1]
-Output: [0,4,1,3,2]
-Explanation:
-nums index target
-0 0 [0]
-1 1 [0,1]
-2 2 [0,1,2]
-3 2 [0,1,3,2]
-4 1 [0,4,1,3,2]
-```
-
-**Example 2**:
-
-```
-Input: nums = [1,2,3,4,0], index = [0,1,2,3,0]
-Output: [0,1,2,3,4]
-Explanation:
-nums index target
-1 0 [1]
-2 1 [1,2]
-3 2 [1,2,3]
-4 3 [1,2,3,4]
-0 0 [0,1,2,3,4]
-```
-
-**Example 3**:
-
-```
-Input: nums = [1], index = [0]
-Output: [1]
-```
-
-**Constraints**:
-
-- `1 <= nums.length, index.length <= 100`
-- `nums.length == index.length`
-- `0 <= nums[i] <= 100`
-- `0 <= index[i] <= i`
-
-## 题目大意
-
-给你两个整数数组 nums 和 index。你需要按照以下规则创建目标数组:
-
-- 目标数组 target 最初为空。
-- 按从左到右的顺序依次读取 nums[i] 和 index[i],在 target 数组中的下标 index[i] 处插入值 nums[i] 。
-- 重复上一步,直到在 nums 和 index 中都没有要读取的元素。
-
-请你返回目标数组。题目保证数字插入位置总是存在。
-
-
-
-
-## 解题思路
-
-- 给定 2 个数组,分别装的是待插入的元素和待插入的位置。最后输出操作完成的数组。
-- 简单题,按照题意插入元素即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func createTargetArray(nums []int, index []int) []int {
- result := make([]int, len(nums))
- for i, pos := range index {
- copy(result[pos+1:i+1], result[pos:i])
- result[pos] = nums[i]
- }
- return result
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md b/website/content/ChapterFour/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md
deleted file mode 100644
index c8081e82b..000000000
--- a/website/content/ChapterFour/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md
+++ /dev/null
@@ -1,98 +0,0 @@
-# [1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/)
-
-
-## 题目
-
-Given a `sentence` that consists of some words separated by a **single space**, and a `searchWord`.
-
-You have to check if `searchWord` is a prefix of any word in `sentence`.
-
-Return *the index of the word* in `sentence` where `searchWord` is a prefix of this word (**1-indexed**).
-
-If `searchWord` is a prefix of more than one word, return the index of the first word **(minimum index)**. If there is no such word return **-1**.
-
-A **prefix** of a string `S` is any leading contiguous substring of `S`.
-
-**Example 1**:
-
-```
-Input: sentence = "i love eating burger", searchWord = "burg"
-Output: 4
-Explanation: "burg" is prefix of "burger" which is the 4th word in the sentence.
-
-```
-
-**Example 2**:
-
-```
-Input: sentence = "this problem is an easy problem", searchWord = "pro"
-Output: 2
-Explanation: "pro" is prefix of "problem" which is the 2nd and the 6th word in the sentence, but we return 2 as it's the minimal index.
-
-```
-
-**Example 3**:
-
-```
-Input: sentence = "i am tired", searchWord = "you"
-Output: -1
-Explanation: "you" is not a prefix of any word in the sentence.
-
-```
-
-**Example 4**:
-
-```
-Input: sentence = "i use triple pillow", searchWord = "pill"
-Output: 4
-
-```
-
-**Example 5**:
-
-```
-Input: sentence = "hello from the other side", searchWord = "they"
-Output: -1
-
-```
-
-**Constraints**:
-
-- `1 <= sentence.length <= 100`
-- `1 <= searchWord.length <= 10`
-- `sentence` consists of lowercase English letters and spaces.
-- `searchWord` consists of lowercase English letters.
-
-## 题目大意
-
-给你一个字符串 sentence 作为句子并指定检索词为 searchWord ,其中句子由若干用 单个空格 分隔的单词组成。请你检查检索词 searchWord 是否为句子 sentence 中任意单词的前缀。
-
-- 如果 searchWord 是某一个单词的前缀,则返回句子 sentence 中该单词所对应的下标(下标从 1 开始)。
-- 如果 searchWord 是多个单词的前缀,则返回匹配的第一个单词的下标(最小下标)。
-- 如果 searchWord 不是任何单词的前缀,则返回 -1 。
-
-字符串 S 的 「前缀」是 S 的任何前导连续子字符串。
-
-## 解题思路
-
-- 给出 2 个字符串,一个是匹配串,另外一个是句子。在句子里面查找带匹配串前缀的单词,并返回第一个匹配单词的下标。
-- 简单题。按照题意,扫描一遍句子,一次匹配即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-import "strings"
-
-func isPrefixOfWord(sentence string, searchWord string) int {
- for i, v := range strings.Split(sentence, " ") {
- if strings.HasPrefix(v, searchWord) {
- return i + 1
- }
- }
- return -1
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1464.Maximum-Product-of-Two-Elements-in-an-Array.md b/website/content/ChapterFour/1464.Maximum-Product-of-Two-Elements-in-an-Array.md
deleted file mode 100644
index 04dbf134b..000000000
--- a/website/content/ChapterFour/1464.Maximum-Product-of-Two-Elements-in-an-Array.md
+++ /dev/null
@@ -1,66 +0,0 @@
-# [1464. Maximum Product of Two Elements in an Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/)
-
-
-## 题目
-
-Given the array of integers `nums`, you will choose two different indices `i` and `j` of that array. Return the maximum value of `(nums[i]-1)*(nums[j]-1)`.
-
-**Example 1**:
-
-```
-Input: nums = [3,4,5,2]
-Output: 12
-Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12.
-
-```
-
-**Example 2**:
-
-```
-Input: nums = [1,5,4,5]
-Output: 16
-Explanation: Choosing the indices i=1 and j=3 (indexed from 0), you will get the maximum value of (5-1)*(5-1) = 16.
-
-```
-
-**Example 3**:
-
-```
-Input: nums = [3,7]
-Output: 12
-
-```
-
-**Constraints**:
-
-- `2 <= nums.length <= 500`
-- `1 <= nums[i] <= 10^3`
-
-## 题目大意
-
-给你一个整数数组 nums,请你选择数组的两个不同下标 i 和 j,使 (nums[i]-1)*(nums[j]-1) 取得最大值。请你计算并返回该式的最大值。
-
-## 解题思路
-
-- 简单题。循环一次,按照题意动态维护 2 个最大值,从而也使得 `(nums[i]-1)*(nums[j]-1)` 能取到最大值。
-
-## 代码
-
-```go
-
-package leetcode
-
-func maxProduct(nums []int) int {
- max1, max2 := 0, 0
- for _, num := range nums {
- if num >= max1 {
- max2 = max1
- max1 = num
- } else if num <= max1 && num >= max2 {
- max2 = num
- }
- }
- return (max1 - 1) * (max2 - 1)
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/1470.Shuffle-the-Array.md b/website/content/ChapterFour/1470.Shuffle-the-Array.md
deleted file mode 100644
index 961d200c4..000000000
--- a/website/content/ChapterFour/1470.Shuffle-the-Array.md
+++ /dev/null
@@ -1,64 +0,0 @@
-# [1470. Shuffle the Array](https://leetcode.com/problems/shuffle-the-array/)
-
-## 题目
-
-Given the array `nums` consisting of `2n` elements in the form `[x1,x2,...,xn,y1,y2,...,yn]`.
-
-*Return the array in the form* `[x1,y1,x2,y2,...,xn,yn]`.
-
-**Example 1**:
-
-```
-Input: nums = [2,5,1,3,4,7], n = 3
-Output: [2,3,5,4,1,7]
-Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].
-
-```
-
-**Example 2**:
-
-```
-Input: nums = [1,2,3,4,4,3,2,1], n = 4
-Output: [1,4,2,3,3,2,4,1]
-
-```
-
-**Example 3**:
-
-```
-Input: nums = [1,1,2,2], n = 2
-Output: [1,2,1,2]
-
-```
-
-**Constraints**:
-
-- `1 <= n <= 500`
-- `nums.length == 2n`
-- `1 <= nums[i] <= 10^3`
-
-## 题目大意
-
-给你一个数组 nums ,数组中有 2n 个元素,按 [x1,x2,...,xn,y1,y2,...,yn] 的格式排列。请你将数组按 [x1,y1,x2,y2,...,xn,yn] 格式重新排列,返回重排后的数组。
-
-## 解题思路
-
-- 给定一个 2n 的数组,把后 n 个元素插空放到前 n 个元素里面。输出最终完成的数组。
-- 简单题,按照题意插空即可。
-
-## 代码
-
-```go
-
-package leetcode
-
-func shuffle(nums []int, n int) []int {
- result := make([]int, 0)
- for i := 0; i < n; i++ {
- result = append(result, nums[i])
- result = append(result, nums[n+i])
- }
- return result
-}
-
-```
\ No newline at end of file
diff --git a/website/content/ChapterFour/_index.md b/website/content/ChapterFour/_index.md
deleted file mode 100644
index 3daf13a7b..000000000
--- a/website/content/ChapterFour/_index.md
+++ /dev/null
@@ -1,17 +0,0 @@
----
-title: 第四章
-type: docs
----
-
-# 第四章 Leetcode 题解
-
-
-
-
-这一章会罗列一些整理好的模板。一起来看看吧。
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Array.md b/website/content/ChapterTwo/Array.md
deleted file mode 100644
index 59dfa8f18..000000000
--- a/website/content/ChapterTwo/Array.md
+++ /dev/null
@@ -1,62 +0,0 @@
----
-title: Array
-type: docs
----
-
-# Array
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|1. Two Sum| [Go]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})| Easy | O(n)| O(n)||
-|11. Container With Most Water| [Go]({{< relref "/ChapterFour/0011.Container-With-Most-Water.md" >}})| Medium | O(n)| O(1)||
-|15. 3Sum | [Go]({{< relref "/ChapterFour/0015.3Sum.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|16. 3Sum Closest | [Go]({{< relref "/ChapterFour/0016.3Sum-Closest.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|18. 4Sum | [Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})| Medium | O(n^3)| O(n^2)|❤️|
-|26. Remove Duplicates from Sorted Array | [Go]({{< relref "/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
-|27. Remove Element | [Go]({{< relref "/ChapterFour/0027.Remove-Element.md" >}})| Easy | O(n)| O(1)||
-|39. Combination Sum | [Go]({{< relref "/ChapterFour/0039.Combination-Sum.md" >}})| Medium | O(n log n)| O(n)||
-|40. Combination Sum II | [Go]({{< relref "/ChapterFour/0040.Combination-Sum-II.md" >}})| Medium | O(n log n)| O(n)||
-|41. First Missing Positive | [Go]({{< relref "/ChapterFour/0041.First-Missing-Positive.md" >}})| Hard | O(n)| O(n)||
-|42. Trapping Rain Water | [Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})| Hard | O(n)| O(1)|❤️|
-|48. Rotate Image | [Go]({{< relref "/ChapterFour/0048.Rotate-Image.md" >}})| Medium | O(n)| O(1)||
-|53. Maximum Subarray| [Go]({{< relref "/ChapterFour/0053.Maximum-Subarray.md" >}})| Easy | O(n)| O(n)||
-|54. Spiral Matrix| [Go]({{< relref "/ChapterFour/0054.Spiral-Matrix.md" >}})| Medium | O(n)| O(n^2)||
-|56. Merge Intervals | [Go]({{< relref "/ChapterFour/0056.Merge-Intervals.md" >}})| Medium | O(n log n)| O(1)||
-|57. Insert Interval | [Go]({{< relref "/ChapterFour/0057.Insert-Interval.md" >}})| Hard | O(n)| O(1)||
-|59. Spiral Matrix II | [Go]({{< relref "/ChapterFour/0059.Spiral-Matrix-II.md" >}})| Medium | O(n)| O(n^2)||
-|62. Unique Paths | [Go]({{< relref "/ChapterFour/0062.Unique-Paths.md" >}})| Medium | O(n^2)| O(n^2)||
-|63. Unique Paths II | [Go]({{< relref "/ChapterFour/0063.Unique-Paths-II.md" >}})| Medium | O(n^2)| O(n^2)||
-|64. Minimum Path Sum | [Go]({{< relref "/ChapterFour/0064.Minimum-Path-Sum.md" >}})| Medium | O(n^2)| O(n^2)||
-|75. Sort Colors | [Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})| Medium| O(n)| O(1)|❤️|
-|78. Subsets| [Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|79. Word Search | [Go]({{< relref "/ChapterFour/0079.Word-Search.md" >}})| Medium | O(n^2)| O(n^2)|❤️|
-|80. Remove Duplicates from Sorted Array II| [Go]({{< relref "/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md" >}})| Medium | O(n)| O(1||
-|84. Largest Rectangle in Histogram | [Go]({{< relref "/ChapterFour/0084.Largest-Rectangle-in-Histogram.md" >}})| Medium | O(n)| O(n)|❤️|
-|88. Merge Sorted Array | [Go]({{< relref "/ChapterFour/0088.Merge-Sorted-Array.md" >}})| Easy | O(n)| O(1)|❤️|
-|90. Subsets II | [Go]({{< relref "/ChapterFour/0090.Subsets-II.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|120. Triangle | [Go]({{< relref "/ChapterFour/0120.Triangle.md" >}})| Medium | O(n^2)| O(n)||
-|121. Best Time to Buy and Sell Stock | [Go]({{< relref "/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md" >}})| Easy | O(n)| O(1)||
-|122. Best Time to Buy and Sell Stock II | [Go]({{< relref "/ChapterFour/0122.Best-Time-to-Buy-and-Sell-Stock-II.md" >}})| Easy | O(n)| O(1)||
-|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
-|152. Maximum Product Subarray | [Go]({{< relref "/ChapterFour/0152.Maximum-Product-Subarray.md" >}})| Medium | O(n)| O(1)||
-|167. Two Sum II - Input array is sorted | [Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})| Easy | O(n)| O(1)||
-|209. Minimum Size Subarray Sum | [Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})| Medium | O(n)| O(1)||
-|216. Combination Sum III | [Go]({{< relref "/ChapterFour/0216.Combination-Sum-III.md" >}})| Medium | O(n)| O(1)|❤️|
-|217. Contains Duplicate | [Go]({{< relref "/ChapterFour/0217.Contains-Duplicate.md" >}})| Easy | O(n)| O(n)||
-|219. Contains Duplicate II | [Go]({{< relref "/ChapterFour/0219.Contains-Duplicate-II.md" >}})| Easy | O(n)| O(n)||
-|283. Move Zeroes | [Go]({{< relref "/ChapterFour/0283.Move-Zeroes.md" >}})| Easy | O(n)| O(1)||
-|287. Find the Duplicate Number | [Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})| Easy | O(n)| O(1)|❤️|
-|532. K-diff Pairs in an Array | [Go]({{< relref "/ChapterFour/0532.K-diff-Pairs-in-an-Array.md" >}})| Easy | O(n)| O(n)||
-|566. Reshape the Matrix | [Go]({{< relref "/ChapterFour/0566.Reshape-the-Matrix.md" >}})| Easy | O(n^2)| O(n^2)||
-|628. Maximum Product of Three Numbers | [Go]({{< relref "/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md" >}})| Easy | O(n)| O(1)||
-|713. Subarray Product Less Than K | [Go]({{< relref "/ChapterFour/0713.Subarray-Product-Less-Than-K.md" >}})| Medium | O(n)| O(1)||
-|714. Best Time to Buy and Sell Stock with Transaction Fee| [Go]({{< relref "/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md" >}})| Medium | O(n)| O(1)||
-|746. Min Cost Climbing Stairs | [Go]({{< relref "/ChapterFour/0746.Min-Cost-Climbing-Stairs.md" >}})| Easy | O(n)| O(1)||
-|766. Toeplitz Matrix | [Go]({{< relref "/ChapterFour/0766.Toeplitz-Matrix.md" >}})| Easy | O(n)| O(1)||
-|867. Transpose Matrix | [Go]({{< relref "/ChapterFour/0867.Transpose-Matrix.md" >}})| Easy | O(n)| O(1)||
-|891. Sum of Subsequence Widths | [Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})| Hard | O(n log n)| O(1)||
-|907. Sum of Subarray Minimums | [Go]({{< relref "/ChapterFour/0907.Sum-of-Subarray-Minimums.md" >}})| Medium | O(n)| O(n)|❤️|
-|922. Sort Array By Parity II | [Go]({{< relref "/ChapterFour/0922.Sort-Array-By-Parity-II.md" >}})| Medium | O(n)| O(1)||
-|969. Pancake Sorting | [Go]({{< relref "/ChapterFour/0969.Pancake-Sorting.md" >}})| Medium | O(n)| O(1)|❤️|
-|977. Squares of a Sorted Array | [Go]({{< relref "/ChapterFour/0977.Squares-of-a-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Backtracking.md b/website/content/ChapterTwo/Backtracking.md
deleted file mode 100644
index 74f112a07..000000000
--- a/website/content/ChapterTwo/Backtracking.md
+++ /dev/null
@@ -1,132 +0,0 @@
----
-title: Backtracking
-type: docs
----
-
-# Backtracking
-
-
-
-- 排列问题 Permutations。第 46 题,第 47 题。第 60 题,第 526 题,第 996 题。
-- 组合问题 Combination。第 39 题,第 40 题,第 77 题,第 216 题。
-- 排列和组合杂交问题。第 1079 题。
-- N 皇后终极解法(二进制解法)。第 51 题,第 52 题。
-- 数独问题。第 37 题。
-- 四个方向搜索。第 79 题,第 212 题,第 980 题。
-- 子集合问题。第 78 题,第 90 题。
-- Trie。第 208 题,第 211 题。
-- BFS 优化。第 126 题,第 127 题。
-- DFS 模板。(只是一个例子,不对应任何题)
-
-```go
-func combinationSum2(candidates []int, target int) [][]int {
- if len(candidates) == 0 {
- return [][]int{}
- }
- c, res := []int{}, [][]int{}
- sort.Ints(candidates)
- findcombinationSum2(candidates, target, 0, c, &res)
- return res
-}
-
-func findcombinationSum2(nums []int, target, index int, c []int, res *[][]int) {
- if target == 0 {
- b := make([]int, len(c))
- copy(b, c)
- *res = append(*res, b)
- return
- }
- for i := index; i < len(nums); i++ {
- if i > index && nums[i] == nums[i-1] { // 这里是去重的关键逻辑
- continue
- }
- if target >= nums[i] {
- c = append(c, nums[i])
- findcombinationSum2(nums, target-nums[i], i+1, c, res)
- c = c[:len(c)-1]
- }
- }
-}
-```
-- BFS 模板。(只是一个例子,不对应任何题)
-
-```go
-func updateMatrix_BFS(matrix [][]int) [][]int {
- res := make([][]int, len(matrix))
- if len(matrix) == 0 || len(matrix[0]) == 0 {
- return res
- }
- queue := make([][]int, 0)
- for i, _ := range matrix {
- res[i] = make([]int, len(matrix[0]))
- for j, _ := range res[i] {
- if matrix[i][j] == 0 {
- res[i][j] = -1
- queue = append(queue, []int{i, j})
- }
- }
- }
- level := 1
- for len(queue) > 0 {
- size := len(queue)
- for size > 0 {
- size -= 1
- node := queue[0]
- queue = queue[1:]
- i, j := node[0], node[1]
- for _, direction := range [][]int{{-1, 0}, {1, 0}, {0, 1}, {0, -1}} {
- x := i + direction[0]
- y := j + direction[1]
- if x < 0 || x >= len(matrix) || y < 0 || y >= len(matrix[0]) || res[x][y] < 0 || res[x][y] > 0 {
- continue
- }
- res[x][y] = level
- queue = append(queue, []int{x, y})
- }
- }
- level++
- }
- for i, row := range res {
- for j, cell := range row {
- if cell == -1 {
- res[i][j] = 0
- }
- }
- }
- return res
-}
-```
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|17. Letter Combinations of a Phone Number | [Go]({{< relref "/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md" >}})| Medium | O(log n)| O(1)||
-|22. Generate Parentheses| [Go]({{< relref "/ChapterFour/0022.Generate-Parentheses.md" >}})| Medium | O(log n)| O(1)||
-|37. Sudoku Solver | [Go]({{< relref "/ChapterFour/0037.Sudoku-Solver.md" >}})| Hard | O(n^2)| O(n^2)|❤️|
-|39. Combination Sum | [Go]({{< relref "/ChapterFour/0039.Combination-Sum.md" >}})| Medium | O(n log n)| O(n)||
-|40. Combination Sum II | [Go]({{< relref "/ChapterFour/0040.Combination-Sum-II.md" >}})| Medium | O(n log n)| O(n)||
-|46. Permutations | [Go]({{< relref "/ChapterFour/0046.Permutations.md" >}})| Medium | O(n)| O(n)|❤️|
-|47. Permutations II | [Go]({{< relref "/ChapterFour/0047.Permutations-II.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|51. N-Queens | [Go]({{< relref "/ChapterFour/0051.N-Queens.md" >}})| Hard | O(n^2)| O(n)|❤️|
-|52. N-Queens II | [Go]({{< relref "/ChapterFour/0052.N-Queens-II.md" >}})| Hard | O(n^2)| O(n)|❤️|
-|60. Permutation Sequence | [Go]({{< relref "/ChapterFour/0060.Permutation-Sequence.md" >}})| Medium | O(n log n)| O(1)||
-|77. Combinations | [Go]({{< relref "/ChapterFour/0077.Combinations.md" >}})| Medium | O(n)| O(n)|❤️|
-|78. Subsets | [Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|79. Word Search | [Go]({{< relref "/ChapterFour/0079.Word-Search.md" >}})| Medium | O(n^2)| O(n^2)|❤️|
-|89. Gray Codes | [Go]({{< relref "/ChapterFour/0089.Gray-Code.md" >}})| Medium | O(n)| O(1)||
-|90. Subsets II | [Go]({{< relref "/ChapterFour/0090.Subsets-II.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|93. Restore IP Addresses | [Go]({{< relref "/ChapterFour/0093.Restore-IP-Addresses.md" >}})| Medium | O(n)| O(n)|❤️|
-|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
-|131. Palindrome Partitioning | [Go]({{< relref "/ChapterFour/0131.Palindrome-Partitioning.md" >}})| Medium | O(n)| O(n^2)|❤️|
-|211. Add and Search Word - Data structure design | [Go]({{< relref "/ChapterFour/0211.Add-and-Search-Word---Data-structure-design.md" >}})| Medium | O(n)| O(n)|❤️|
-|212. Word Search II | [Go]({{< relref "/ChapterFour/0212.Word-Search-II.md" >}})| Hard | O(n^2)| O(n^2)|❤️|
-|216. Combination Sum III | [Go]({{< relref "/ChapterFour/0216.Combination-Sum-III.md" >}})| Medium | O(n)| O(1)|❤️|
-|306. Additive Number | [Go]({{< relref "/ChapterFour/0306.Additive-Number.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|357. Count Numbers with Unique Digits | [Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})| Medium | O(1)| O(1)||
-|401. Binary Watch | [Go]({{< relref "/ChapterFour/0401.Binary-Watch.md" >}})| Easy | O(1)| O(1)||
-|526. Beautiful Arrangement | [Go]({{< relref "/ChapterFour/0526.Beautiful-Arrangement.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|784. Letter Case Permutation | [Go]({{< relref "/ChapterFour/0784.Letter-Case-Permutation.md" >}})| Easy | O(n)| O(n)||
-|842. Split Array into Fibonacci Sequence | [Go]({{< relref "/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|980. Unique Paths III | [Go]({{< relref "/ChapterFour/0980.Unique-Paths-III.md" >}})| Hard | O(n log n)| O(n)||
-|996. Number of Squareful Arrays | [Go]({{< relref "/ChapterFour/0996.Number-of-Squareful-Arrays.md" >}})| Hard | O(n log n)| O(n) ||
-|1079. Letter Tile Possibilities | [Go]({{< relref "/ChapterFour/1079.Letter-Tile-Possibilities.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Binary_Indexed_Tree.md b/website/content/ChapterTwo/Binary_Indexed_Tree.md
deleted file mode 100644
index 7fbc2dfca..000000000
--- a/website/content/ChapterTwo/Binary_Indexed_Tree.md
+++ /dev/null
@@ -1,8 +0,0 @@
----
-title: Binary Indexed Tree
-type: docs
----
-
-# Binary Indexed Tree
-
-
diff --git a/website/content/ChapterTwo/Binary_Search.md b/website/content/ChapterTwo/Binary_Search.md
deleted file mode 100644
index 2c71c30df..000000000
--- a/website/content/ChapterTwo/Binary_Search.md
+++ /dev/null
@@ -1,145 +0,0 @@
----
-title: Binary Search
-type: docs
----
-
-# Binary Search
-
-- 二分搜索的经典写法。需要注意的三点:
- 1. 循环退出条件,注意是 low <= high,而不是 low < high。
- 2. mid 的取值,mid := low + (high-low)>>1
- 3. low 和 high 的更新。low = mid + 1,high = mid - 1。
-
-```go
-func binarySearchMatrix(nums []int, target int) int {
- low, high := 0, len(nums)-1
- for low <= high {
- mid := low + (high-low)>>1
- if nums[mid] == target {
- return mid
- } else if nums[mid] > target {
- high = mid - 1
- } else {
- low = mid + 1
- }
- }
- return -1
-}
-```
-
-- 二分搜索的变种写法。有 4 个基本变种:
- 1. 查找第一个与 target 相等的元素,时间复杂度 O(logn)
- 2. 查找最后一个与 target 相等的元素,时间复杂度 O(logn)
- 3. 查找第一个大于等于 target 的元素,时间复杂度 O(logn)
- 4. 查找最后一个小于等于 target 的元素,时间复杂度 O(logn)
-
-```go
-// 二分查找第一个与 target 相等的元素,时间复杂度 O(logn)
-func searchFirstEqualElement(nums []int, target int) int {
- low, high := 0, len(nums)-1
- for low <= high {
- mid := low + ((high - low) >> 1)
- if nums[mid] > target {
- high = mid - 1
- } else if nums[mid] < target {
- low = mid + 1
- } else {
- if (mid == 0) || (nums[mid-1] != target) { // 找到第一个与 target 相等的元素
- return mid
- }
- high = mid - 1
- }
- }
- return -1
-}
-
-// 二分查找最后一个与 target 相等的元素,时间复杂度 O(logn)
-func searchLastEqualElement(nums []int, target int) int {
- low, high := 0, len(nums)-1
- for low <= high {
- mid := low + ((high - low) >> 1)
- if nums[mid] > target {
- high = mid - 1
- } else if nums[mid] < target {
- low = mid + 1
- } else {
- if (mid == len(nums)-1) || (nums[mid+1] != target) { // 找到最后一个与 target 相等的元素
- return mid
- }
- low = mid + 1
- }
- }
- return -1
-}
-
-// 二分查找第一个大于等于 target 的元素,时间复杂度 O(logn)
-func searchFirstGreaterElement(nums []int, target int) int {
- low, high := 0, len(nums)-1
- for low <= high {
- mid := low + ((high - low) >> 1)
- if nums[mid] >= target {
- if (mid == 0) || (nums[mid-1] < target) { // 找到第一个大于等于 target 的元素
- return mid
- }
- high = mid - 1
- } else {
- low = mid + 1
- }
- }
- return -1
-}
-
-// 二分查找最后一个小于等于 target 的元素,时间复杂度 O(logn)
-func searchLastLessElement(nums []int, target int) int {
- low, high := 0, len(nums)-1
- for low <= high {
- mid := low + ((high - low) >> 1)
- if nums[mid] <= target {
- if (mid == len(nums)-1) || (nums[mid+1] > target) { // 找到最后一个小于等于 target 的元素
- return mid
- }
- low = mid + 1
- } else {
- high = mid - 1
- }
- }
- return -1
-}
-```
-
-- 在基本有序的数组中用二分搜索。经典解法可以解,变种写法也可以写,常见的题型,在山峰数组中找山峰,在旋转有序数组中找分界点。第 33 题,第 81 题,第 153 题,第 154 题,第 162 题,第 852 题
-
-```go
-func peakIndexInMountainArray(A []int) int {
- low, high := 0, len(A)-1
- for low < high {
- mid := low + (high-low)>>1
- // 如果 mid 较大,则左侧存在峰值,high = m,如果 mid + 1 较大,则右侧存在峰值,low = mid + 1
- if A[mid] > A[mid+1] {
- high = mid
- } else {
- low = mid + 1
- }
- }
- return low
-}
-```
-
-- max-min 最大值最小化问题。求在最小满足条件的情况下的最大值。第 410 题,第 875 题,第 1011 题,第 1283 题。
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|50. Pow(x, n) | [Go]({{< relref "/ChapterFour/0050.Powx-n.md" >}})| Medium | O(log n)| O(1)||
-|69. Sqrt(x) | [Go]({{< relref "/ChapterFour/0069.Sqrtx.md" >}})| Easy | O(log n)| O(1)||
-|167. Two Sum II - Input array is sorted | [Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})| Easy | O(n)| O(1)||
-|209. Minimum Size Subarray Sum | [Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})| Medium | O(n)| O(1)||
-|222. Count Complete Tree Nodes | [Go]({{< relref "/ChapterFour/0222.Count-Complete-Tree-Nodes.md" >}})| Medium | O(n)| O(1)||
-|230. Kth Smallest Element in a BST | [Go]({{< relref "/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md" >}})| Medium | O(n)| O(1)||
-|287. Find the Duplicate Number | [Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})| Easy | O(n)| O(1)|❤️|
-|300. Longest Increasing Subsequence | [Go]({{< relref "/ChapterFour/0300.Longest-Increasing-Subsequence.md" >}})| Medium | O(n log n)| O(n)||
-|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
-|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
-|392. Is Subsequence | [Go]({{< relref "/ChapterFour/0392.Is-Subsequence.md" >}})| Medium | O(n)| O(1)||
-|454. 4Sum II | [Go]({{< relref "/ChapterFour/0454.4Sum-II.md" >}})| Medium | O(n^2)| O(n) ||
-|710. Random Pick with Blacklist | [Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})| Hard | O(n)| O(n) ||
-|-----------------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Bit_Manipulation.md b/website/content/ChapterTwo/Bit_Manipulation.md
deleted file mode 100644
index 4dbc87050..000000000
--- a/website/content/ChapterTwo/Bit_Manipulation.md
+++ /dev/null
@@ -1,74 +0,0 @@
----
-title: Bit Manipulation
-type: docs
----
-
-# Bit Manipulation
-
-
-
-- 异或的特性。第 136 题,第 268 题,第 389 题,第 421 题,
-
-```go
-x ^ 0 = x
-x ^ 11111……1111 = ~x
-x ^ (~x) = 11111……1111
-x ^ x = 0
-a ^ b = c => a ^ c = b => b ^ c = a (交换律)
-a ^ b ^ c = a ^ (b ^ c) = (a ^ b)^ c (结合律)
-```
-
-- 构造特殊 Mask,将特殊位置放 0 或 1。
-
-```go
-将 x 最右边的 n 位清零, x & ( ~0 << n )
-获取 x 的第 n 位值(0 或者 1),(x >> n) & 1
-获取 x 的第 n 位的幂值,x & (1 << (n - 1))
-仅将第 n 位置为 1,x | (1 << n)
-仅将第 n 位置为 0,x & (~(1 << n))
-将 x 最高位至第 n 位(含)清零,x & ((1 << n) - 1)
-将第 n 位至第 0 位(含)清零,x & (~((1 << (n + 1)) - 1))
-```
-
-- 有特殊意义的 & 位操作运算。第 260 题,第 201 题,第 318 题,第 371 题,第 397 题,第 461 题,第 693 题,
-
-```go
-X & 1 == 1 判断是否是奇数(偶数)
-X & = (X - 1) 将最低位(LSB)的 1 清零
-X & -X 得到最低位(LSB)的 1
-X & ~X = 0
-```
-
-
-| Title | Solution | Difficulty | Time | Space | 收藏 |
-| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
-|78. Subsets | [Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|136. Single Number | [Go]({{< relref "/ChapterFour/0136.Single-Number.md" >}})| Easy | O(n)| O(1)||
-|137. Single Number II | [Go]({{< relref "/ChapterFour/0137.Single-Number-II.md" >}})| Medium | O(n)| O(1)|❤️|
-|169. Majority Element | [Go]({{< relref "/ChapterFour/0169.Majority-Element.md" >}})| Easy | O(n)| O(1)|❤️|
-|187. Repeated DNA Sequences | [Go]({{< relref "/ChapterFour/0187.Repeated-DNA-Sequences.md" >}})| Medium | O(n)| O(1)||
-|190. Reverse Bits | [Go]({{< relref "/ChapterFour/0190.Reverse-Bits.md" >}})| Easy | O(n)| O(1)|❤️|
-|191. Number of 1 Bits | [Go]({{< relref "/ChapterFour/0191.Number-of-1-Bits.md" >}})| Easy | O(n)| O(1)||
-|201. Bitwise AND of Numbers Range | [Go]({{< relref "/ChapterFour/0201.Bitwise-AND-of-Numbers-Range.md" >}})| Medium | O(n)| O(1)|❤️|
-|231. Power of Two | [Go]({{< relref "/ChapterFour/0231.Power-of-Two.md" >}})| Easy | O(1)| O(1)||
-|260. Single Number III | [Go]({{< relref "/ChapterFour/0260.Single-Number-III.md" >}})| Medium | O(n)| O(1)|❤️|
-|268. Missing Number | [Go]({{< relref "/ChapterFour/0268.Missing-Number.md" >}})| Easy | O(n)| O(1)||
-|318. Maximum Product of Word Lengths | [Go]({{< relref "/ChapterFour/0318.Maximum-Product-of-Word-Lengths.md" >}})| Medium | O(n)| O(1)||
-|338. Counting Bits | [Go]({{< relref "/ChapterFour/0338.Counting-Bits.md" >}})| Medium | O(n)| O(n)||
-|342. Power of Four | [Go]({{< relref "/ChapterFour/0342.Power-of-Four.md" >}})| Easy | O(n)| O(1)||
-|371. Sum of Two Integers | [Go]({{< relref "/ChapterFour/0371.Sum-of-Two-Integers.md" >}})| Easy | O(n)| O(1)||
-|389. Find the Difference | [Go]({{< relref "/ChapterFour/0389.Find-the-Difference.md" >}})| Easy | O(n)| O(1)||
-|393. UTF-8 Validation | [Go]({{< relref "/ChapterFour/0393.UTF-8-Validation.md" >}})| Medium | O(n)| O(1)||
-|397. Integer Replacement | [Go]({{< relref "/ChapterFour/0397.Integer-Replacement.md" >}})| Medium | O(n)| O(1)||
-|401. Binary Watch | [Go]({{< relref "/ChapterFour/0401.Binary-Watch.md" >}})| Easy | O(1)| O(1)||
-|405. Convert a Number to Hexadecimal | [Go]({{< relref "/ChapterFour/0405.Convert-a-Number-to-Hexadecimal.md" >}})| Easy | O(n)| O(1)||
-|421. Maximum XOR of Two Numbers in an Array | [Go]({{< relref "/ChapterFour/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md" >}})| Medium | O(n)| O(1)|❤️|
-|461. Hamming Distance | [Go]({{< relref "/ChapterFour/0461.Hamming-Distance.md" >}})| Easy | O(n)| O(1)||
-|476. Number Complement | [Go]({{< relref "/ChapterFour/0476.Number-Complement.md" >}})| Easy | O(n)| O(1)||
-|477. Total Hamming Distance | [Go]({{< relref "/ChapterFour/0477.Total-Hamming-Distance.md" >}})| Medium | O(n)| O(1)||
-|693. Binary Number with Alternating Bits | [Go]({{< relref "/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md" >}})| Easy | O(n)| O(1)|❤️|
-|756. Pyramid Transition Matrix | [Go]({{< relref "/ChapterFour/0756.Pyramid-Transition-Matrix.md" >}})| Medium | O(n log n)| O(n)||
-|762. Prime Number of Set Bits in Binary Representation | [Go]({{< relref "/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md" >}})| Easy | O(n)| O(1)||
-|784. Letter Case Permutation | [Go]({{< relref "/ChapterFour/0784.Letter-Case-Permutation.md" >}})| Easy | O(n)| O(1)||
-|898. Bitwise ORs of Subarrays | [Go]({{< relref "/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md" >}})| Medium | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Breadth_First_Search.md b/website/content/ChapterTwo/Breadth_First_Search.md
deleted file mode 100644
index f5ff7c731..000000000
--- a/website/content/ChapterTwo/Breadth_First_Search.md
+++ /dev/null
@@ -1,24 +0,0 @@
----
-title: Breadth First Search
-type: docs
----
-
-# Breadth First Search
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|101. Symmetric Tree | [Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})| Easy | O(n)| O(1)||
-|102. Binary Tree Level Order Traversal | [Go]({{< relref "/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md" >}})| Medium | O(n)| O(1)||
-|103. Binary Tree Zigzag Level Order Traversal | [Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})| Medium | O(n)| O(n)||
-|107. Binary Tree Level Order Traversal II | [Go]({{< relref "/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})| Easy | O(n)| O(1)||
-|111. Minimum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
-|127. Word Ladder | [Go]({{< relref "/ChapterFour/0127.Word-Ladder.md" >}})| Medium | O(n)| O(n)||
-|199. Binary Tree Right Side View | [Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})| Medium | O(n)| O(1)||
-|200. Number of Islands | [Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})| Medium | O(n^2)| O(n^2)||
-|207. Course Schedule | [Go]({{< relref "/ChapterFour/0207.Course-Schedule.md" >}})| Medium | O(n^2)| O(n^2)||
-|210. Course Schedule II | [Go]({{< relref "/ChapterFour/0210.Course-Schedule-II.md" >}})| Medium | O(n^2)| O(n^2)||
-|515. Find Largest Value in Each Tree Row | [Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})| Medium | O(n)| O(n)||
-|542. 01 Matrix | [Go]({{< relref "/ChapterFour/0542.01-Matrix.md" >}})| Medium | O(n)| O(1)||
-|993. Cousins in Binary Tree | [Go]({{< relref "/ChapterFour/0993.Cousins-in-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Depth_First_Search.md b/website/content/ChapterTwo/Depth_First_Search.md
deleted file mode 100644
index 41d8ac37e..000000000
--- a/website/content/ChapterTwo/Depth_First_Search.md
+++ /dev/null
@@ -1,33 +0,0 @@
----
-title: Depth First Search
-type: docs
----
-
-# Depth First Search
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|98. Validate Binary Search Tree | [Go]({{< relref "/ChapterFour/0098.Validate-Binary-Search-Tree.md" >}})| Medium | O(n)| O(1)||
-|99. Recover Binary Search Tree | [Go]({{< relref "/ChapterFour/0099.Recover-Binary-Search-Tree.md" >}})| Hard | O(n)| O(1)||
-|100. Same Tree | [Go]({{< relref "/ChapterFour/0100.Same-Tree.md" >}})| Easy | O(n)| O(1)||
-|101. Symmetric Tree | [Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})| Easy | O(n)| O(1)||
-|104. Maximum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|108. Convert Sorted Array to Binary Search Tree | [Go]({{< relref "/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})| Easy | O(n)| O(1)||
-|109. Convert Sorted List to Binary Search Tree | [Go]({{< relref "/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})| Medium | O(log n)| O(n)||
-|110. Balanced Binary Tree | [Go]({{< relref "/ChapterFour/0110.Balanced-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|111. Minimum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|112. Path Sum | [Go]({{< relref "/ChapterFour/0112.Path-Sum.md" >}})| Easy | O(n)| O(1)||
-|113. Path Sum II | [Go]({{< relref "/ChapterFour/0113.Path-Sum-II.md" >}})| Medium | O(n)| O(1)||
-|114. Flatten Binary Tree to Linked List | [Go]({{< relref "/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|124. Binary Tree Maximum Path Sum | [Go]({{< relref "/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md" >}})| Hard | O(n)| O(1)||
-|129. Sum Root to Leaf Numbers | [Go]({{< relref "/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md" >}})| Medium | O(n)| O(1)||
-|199. Binary Tree Right Side View | [Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})| Medium | O(n)| O(1)||
-|200. Number of Islands | [Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})| Medium | O(n^2)| O(n^2)||
-|207. Course Schedule | [Go]({{< relref "/ChapterFour/0207.Course-Schedule.md" >}})| Medium | O(n^2)| O(n^2)||
-|210. Course Schedule II | [Go]({{< relref "/ChapterFour/0210.Course-Schedule-II.md" >}})| Medium | O(n^2)| O(n^2)||
-|257. Binary Tree Paths | [Go]({{< relref "/ChapterFour/0257.Binary-Tree-Paths.md" >}})| Easy | O(n)| O(1)||
-|394. Decode String | [Go]({{< relref "/ChapterFour/0394.Decode-String.md" >}})| Medium | O(n)| O(n)||
-|515. Find Largest Value in Each Tree Row | [Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})| Medium | O(n)| O(n)||
-|542. 01 Matrix | [Go]({{< relref "/ChapterFour/0542.01-Matrix.md" >}})| Medium | O(n)| O(1)||
-|980. Unique Paths III | [Go]({{< relref "/ChapterFour/0980.Unique-Paths-III.md" >}})| Hard | O(n log n)| O(n)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Dynamic_Programming.md b/website/content/ChapterTwo/Dynamic_Programming.md
deleted file mode 100644
index 2baddaa93..000000000
--- a/website/content/ChapterTwo/Dynamic_Programming.md
+++ /dev/null
@@ -1,36 +0,0 @@
----
-title: Dynamic Programming
-type: docs
----
-
-# Dynamic Programming
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|53. Maximum Subarray| [Go]({{< relref "/ChapterFour/0053.Maximum-Subarray.md" >}})| Easy | O(n)| O(n)||
-|62. Unique Paths | [Go]({{< relref "/ChapterFour/0062.Unique-Paths.md" >}})| Medium | O(n^2)| O(n^2)||
-|63. Unique Paths II | [Go]({{< relref "/ChapterFour/0063.Unique-Paths-II.md" >}})| Medium | O(n^2)| O(n^2)||
-|64. Minimum Path Sum | [Go]({{< relref "/ChapterFour/0064.Minimum-Path-Sum.md" >}})| Medium | O(n^2)| O(n^2)||
-|70. Climbing Stairs | [Go]({{< relref "/ChapterFour/0070.Climbing-Stairs.md" >}})| Easy | O(n)| O(n)||
-|91. Decode Ways | [Go]({{< relref "/ChapterFour/0091.Decode-Ways.md" >}})| Medium | O(n)| O(n)||
-|96. Unique Binary Search Trees | [Go]({{< relref "/ChapterFour/0096.Unique-Binary-Search-Trees.md" >}})| Medium | O(n)| O(n)||
-|120. Triangle | [Go]({{< relref "/ChapterFour/0120.Triangle.md" >}})| Medium | O(n^2)| O(n)||
-|121. Best Time to Buy and Sell Stock | [Go]({{< relref "/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md" >}})| Easy | O(n)| O(1)||
-|152. Maximum Product Subarray | [Go]({{< relref "/ChapterFour/0152.Maximum-Product-Subarray.md" >}})| Medium | O(n)| O(1)||
-|198. House Robber | [Go]({{< relref "/ChapterFour/0198.House-Robber.md" >}})| Easy | O(n)| O(n)||
-|213. House Robber II | [Go]({{< relref "/ChapterFour/0213.House-Robber-II.md" >}})| Medium | O(n)| O(n)||
-|300. Longest Increasing Subsequence | [Go]({{< relref "/ChapterFour/0300.Longest-Increasing-Subsequence.md" >}})| Medium | O(n log n)| O(n)||
-|309. Best Time to Buy and Sell Stock with Cooldown | [Go]({{< relref "/ChapterFour/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown.md" >}})| Medium | O(n)| O(n)||
-|322. Coin Change | [Go]({{< relref "/ChapterFour/0322.Coin-Change.md" >}})| Medium | O(n)| O(n)||
-|338. Counting Bits | [Go]({{< relref "/ChapterFour/0338.Counting-Bits.md" >}})| Medium | O(n)| O(n)||
-|343. Integer Break | [Go]({{< relref "/ChapterFour/0343.Integer-Break.md" >}})| Medium | O(n^2)| O(n)||
-|357. Count Numbers with Unique Digits | [Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})| Medium | O(1)| O(1)||
-|392. Is Subsequence | [Go]({{< relref "/ChapterFour/0392.Is-Subsequence.md" >}})| Medium | O(n)| O(1)||
-|416. Partition Equal Subset Sum | [Go]({{< relref "/ChapterFour/0416.Partition-Equal-Subset-Sum.md" >}})| Medium | O(n^2)| O(n)||
-|714. Best Time to Buy and Sell Stock with Transaction Fee | [Go]({{< relref "/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md" >}})| Medium | O(n)| O(1)||
-|746. Min Cost Climbing Stairs | [Go]({{< relref "/ChapterFour/0746.Min-Cost-Climbing-Stairs.md" >}})| Easy | O(n)| O(1)||
-|838. Push Dominoes | [Go]({{< relref "/ChapterFour/0838.Push-Dominoes.md" >}})| Medium | O(n)| O(n)||
-|1025. Divisor Game | [Go]({{< relref "/ChapterFour/1025.Divisor-Game.md" >}})| Easy | O(1)| O(1)||
-|891. Sum of Subsequence Widths | [Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})| Hard | O(n log n)| O(1)||
-|942. DI String Match | [Go]({{< relref "/ChapterFour/0942.DI-String-Match.md" >}})| Easy | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Hash_Table.md b/website/content/ChapterTwo/Hash_Table.md
deleted file mode 100644
index ae4d23865..000000000
--- a/website/content/ChapterTwo/Hash_Table.md
+++ /dev/null
@@ -1,43 +0,0 @@
----
-title: Hash Table
-type: docs
----
-
-# Hash Table
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|1. Two Sum | [Go]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})| Easy | O(n)| O(n)||
-|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
-|18. 4Sum | [Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})| Medium | O(n^3)| O(n^2)|❤️|
-|30. Substring with Concatenation of All Words | [Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})| Hard | O(n)| O(n)|❤️|
-|36. Valid Sudoku | [Go]({{< relref "/ChapterFour/0036.Valid-Sudoku.md" >}})| Medium | O(n^2)| O(n^2)||
-|37. Sudoku Solver | [Go]({{< relref "/ChapterFour/0037.Sudoku-Solver.md" >}})| Hard | O(n^2)| O(n^2)|❤️|
-|49. Group Anagrams | [Go]({{< relref "/ChapterFour/0049.Group-Anagrams.md" >}})| Medium | O(n log n)| O(n)||
-|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
-|94. Binary Tree Inorder Traversal | [Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|138. Copy List with Random Pointer | [Go]()| Medium | O(n)| O(1)||
-|202. Happy Number | [Go]({{< relref "/ChapterFour/0202.Happy-Number.md" >}})| Easy | O(log n)| O(1)||
-|205. Isomorphic Strings | [Go]({{< relref "/ChapterFour/0205.Isomorphic-Strings.md" >}})| Easy | O(log n)| O(n)||
-|217. Contains Duplicate | [Go]({{< relref "/ChapterFour/0217.Contains-Duplicate.md" >}})| Easy | O(n)| O(n)||
-|219. Contains Duplicate II | [Go]({{< relref "/ChapterFour/0219.Contains-Duplicate-II.md" >}})| Easy | O(n)| O(n)||
-|242. Valid Anagram | [Go]({{< relref "/ChapterFour/0242.Valid-Anagram.md" >}})| Easy | O(n)| O(n) ||
-|274. H-Index | [Go]({{< relref "/ChapterFour/0274.H-Index.md" >}})| Medium | O(n)| O(n) ||
-|290. Word Pattern | [Go]({{< relref "/ChapterFour/0290.Word-Pattern.md" >}})| Easy | O(n)| O(n) ||
-|347. Top K Frequent Elements | [Go]({{< relref "/ChapterFour/0347.Top-K-Frequent-Elements.md" >}})| Medium | O(n)| O(n) ||
-|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
-|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
-|438. Find All Anagrams in a String | [Go]({{< relref "/ChapterFour/0438.Find-All-Anagrams-in-a-String.md" >}})| Easy | O(n)| O(1) ||
-|447. Number of Boomerangs | [Go]({{< relref "/ChapterFour/0447.Number-of-Boomerangs.md" >}})| Easy | O(n)| O(1) ||
-|451. Sort Characters By Frequency | [Go]({{< relref "/ChapterFour/0451.Sort-Characters-By-Frequency.md" >}})| Medium | O(n log n)| O(1) ||
-|454. 4Sum II | [Go]({{< relref "/ChapterFour/0454.4Sum-II.md" >}})| Medium | O(n^2)| O(n) ||
-|648. Replace Words | [Go]({{< relref "/ChapterFour/0648.Replace-Words.md" >}})| Medium | O(n)| O(n) ||
-|676. Implement Magic Dictionary | [Go]({{< relref "/ChapterFour/0676.Implement-Magic-Dictionary.md" >}})| Medium | O(n)| O(n) ||
-|720. Longest Word in Dictionary | [Go]({{< relref "/ChapterFour/0720.Longest-Word-in-Dictionary.md" >}})| Easy | O(n)| O(n) ||
-|726. Number of Atoms | [Go]({{< relref "/ChapterFour/0726.Number-of-Atoms.md" >}})| Hard | O(n)| O(n) |❤️|
-|739. Daily Temperatures | [Go]({{< relref "/ChapterFour/0739.Daily-Temperatures.md" >}})| Medium | O(n)| O(n) ||
-|710. Random Pick with Blacklist | [Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})| Hard | O(n)| O(n) ||
-|895. Maximum Frequency Stack | [Go]({{< relref "/ChapterFour/0895.Maximum-Frequency-Stack.md" >}})| Hard | O(n)| O(n) ||
-|930. Binary Subarrays With Sum | [Go]({{< relref "/ChapterFour/0930.Binary-Subarrays-With-Sum.md" >}})| Medium | O(n)| O(n) |❤️|
-|992. Subarrays with K Different Integers | [Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})| Hard | O(n)| O(n) |❤️|
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Linked_List.md b/website/content/ChapterTwo/Linked_List.md
deleted file mode 100644
index d786f4665..000000000
--- a/website/content/ChapterTwo/Linked_List.md
+++ /dev/null
@@ -1,53 +0,0 @@
----
-title: Linked List
-type: docs
----
-
-# Linked List
-
-
-
-
-- 巧妙的构造虚拟头结点。可以使遍历处理逻辑更加统一。
-- 灵活使用递归。构造递归条件,使用递归可以巧妙的解题。不过需要注意有些题目不能使用递归,因为递归深度太深会导致超时和栈溢出。
-- 链表区间逆序。第 92 题。
-- 链表寻找中间节点。第 876 题。链表寻找倒数第 n 个节点。第 19 题。只需要一次遍历就可以得到答案。
-- 合并 K 个有序链表。第 21 题,第 23 题。
-- 链表归类。第 86 题,第 328 题。
-- 链表排序,时间复杂度要求 O(n * log n),空间复杂度 O(1)。只有一种做法,归并排序,至顶向下归并。第 148 题。
-- 判断链表是否存在环,如果有环,输出环的交叉点的下标;判断 2 个链表是否有交叉点,如果有交叉点,输出交叉点。第 141 题,第 142 题,第 160 题。
-
-
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|2. Add Two Numbers | [Go]({{< relref "/ChapterFour/0002.Add-Two-Numbers.md" >}})| Medium | O(n)| O(1)||
-|19. Remove Nth Node From End of List | [Go]({{< relref "/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md" >}})| Medium | O(n)| O(1)||
-|21. Merge Two Sorted Lists | [Go]({{< relref "/ChapterFour/0021.Merge-Two-Sorted-Lists.md" >}})| Easy | O(log n)| O(1)||
-|23. Merge k Sorted Lists| [Go]({{< relref "/ChapterFour/0023.Merge-k-Sorted-Lists.md" >}})| Hard | O(log n)| O(1)|❤️|
-|24. Swap Nodes in Pairs | [Go]({{< relref "/ChapterFour/0024.Swap-Nodes-in-Pairs.md" >}})| Medium | O(n)| O(1)||
-|25. Reverse Nodes in k-Group | [Go]({{< relref "/ChapterFour/0025.Reverse-Nodes-in-k-Group.md" >}})| Hard | O(log n)| O(1)|❤️|
-|61. Rotate List | [Go]({{< relref "/ChapterFour/0061.Rotate-List.md" >}})| Medium | O(n)| O(1)||
-|82. Remove Duplicates from Sorted List II | [Go]({{< relref "/ChapterFour/0082.Remove-Duplicates-from-Sorted-List-II.md" >}})| Medium | O(n)| O(1)||
-|83. Remove Duplicates from Sorted List | [Go]({{< relref "/ChapterFour/0083.Remove-Duplicates-from-Sorted-List.md" >}})| Easy | O(n)| O(1)||
-|86. Partition List | [Go]({{< relref "/ChapterFour/0086.Partition-List.md" >}})| Medium | O(n)| O(1)|❤️|
-|92. Reverse Linked List II | [Go]({{< relref "/ChapterFour/0092.Reverse-Linked-List-II.md" >}})| Medium | O(n)| O(1)|❤️|
-|109. Convert Sorted List to Binary Search Tree | [Go]({{< relref "/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})| Medium | O(log n)| O(n)||
-|141. Linked List Cycle | [Go]({{< relref "/ChapterFour/0141.Linked-List-Cycle.md" >}})| Easy | O(n)| O(1)|❤️|
-|142. Linked List Cycle II | [Go]({{< relref "/ChapterFour/0142.Linked-List-Cycle-II.md" >}})| Medium | O(n)| O(1)|❤️|
-|143. Reorder List | [Go]({{< relref "/ChapterFour/0143.Reorder-List.md" >}})| Medium | O(n)| O(1)|❤️|
-|147. Insertion Sort List | [Go]({{< relref "/ChapterFour/0147.Insertion-Sort-List.md" >}})| Medium | O(n)| O(1)|❤️|
-|148. Sort List | [Go]({{< relref "/ChapterFour/0148.Sort-List.md" >}})| Medium | O(n log n)| O(n)|❤️|
-|160. Intersection of Two Linked Lists | [Go]({{< relref "/ChapterFour/0160.Intersection-of-Two-Linked-Lists.md" >}})| Easy | O(n)| O(1)|❤️|
-|203. Remove Linked List Elements | [Go]({{< relref "/ChapterFour/0203.Remove-Linked-List-Elements.md" >}})| Easy | O(n)| O(1)||
-|206. Reverse Linked List | [Go]({{< relref "/ChapterFour/0206.Reverse-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|234. Palindrome Linked List | [Go]({{< relref "/ChapterFour/0234.Palindrome-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|237. Delete Node in a Linked List | [Go]({{< relref "/ChapterFour/0237.Delete-Node-in-a-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|328. Odd Even Linked List | [Go]({{< relref "/ChapterFour/0328.Odd-Even-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|445. Add Two Numbers II | [Go]({{< relref "/ChapterFour/0445.Add-Two-Numbers-II.md" >}})| Medium | O(n)| O(n)||
-|725. Split Linked List in Parts | [Go]({{< relref "/ChapterFour/0725.Split-Linked-List-in-Parts.md" >}})| Medium | O(n)| O(1)||
-|817. Linked List Components | [Go]({{< relref "/ChapterFour/0817.Linked-List-Components.md" >}})| Medium | O(n)| O(1)||
-|707. Design Linked List | [Go]({{< relref "/ChapterFour/0707.Design-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|876. Middle of the Linked List | [Go]({{< relref "/ChapterFour/0876.Middle-of-the-Linked-List.md" >}})| Easy | O(n)| O(1)|❤️|
-|1019. Next Greater Node In Linked List | [Go]({{< relref "/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|---------------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Math.md b/website/content/ChapterTwo/Math.md
deleted file mode 100644
index b20da7a36..000000000
--- a/website/content/ChapterTwo/Math.md
+++ /dev/null
@@ -1,28 +0,0 @@
----
-title: Math
-type: docs
----
-
-# Math
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|2. Add Two Numbers | [Go]({{< relref "/ChapterFour/0002.Add-Two-Numbers.md" >}})| Medium | O(n)| O(1)||
-|50. Pow(x, n) | [Go]({{< relref "/ChapterFour/0050.Powx-n.md" >}})| Medium | O(log n)| O(1)||
-|60. Permutation Sequence | [Go]({{< relref "/ChapterFour/0060.Permutation-Sequence.md" >}})| Medium | O(n log n)| O(1)||
-|69. Sqrt(x) | [Go]({{< relref "/ChapterFour/0069.Sqrtx.md" >}})| Easy | O(log n)| O(1)||
-|202. Happy Number | [Go]({{< relref "/ChapterFour/0202.Happy-Number.md" >}})| Easy | O(log n)| O(1)||
-|224. Basic Calculator | [Go]({{< relref "/ChapterFour/0224.Basic-Calculator.md" >}})| Hard | O(n)| O(n)||
-|231. Power of Two | [Go]({{< relref "/ChapterFour/0231.Power-of-Two.md" >}})| Easy | O(1)| O(1)||
-|263. Ugly Number | [Go]({{< relref "/ChapterFour/0263.Ugly-Number.md" >}})| Easy | O(log n)| O(1)||
-|326. Power of Three | [Go]({{< relref "/ChapterFour/0326.Power-of-Three.md" >}})| Easy | O(1)| O(1)||
-|343. Integer Break | [Go]({{< relref "/ChapterFour/0343.Integer-Break.md" >}})| Medium | O(n^2)| O(n)||
-|357. Count Numbers with Unique Digits | [Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})| Medium | O(1)| O(1)||
-|628. Maximum Product of Three Numbers | [Go]({{< relref "/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md" >}})| Easy | O(n)| O(1)||
-|885. Spiral Matrix III | [Go]({{< relref "/ChapterFour/0885.Spiral-Matrix-III.md" >}})| Medium | O(n^2)| O(1)||
-|891. Sum of Subsequence Widths | [Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})| Hard | O(n log n)| O(1)||
-|942. DI String Match | [Go]({{< relref "/ChapterFour/0942.DI-String-Match.md" >}})| Easy | O(n)| O(1)||
-|976. Largest Perimeter Triangle | [Go]({{< relref "/ChapterFour/0976.Largest-Perimeter-Triangle.md" >}})| Easy | O(n log n)| O(log n) ||
-|996. Number of Squareful Arrays | [Go]({{< relref "/ChapterFour/0996.Number-of-Squareful-Arrays.md" >}})| Hard | O(n log n)| O(n) ||
-|1025. Divisor Game | [Go]({{< relref "/ChapterFour/1025.Divisor-Game.md" >}})| Easy | O(1)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Sliding_Window.md b/website/content/ChapterTwo/Sliding_Window.md
deleted file mode 100644
index 2ffd90d7e..000000000
--- a/website/content/ChapterTwo/Sliding_Window.md
+++ /dev/null
@@ -1,43 +0,0 @@
----
-title: Sliding Window
-type: docs
----
-
-# Sliding Window
-
-
-
-- 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 3 题,第 76 题,第 209 题,第 424 题,第 438 题,第 567 题,第 713 题,第 763 题,第 845 题,第 881 题,第 904 题,第 978 题,第 992 题,第 1004 题,第 1040 题,第 1052 题。
-
-```c
- left, right := 0, -1
-
- for left < len(s) {
- if right+1 < len(s) && freq[s[right+1]-'a'] == 0 {
- freq[s[right+1]-'a']++
- right++
- } else {
- freq[s[left]-'a']--
- left++
- }
- result = max(result, right-left+1)
- }
-```
-- 滑动窗口经典题。第 239 题,第 480 题。
-
-| Title | Solution | Difficulty | Time | Space | 收藏 |
-| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
-|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
-|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
-|239. Sliding Window Maximum | [Go]({{< relref "/ChapterFour/0239.Sliding-Window-Maximum.md" >}})| Hard | O(n * k)| O(n)|❤️|
-|424. Longest Repeating Character Replacement | [Go]({{< relref "/ChapterFour/0424.Longest-Repeating-Character-Replacement.md" >}})| Medium | O(n)| O(1) ||
-|480. Sliding Window Median | [Go]({{< relref "/ChapterFour/0480.Sliding-Window-Median.md" >}})| Hard | O(n * log k)| O(k)|❤️|
-|567. Permutation in String | [Go]({{< relref "/ChapterFour/0567.Permutation-in-String.md" >}})| Medium | O(n)| O(1)|❤️|
-|978. Longest Turbulent Subarray | [Go]({{< relref "/ChapterFour/0978.Longest-Turbulent-Subarray.md" >}})| Medium | O(n)| O(1)|❤️|
-|992. Subarrays with K Different Integers | [Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})| Hard | O(n)| O(n)|❤️|
-|995. Minimum Number of K Consecutive Bit Flips | [Go]({{< relref "/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md" >}})| Hard | O(n)| O(1)|❤️|
-|1004. Max Consecutive Ones III | [Go]({{< relref "/ChapterFour/1004.Max-Consecutive-Ones-III.md" >}})| Medium | O(n)| O(1) ||
-|1040. Moving Stones Until Consecutive II | [Go]({{< relref "/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md" >}})| Medium | O(n log n)| O(1) |❤️|
-|1052. Grumpy Bookstore Owner | [Go]({{< relref "/ChapterFour/1052.Grumpy-Bookstore-Owner.md" >}})| Medium | O(n log n)| O(1) ||
-|1074. Number of Submatrices That Sum to Target | [Go]({{< relref "/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md" >}})| Hard | O(n^3)| O(n) |❤️|
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Sort.md b/website/content/ChapterTwo/Sort.md
deleted file mode 100644
index f759edf86..000000000
--- a/website/content/ChapterTwo/Sort.md
+++ /dev/null
@@ -1,42 +0,0 @@
----
-title: Sort
-type: docs
----
-
-# Sort
-
-
-
-- 深刻的理解多路快排。第 75 题。
-- 链表的排序,插入排序(第 147 题)和归并排序(第 148 题)
-- 桶排序和基数排序。第 164 题。
-- "摆动排序"。第 324 题。
-- 两两不相邻的排序。第 767 题,第 1054 题。
-- "饼子排序"。第 969 题。
-
-| Title | Solution | Difficulty | Time | Space | 收藏 |
-| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
-|56. Merge Intervals | [Go]({{< relref "/ChapterFour/0056.Merge-Intervals.md" >}})| Medium | O(n log n)| O(log n)||
-|57. Insert Interval | [Go]({{< relref "/ChapterFour/0057.Insert-Interval.md" >}})| Hard | O(n)| O(1)||
-|75. Sort Colors | [Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})| Medium| O(n)| O(1)|❤️|
-|147. Insertion Sort List | [Go]({{< relref "/ChapterFour/0147.Insertion-Sort-List.md" >}})| Medium | O(n)| O(1) |❤️|
-|148. Sort List | [Go]({{< relref "/ChapterFour/0148.Sort-List.md" >}})| Medium |O(n log n)| O(log n)|❤️|
-|164. Maximum Gap | [Go]({{< relref "/ChapterFour/0164.Maximum-Gap.md" >}})| Hard | O(n log n)| O(log n) |❤️|
-|179. Largest Number | [Go]({{< relref "/ChapterFour/0179.Largest-Number.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|220. Contains Duplicate III | [Go]({{< relref "/ChapterFour/0220.Contains-Duplicate-III.md" >}})| Medium | O(n log n)| O(1) |❤️|
-|242. Valid Anagram | [Go]({{< relref "/ChapterFour/0242.Valid-Anagram.md" >}})| Easy | O(n)| O(n) ||
-|274. H-Index | [Go]({{< relref "/ChapterFour/0274.H-Index.md" >}})| Medium | O(n)| O(n) ||
-|324. Wiggle Sort II | [Go]({{< relref "/ChapterFour/0324.Wiggle-Sort-II.md" >}})| Medium| O(n)| O(n)|❤️|
-|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
-|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
-|524. Longest Word in Dictionary through Deleting | [Go]({{< relref "/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})| Medium | O(n)| O(1) ||
-|767. Reorganize String | [Go]({{< relref "/ChapterFour/0767.Reorganize-String.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|853. Car Fleet | [Go]({{< relref "/ChapterFour/0853.Car-Fleet.md" >}})| Medium | O(n log n)| O(log n) ||
-|710. Random Pick with Blacklist | [Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})| Hard | O(n)| O(n) ||
-|922. Sort Array By Parity II | [Go]({{< relref "/ChapterFour/0922.Sort-Array-By-Parity-II.md" >}})| Easy | O(n)| O(1) ||
-|969. Pancake Sorting | [Go]({{< relref "/ChapterFour/0969.Pancake-Sorting.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|973. K Closest Points to Origin | [Go]({{< relref "/ChapterFour/0973.K-Closest-Points-to-Origin.md" >}})| Medium | O(n log n)| O(log n) ||
-|976. Largest Perimeter Triangle | [Go]({{< relref "/ChapterFour/0976.Largest-Perimeter-Triangle.md" >}})| Easy | O(n log n)| O(log n) ||
-|1030. Matrix Cells in Distance Order | [Go]({{< relref "/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md" >}})| Easy | O(n^2)| O(1) ||
-|1054. Distant Barcodes | [Go]({{< relref "/ChapterFour/1054.Distant-Barcodes.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Stack.md b/website/content/ChapterTwo/Stack.md
deleted file mode 100644
index cae1b29c9..000000000
--- a/website/content/ChapterTwo/Stack.md
+++ /dev/null
@@ -1,54 +0,0 @@
----
-title: Stack
-type: docs
----
-
-# Stack
-
-
-
-- 括号匹配问题及类似问题。第 20 题,第 921 题,第 1021 题。
-- 栈的基本 pop 和 push 操作。第 71 题,第 150 题,第 155 题,第 224 题,第 225 题,第 232 题,第 946 题,第 1047 题。
-- 利用栈进行编码问题。第 394 题,第 682 题,第 856 题,第 880 题。
-- **单调栈**。**利用栈维护一个单调递增或者递减的下标数组**。第 84 题,第 456 题,第 496 题,第 503 题,第 739 题,第 901 题,第 907 题,第 1019 题。
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|20. Valid Parentheses | [Go]({{< relref "/ChapterFour/0020.Valid-Parentheses.md" >}})| Easy | O(log n)| O(1)||
-|42. Trapping Rain Water | [Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})| Hard | O(n)| O(1)|❤️|
-|71. Simplify Path | [Go]({{< relref "/ChapterFour/0071.Simplify-Path.md" >}})| Medium | O(n)| O(n)|❤️|
-|84. Largest Rectangle in Histogram | [Go]({{< relref "/ChapterFour/0084.Largest-Rectangle-in-Histogram.md" >}})| Medium | O(n)| O(n)|❤️|
-|94. Binary Tree Inorder Traversal | [Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|103. Binary Tree Zigzag Level Order Traversal | [Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})| Medium | O(n)| O(n)||
-|144. Binary Tree Preorder Traversal | [Go]({{< relref "/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|145. Binary Tree Postorder Traversal | [Go]({{< relref "/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md" >}})| Hard | O(n)| O(1)||
-|150. Evaluate Reverse Polish Notation | [Go]({{< relref "/ChapterFour/0150.Evaluate-Reverse-Polish-Notation.md" >}})| Medium | O(n)| O(1)||
-|155. Min Stack | [Go]({{< relref "/ChapterFour/0155.Min-Stack.md" >}})| Easy | O(n)| O(n)||
-|173. Binary Search Tree Iterator | [Go]({{< relref "/ChapterFour/0173.Binary-Search-Tree-Iterator.md" >}})| Medium | O(n)| O(1)||
-|224. Basic Calculator | [Go]({{< relref "/ChapterFour/0224.Basic-Calculator.md" >}})| Hard | O(n)| O(n)||
-|225. Implement Stack using Queues | [Go]({{< relref "/ChapterFour/0225.Implement-Stack-using-Queues.md" >}})| Easy | O(n)| O(n)||
-|232. Implement Queue using Stacks | [Go]({{< relref "/ChapterFour/0232.Implement-Queue-using-Stacks.md" >}})| Easy | O(n)| O(n)||
-|331. Verify Preorder Serialization of a Binary Tree | [Go]({{< relref "/ChapterFour/0331.Verify-Preorder-Serialization-of-a-Binary-Tree.md" >}})| Medium | O(n)| O(1)||
-|394. Decode String | [Go]({{< relref "/ChapterFour/0394.Decode-String.md" >}})| Medium | O(n)| O(n)||
-|402. Remove K Digits | [Go]({{< relref "/ChapterFour/0402.Remove-K-Digits.md" >}})| Medium | O(n)| O(1)||
-|456. 132 Pattern | [Go]({{< relref "/ChapterFour/0456.132-Pattern.md" >}})| Medium | O(n)| O(n)||
-|496. Next Greater Element I | [Go]({{< relref "/ChapterFour/0496.Next-Greater-Element-I.md" >}})| Easy | O(n)| O(n)||
-|503. Next Greater Element II | [Go]({{< relref "/ChapterFour/0503.Next-Greater-Element-II.md" >}})| Medium | O(n)| O(n)||
-|636. Exclusive Time of Functions | [Go]({{< relref "/ChapterFour/0636.Exclusive-Time-of-Functions.md" >}})| Medium | O(n)| O(n)||
-|682. Baseball Game | [Go]({{< relref "/ChapterFour/0682.Baseball-Game.md" >}})| Easy | O(n)| O(n)||
-|726. Number of Atoms | [Go]({{< relref "/ChapterFour/0726.Number-of-Atoms.md" >}})| Hard | O(n)| O(n) |❤️|
-|735. Asteroid Collision | [Go]({{< relref "/ChapterFour/0735.Asteroid-Collision.md" >}})| Medium | O(n)| O(n) ||
-|739. Daily Temperatures | [Go]({{< relref "/ChapterFour/0739.Daily-Temperatures.md" >}})| Medium | O(n)| O(n) ||
-|844. Backspace String Compare | [Go]({{< relref "/ChapterFour/0844.Backspace-String-Compare.md" >}})| Easy | O(n)| O(n) ||
-|856. Score of Parentheses | [Go]({{< relref "/ChapterFour/0856.Score-of-Parentheses.md" >}})| Medium | O(n)| O(n)||
-|880. Decoded String at Index | [Go]({{< relref "/ChapterFour/0880.Decoded-String-at-Index.md" >}})| Medium | O(n)| O(n)||
-|895. Maximum Frequency Stack | [Go]({{< relref "/ChapterFour/0895.Maximum-Frequency-Stack.md" >}})| Hard | O(n)| O(n) ||
-|901. Online Stock Span | [Go]({{< relref "/ChapterFour/0901.Online-Stock-Span.md" >}})| Medium | O(n)| O(n) ||
-|907. Sum of Subarray Minimums | [Go]({{< relref "/ChapterFour/0907.Sum-of-Subarray-Minimums.md" >}})| Medium | O(n)| O(n)|❤️|
-|921. Minimum Add to Make Parentheses Valid | [Go]({{< relref "/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md" >}})| Medium | O(n)| O(n)||
-|946. Validate Stack Sequences | [Go]({{< relref "/ChapterFour/0946.Validate-Stack-Sequences.md" >}})| Medium | O(n)| O(n)||
-|1003. Check If Word Is Valid After Substitutions | [Go]({{< relref "/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md" >}})| Medium | O(n)| O(1)||
-|1019. Next Greater Node In Linked List | [Go]({{< relref "/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|1021. Remove Outermost Parentheses | [Go]({{< relref "/ChapterFour/1021.Remove-Outermost-Parentheses.md" >}})| Medium | O(n)| O(1)||
-|1047. Remove All Adjacent Duplicates In String | [Go]({{< relref "/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md" >}})| Medium | O(n)| O(1)||
-|---------------------------------------|-----------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/String.md b/website/content/ChapterTwo/String.md
deleted file mode 100644
index 1ea29de57..000000000
--- a/website/content/ChapterTwo/String.md
+++ /dev/null
@@ -1,30 +0,0 @@
----
-title: String
-type: docs
----
-
-# String
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
-|17. Letter Combinations of a Phone Number | [Go]({{< relref "/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md" >}})| Medium | O(log n)| O(1)||
-|20. Valid Parentheses | [Go]({{< relref "/ChapterFour/0020.Valid-Parentheses.md" >}})| Easy | O(log n)| O(1)||
-|22. Generate Parentheses | [Go]({{< relref "/ChapterFour/0022.Generate-Parentheses.md" >}})| Medium | O(log n)| O(1)||
-|28. Implement strStr() | [Go]({{< relref "/ChapterFour/0028.Implement-strStr.md" >}})| Easy | O(n)| O(1)||
-|30. Substring with Concatenation of All Words | [Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})| Hard | O(n)| O(n)|❤️|
-|49. Group Anagrams | [Go]({{< relref "/ChapterFour/0049.Group-Anagrams.md" >}})| Medium | O(n log n)| O(n)||
-|71. Simplify Path | [Go]({{< relref "/ChapterFour/0071.Simplify-Path.md" >}})| Medium | O(n)| O(n)||
-|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
-|91. Decode Ways | [Go]({{< relref "/ChapterFour/0091.Decode-Ways.md" >}})| Medium | O(n)| O(n)||
-|93. Restore IP Addresses | [Go]({{< relref "/ChapterFour/0093.Restore-IP-Addresses.md" >}})| Medium | O(n)| O(n)|❤️|
-|125. Valid Palindrome | [Go]({{< relref "/ChapterFour/0125.Valid-Palindrome.md" >}})| Easy | O(n)| O(1)||
-|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
-|344. Reverse String | [Go]({{< relref "/ChapterFour/0344.Reverse-String.md" >}})| Easy | O(n)| O(1)||
-|345. Reverse Vowels of a String | [Go]({{< relref "/ChapterFour/0345.Reverse-Vowels-of-a-String.md" >}})| Easy | O(n)| O(1)||
-|767. Reorganize String | [Go]({{< relref "/ChapterFour/0767.Reorganize-String.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|842. Split Array into Fibonacci Sequence | [Go]({{< relref "/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|856. Score of Parentheses | [Go]({{< relref "/ChapterFour/0856.Score-of-Parentheses.md" >}})| Medium | O(n)| O(n)||
-|925. Long Pressed Name | [Go]({{< relref "/ChapterFour/0925.Long-Pressed-Name.md" >}})| Easy | O(n)| O(1)||
-|1003. Check If Word Is Valid After Substitutions | [Go]({{< relref "/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md" >}})| Medium | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Tree.md b/website/content/ChapterTwo/Tree.md
deleted file mode 100644
index d8a1267e5..000000000
--- a/website/content/ChapterTwo/Tree.md
+++ /dev/null
@@ -1,43 +0,0 @@
----
-title: Tree
-type: docs
----
-
-# Tree
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|94. Binary Tree Inorder Traversal | [Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|96. Unique Binary Search Trees | [Go]({{< relref "/ChapterFour/0096.Unique-Binary-Search-Trees.md" >}})| Medium | O(n^2)| O(n)||
-|98. Validate Binary Search Tree | [Go]({{< relref "/ChapterFour/0098.Validate-Binary-Search-Tree.md" >}})| Medium | O(n)| O(1)||
-|99. Recover Binary Search Tree | [Go]({{< relref "/ChapterFour/0099.Recover-Binary-Search-Tree.md" >}})| Hard | O(n)| O(1)||
-|100. Same Tree | [Go]({{< relref "/ChapterFour/0100.Same-Tree.md" >}})| Easy | O(n)| O(1)||
-|101. Symmetric Tree | [Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})| Easy | O(n)| O(1)||
-|102. Binary Tree Level Order Traversal | [Go]({{< relref "/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md" >}})| Medium | O(n)| O(1)||
-|103. Binary Tree Zigzag Level Order Traversal | [Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})| Medium | O(n)| O(n)||
-|104. Maximum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|107. Binary Tree Level Order Traversal II | [Go]({{< relref "/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})| Easy | O(n)| O(1)||
-|108. Convert Sorted Array to Binary Search Tree | [Go]({{< relref "/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})| Easy | O(n)| O(1)||
-|110. Balanced Binary Tree | [Go]({{< relref "/ChapterFour/0110.Balanced-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|111. Minimum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|112. Path Sum | [Go]({{< relref "/ChapterFour/0112.Path-Sum.md" >}})| Easy | O(n)| O(1)||
-|113. Path Sum II | [Go]({{< relref "/ChapterFour/0113.Path-Sum-II.md" >}})| Medium | O(n)| O(1)||
-|114. Flatten Binary Tree to Linked List | [Go]({{< relref "/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|124. Binary Tree Maximum Path Sum | [Go]({{< relref "/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md" >}})| Hard | O(n)| O(1)||
-|129. Sum Root to Leaf Numbers | [Go]({{< relref "/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md" >}})| Medium | O(n)| O(1)||
-|144. Binary Tree Preorder Traversal | [Go]({{< relref "/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|145. Binary Tree Postorder Traversal | [Go]({{< relref "/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md" >}})| Hard | O(n)| O(1)||
-|173. Binary Search Tree Iterator | [Go]({{< relref "/ChapterFour/0173.Binary-Search-Tree-Iterator.md" >}})| Medium | O(n)| O(1)||
-|199. Binary Tree Right Side View | [Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})| Medium | O(n)| O(1)||
-|222. Count Complete Tree Nodes | [Go]({{< relref "/ChapterFour/0222.Count-Complete-Tree-Nodes.md" >}})| Medium | O(n)| O(1)||
-|226. Invert Binary Tree | [Go]({{< relref "/ChapterFour/0226.Invert-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|230. Kth Smallest Element in a BST | [Go]({{< relref "/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md" >}})| Medium | O(n)| O(1)||
-|235. Lowest Common Ancestor of a Binary Search Tree | [Go]({{< relref "/ChapterFour/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md" >}})| Easy | O(n)| O(1)||
-|236. Lowest Common Ancestor of a Binary Tree | [Go]({{< relref "/ChapterFour/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md" >}})| Medium | O(n)| O(1)||
-|257. Binary Tree Paths | [Go]({{< relref "/ChapterFour/0257.Binary-Tree-Paths.md" >}})| Easy | O(n)| O(1)||
-|404. Sum of Left Leaves | [Go]({{< relref "/ChapterFour/0404.Sum-of-Left-Leaves.md" >}})| Easy | O(n)| O(1)||
-|437. Path Sum III | [Go]({{< relref "/ChapterFour/0437.Path-Sum-III.md" >}})| Easy | O(n)| O(1)||
-|515. Find Largest Value in Each Tree Row | [Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})| Medium | O(n)| O(n)||
-|637. Average of Levels in Binary Tree | [Go]({{< relref "/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md" >}})| Easy | O(n)| O(n)||
-|993. Cousins in Binary Tree | [Go]({{< relref "/ChapterFour/0993.Cousins-in-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Two_Pointers.md b/website/content/ChapterTwo/Two_Pointers.md
deleted file mode 100644
index ece49e88d..000000000
--- a/website/content/ChapterTwo/Two_Pointers.md
+++ /dev/null
@@ -1,83 +0,0 @@
----
-title: Two Pointers
-type: docs
----
-
-# Two Pointers
-
-
-
-- 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 3 题,第 76 题,第 209 题,第 424 题,第 438 题,第 567 题,第 713 题,第 763 题,第 845 题,第 881 题,第 904 题,第 978 题,第 992 题,第 1004 题,第 1040 题,第 1052 题。
-
-```c
- left, right := 0, -1
-
- for left < len(s) {
- if right+1 < len(s) && freq[s[right+1]-'a'] == 0 {
- freq[s[right+1]-'a']++
- right++
- } else {
- freq[s[left]-'a']--
- left++
- }
- result = max(result, right-left+1)
- }
-```
-
-- 快慢指针可以查找重复数字,时间复杂度 O(n),第 287 题。
-- 替换字母以后,相同字母能出现连续最长的长度。第 424 题。
-- SUM 问题集。第 1 题,第 15 题,第 16 题,第 18 题,第 167 题,第 923 题,第 1074 题。
-
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
-|11. Container With Most Water | [Go]({{< relref "/ChapterFour/0011.Container-With-Most-Water.md" >}})| Medium | O(n)| O(1)||
-|15. 3Sum | [Go]({{< relref "/ChapterFour/0015.3Sum.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|16. 3Sum Closest | [Go]({{< relref "/ChapterFour/0016.3Sum-Closest.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|18. 4Sum | [Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})| Medium | O(n^3)| O(n^2)|❤️|
-|19. Remove Nth Node From End of List | [Go]({{< relref "/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md" >}})| Medium | O(n)| O(1)||
-|26. Remove Duplicates from Sorted Array | [Go]({{< relref "/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
-|27. Remove Element | [Go]({{< relref "/ChapterFour/0027.Remove-Element.md" >}})| Easy | O(n)| O(1)||
-|28. Implement strStr() | [Go]({{< relref "/ChapterFour/0028.Implement-strStr.md" >}})| Easy | O(n)| O(1)||
-|30. Substring with Concatenation of All Words | [Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})| Hard | O(n)| O(n)|❤️|
-|42. Trapping Rain Water | [Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})| Hard | O(n)| O(1)|❤️|
-|61. Rotate List | [Go]({{< relref "/ChapterFour/0061.Rotate-List.md" >}})| Medium | O(n)| O(1)||
-|75. Sort Colors | [Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})| Medium| O(n)| O(1)|❤️|
-|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
-|80. Remove Duplicates from Sorted Array II | [Go]({{< relref "/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md" >}})| Medium | O(n)| O(1||
-|86. Partition List | [Go]({{< relref "/ChapterFour/0086.Partition-List.md" >}})| Medium | O(n)| O(1)|❤️|
-|88. Merge Sorted Array | [Go]({{< relref "/ChapterFour/0088.Merge-Sorted-Array.md" >}})| Easy | O(n)| O(1)|❤️|
-|125. Valid Palindrome | [Go]({{< relref "/ChapterFour/0125.Valid-Palindrome.md" >}})| Easy | O(n)| O(1)||
-|141. Linked List Cycle | [Go]({{< relref "/ChapterFour/0141.Linked-List-Cycle.md" >}})| Easy | O(n)| O(1)|❤️|
-|142. Linked List Cycle II | [Go]({{< relref "/ChapterFour/0142.Linked-List-Cycle-II.md" >}})| Medium | O(n)| O(1)|❤️|
-|167. Two Sum II - Input array is sorted | [Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})| Easy | O(n)| O(1)||
-|209. Minimum Size Subarray Sum | [Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})| Medium | O(n)| O(1)||
-|234. Palindrome Linked List | [Go]({{< relref "/ChapterFour/0234.Palindrome-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|283. Move Zeroes | [Go]({{< relref "/ChapterFour/0283.Move-Zeroes.md" >}})| Easy | O(n)| O(1)||
-|287. Find the Duplicate Number | [Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})| Easy | O(n)| O(1)|❤️|
-|344. Reverse String | [Go]({{< relref "/ChapterFour/0344.Reverse-String.md" >}})| Easy | O(n)| O(1)||
-|345. Reverse Vowels of a String | [Go]({{< relref "/ChapterFour/0345.Reverse-Vowels-of-a-String.md" >}})| Easy | O(n)| O(1)||
-|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
-|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
-|424. Longest Repeating Character Replacement | [Go]({{< relref "/ChapterFour/0424.Longest-Repeating-Character-Replacement.md" >}})| Medium | O(n)| O(1) ||
-|524. Longest Word in Dictionary through Deleting | [Go]({{< relref "/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})| Medium | O(n)| O(1) ||
-|532. K-diff Pairs in an Array | [Go]({{< relref "/ChapterFour/0532.K-diff-Pairs-in-an-Array.md" >}})| Easy | O(n)| O(n)||
-|567. Permutation in String | [Go]({{< relref "/ChapterFour/0567.Permutation-in-String.md" >}})| Medium | O(n)| O(1)|❤️|
-|713. Subarray Product Less Than K | [Go]({{< relref "/ChapterFour/0713.Subarray-Product-Less-Than-K.md" >}})| Medium | O(n)| O(1)||
-|763. Partition Labels | [Go]({{< relref "/ChapterFour/0763.Partition-Labels.md" >}})| Medium | O(n)| O(1)|❤️|
-|826. Most Profit Assigning Work | [Go]({{< relref "/ChapterFour/0826.Most-Profit-Assigning-Work.md" >}})| Medium | O(n log n)| O(n)||
-|828. Unique Letter String | [Go]({{< relref "/ChapterFour/0828.COPYRIGHT-PROBLEM-XXX.md" >}})| Hard | O(n)| O(1)|❤️|
-|838. Push Dominoes | [Go]({{< relref "/ChapterFour/0838.Push-Dominoes.md" >}})| Medium | O(n)| O(n)||
-|844. Backspace String Compare | [Go]({{< relref "/ChapterFour/0844.Backspace-String-Compare.md" >}})| Easy | O(n)| O(n) ||
-|845. Longest Mountain in Array | [Go]({{< relref "/ChapterFour/0845.Longest-Mountain-in-Array.md" >}})| Medium | O(n)| O(1) ||
-|881. Boats to Save People | [Go]({{< relref "/ChapterFour/0881.Boats-to-Save-People.md" >}})| Medium | O(n log n)| O(1) ||
-|904. Fruit Into Baskets | [Go]({{< relref "/ChapterFour/0904.Fruit-Into-Baskets.md" >}})| Medium | O(n log n)| O(1) ||
-|923. 3Sum With Multiplicity | [Go]({{< relref "/ChapterFour/0923.3Sum-With-Multiplicity.md" >}})| Medium | O(n^2)| O(n) ||
-|925. Long Pressed Name | [Go]({{< relref "/ChapterFour/0925.Long-Pressed-Name.md" >}})| Easy | O(n)| O(1)||
-|930. Binary Subarrays With Sum | [Go]({{< relref "/ChapterFour/0930.Binary-Subarrays-With-Sum.md" >}})| Medium | O(n)| O(n) |❤️|
-|977. Squares of a Sorted Array | [Go]({{< relref "/ChapterFour/0977.Squares-of-a-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
-|986. Interval List Intersections | [Go]({{< relref "/ChapterFour/0986.Interval-List-Intersections.md" >}})| Medium | O(n)| O(1)||
-|992. Subarrays with K Different Integers | [Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})| Hard | O(n)| O(n)|❤️|
-|1004. Max Consecutive Ones III | [Go]({{< relref "/ChapterFour/1004.Max-Consecutive-Ones-III.md" >}})| Medium | O(n)| O(1) ||
-|1093. Statistics from a Large Sample | [Go]({{< relref "/ChapterFour/1093.Statistics-from-a-Large-Sample.md" >}})| Medium | O(n)| O(1) ||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/Union_Find.md b/website/content/ChapterTwo/Union_Find.md
deleted file mode 100644
index 79b693d5f..000000000
--- a/website/content/ChapterTwo/Union_Find.md
+++ /dev/null
@@ -1,38 +0,0 @@
----
-title: Union Find
-type: docs
----
-
-# Union Find
-
-
-
-- 灵活使用并查集的思想,熟练掌握并查集的[模板]({{< relref "/ChapterThree/UnionFind.md" >}}),模板中有两种并查集的实现方式,一种是路径压缩 + 秩优化的版本,另外一种是计算每个集合中元素的个数 + 最大集合元素个数的版本,这两种版本都有各自使用的地方。能使用第一类并查集模板的题目有:第 128 题,第 130 题,第 547 题,第 684 题,第 721 题,第 765 题,第 778 题,第 839 题,第 924 题,第 928 题,第 947 题,第 952 题,第 959 题,第 990 题。能使用第二类并查集模板的题目有:第 803 题,第 952 题。第 803 题秩优化和统计集合个数这些地方会卡时间,如果不优化,会 TLE。
-- 并查集是一种思想,有些题需要灵活使用这种思想,而不是死套模板,如第 399 题,这一题是 stringUnionFind,利用并查集思想实现的。这里每个节点是基于字符串和 map 的,而不是单纯的用 int 节点编号实现的。
-- 有些题死套模板反而做不出来,比如第 685 题,这一题不能路径压缩和秩优化,因为题目中涉及到有向图,需要知道节点的前驱节点,如果路径压缩了,这一题就没法做了。这一题不需要路径压缩和秩优化。
-- 灵活的抽象题目给的信息,将给定的信息合理的编号,使用并查集解题,并用 map 降低时间复杂度,如第 721 题,第 959 题。
-- 关于地图,砖块,网格的题目,可以新建一个特殊节点,将四周边缘的砖块或者网格都 union() 到这个特殊节点上。第 130 题,第 803 题。
-- 能用并查集的题目,一般也可以用 DFS 和 BFS 解答,只不过时间复杂度会高一点。
-
-
-| Title | Solution | Difficulty | Time | Space | 收藏 |
-| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
-|128. Longest Consecutive Sequence | [Go]({{< relref "/ChapterFour/0128.Longest-Consecutive-Sequence.md" >}})| Hard | O(n)| O(n)|❤️|
-|130. Surrounded Regions | [Go]({{< relref "/ChapterFour/0130.Surrounded-Regions.md" >}})| Medium | O(m\*n)| O(m\*n)||
-|200. Number of Islands | [Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})| Medium | O(m\*n)| O(m\*n)||
-|399. Evaluate Division | [Go]({{< relref "/ChapterFour/0399.Evaluate-Division.md" >}})| Medium | O(n)| O(n)||
-|547. Friend Circles | [Go]({{< relref "/ChapterFour/0547.Friend-Circles.md" >}})| Medium | O(n^2)| O(n)||
-|684. Redundant Connection | [Go]({{< relref "/ChapterFour/0684.Redundant-Connection.md" >}})| Medium | O(n)| O(n)||
-|685. Redundant Connection II | [Go]({{< relref "/ChapterFour/0685.Redundant-Connection-II.md" >}})| Hard | O(n)| O(n)||
-|721. Accounts Merge | [Go]({{< relref "/ChapterFour/0721.Accounts-Merge.md" >}})| Medium | O(n)| O(n)|❤️|
-|765. Couples Holding Hands | [Go]({{< relref "/ChapterFour/0765.Couples-Holding-Hands.md" >}})| Hard | O(n)| O(n)|❤️|
-|778. Swim in Rising Water | [Go]({{< relref "/ChapterFour/0778.Swim-in-Rising-Water.md" >}})| Hard | O(n^2)| O(n)|❤️|
-|803. Bricks Falling When Hit | [Go]({{< relref "/ChapterFour/0803.Bricks-Falling-When-Hit.md" >}})| Hard | O(n^2)| O(n)|❤️|
-|839. Similar String Groups | [Go]({{< relref "/ChapterFour/0839.Similar-String-Groups.md" >}})| Hard | O(n^2)| O(n)||
-|924. Minimize Malware Spread | [Go]({{< relref "/ChapterFour/0924.Minimize-Malware-Spread.md" >}})| Hard | O(m\*n)| O(n)||
-|928. Minimize Malware Spread II | [Go]({{< relref "/ChapterFour/0928.Minimize-Malware-Spread-II.md" >}})| Hard | O(m\*n)| O(n)|❤️|
-|947. Most Stones Removed with Same Row or Column | [Go]({{< relref "/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md" >}})| Medium | O(n)| O(n)||
-|952. Largest Component Size by Common Factor | [Go]({{< relref "/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md" >}})| Hard | O(n)| O(n)|❤️|
-|959. Regions Cut By Slashes | [Go]({{< relref "/ChapterFour/0959.Regions-Cut-By-Slashes.md" >}})| Medium | O(n^2)| O(n^2)|❤️|
-|990. Satisfiability of Equality Equations | [Go]({{< relref "/ChapterFour/0990.Satisfiability-of-Equality-Equations.md" >}})| Medium | O(n)| O(n)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
diff --git a/website/content/ChapterTwo/_index.md b/website/content/ChapterTwo/_index.md
deleted file mode 100644
index c28b73c5b..000000000
--- a/website/content/ChapterTwo/_index.md
+++ /dev/null
@@ -1,21 +0,0 @@
----
-title: 第二章
-type: docs
----
-
-# 第二章 算法专题
-
-
-
-
-
-
-
-
-本来天真的认为,把 LeetCode 所有题都完整刷一遍,就可以完整这本书了。经过事实证明,确实是天真了。因为 LeetCode 每天都会增加新题,有时候工作忙了,刷题进度就完全追不上题目更新的速度了。而且以我当前的刷题速度,一年才完成 500+,一年 LeetCode 也会更新 400+ 多题,要起码 5~10 年才能把所有的题目刷完。时间太长了。所以先给自己定了一个小目标,500 题就先把书写出来,总结这个阶段的刷题心得,和大家一起交流。要想把 LeetCode 所有题目都刷完,看来这本书要迭代 5 ~ 10 个版本了(一年迭代一版)。
-
-那么这一章就把已经刷完了的专题都整理一遍。有相似套路的题目都放在一起,如果想快速面试的话,其实相同的题目刷 2,3 道就可以了。相同类型的题目非常熟练的情况下,再多刷几道也是做无用功。
-
-做到目前为止,笔者认为动态规划是最灵活的类型,这类题目没有一个模板可以给你套用,它也是算法之优雅的地方。笔者认为称它为算法的艺术不为过。动态规划这类型,笔者也还没有刷完,只刷了一部分,还在学习中。
-
-那么就分享一下笔者目前刷过的题,和有相似点的题目吧。
diff --git a/website/content/_index.md b/website/content/_index.md
deleted file mode 100644
index e9a44e0b5..000000000
--- a/website/content/_index.md
+++ /dev/null
@@ -1,88 +0,0 @@
----
-title: 序
-type: docs
----
-
-# 序
-
-{{< columns >}}
-## 关于 LeetCode
-
-说到 LeetCode,作为一个程序员来说,应该不陌生,近几年参加面试都会提到它。国内外的程序员用它刷题主要是为了面试。据历史记载,这个网站 2011 年就成立了,马上就要到自己 10 周年的生日了。每周举行周赛,双周赛,月赛,在有限时间内编码,确实非常能考验人的算法能力。一些大公司赞助冠名的比赛获得前几名除了有奖品,还能直接拿到内推的机会。
-
-<--->
-
-## 什么是 Cookbook
-
-直译的话就是烹饪书,教你做各种食谱美食的书。经常看 O'Reilly 技术书的同学对这个名词会很熟悉。一般动手操作,实践类的书都会有这个名字。
-
-{{< /columns >}}
-
-
-
-## 为什么会写这个开源书
-
-笔者刷题刷了一年了,想和大家分享分享一些做题心得,解题方法。想和有相同爱好的人交个朋友,一起交流学习。对于自己来说,写题解也是一种提高。把一道深奥的题目讲给一点都没有头绪的人,并能让他完全听懂,很能锻炼人的表达能力。在讲解中很可能还会遇到听者的一些提问,这些问题可能是自己的知识漏洞,强迫自己去弥补。笔者在公司做过相关的分享,感受很深,双方受益都还不错。
-
-> 另外,在大学期间,笔者做题的时候最讨厌写题解,感觉是浪费时间,用更多的时间去做更多的题。现在不知道算不算是“出来混的,总是要还的”。
-
-
-## 关于书的封面
-
-常看 O'Reilly 动物书的同学一看这个封面就知道是向他们致敬。确实是这个目的。O'Reilly 的封面动物都是稀缺动物,并且画风都是黑白素描风。这些动物都有版权了,所以只能在网上找没有版权的黑白素描风的图片。常见的能找到 40 张这种风格的图片。不过用的人太多了,笔者费劲的找了其他几张这种图片,这张孔雀开屏是其中一张。孔雀开屏的意义是希望大家刷完 LeetCode 以后,提高了自身的算法能力,在人生的舞台上开出自己的“屏”。全书配色也都是绿色,因为这是 AC 的颜色。
-
-
-## 关于作者
-
-笔者是一个刚刚入行一年半的 gopher 新人,还请各位大佬多多指点小弟我。大学参加了 3 年 ACM-ICPC,但是由于资质不高,没有拿到一块金牌。所以在算法方面,我对自己的评价算是新手吧。参加 ACM-ICPC 最大的收获是训练了思维能力,这种能力也会运用到生活中。其次是认识了很多国内很聪明的选手,看到了自己和他们的差距。最后,就是那 200 多页,有些自己都没有完全理解的,打印的密密麻麻的[算法模板](https://github.com/halfrost/LeetCode-Go/releases/tag/Special)。知识学会了,终身都是自己的,没有学会,那些知识都是身外之物。
-
-笔者从 2019 年 3 月 25 号开始刷题,到 2020 年 3 月 25 号,整整一年的时间。原计划是每天一题。实际上每天有时候不止一题,最终完成了 600+:
-
-
-
-> 一个温馨提示:笔者本以为每天做一题,会让这个 submissions 图全绿,但是我发现我错了。如果你也想坚持,让这个图全绿,一定要注意以下的问题:LeetCode 服务器是在 +0 时区的,这个图也是按照这个时区计算的。也就是说,中国每天早上 8 点之前,是算前一天的!也是因为时区的问题,导致我空白了这 22 个格子。比如有一道 Hard 题很难,当天工作也很多,晚上下班回家想出来了就到第二天凌晨了。于是再做一题当做第二天的量。结果会发现这 2 题都算前一天的。有时候笔者早上 6 点起床刷题,提交以后也都是前一天的。
->
-> (当然这些都是过去了,不重要了,全当是奋斗路上的一些小插曲)
-
-2020 年笔者肯定还会继续刷题,因为还没有达到自己的一些目标。可能会朝着 1000 题奋进,也有可能刷到 800 题的时候回头开始二刷,三刷。(不达目的不罢休吧~)
-
-## 关于书中的代码
-
-代码都放在 [github repo](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode) 中,按题号可以搜索到题目。
-本书题目的代码都已经 beats 100% 了。没有 beats 100% 题解就没有放到本书中了。那些题目笔者会继续优化到 100% 再放进来。
-
-有可能读者会问,为何要追求 beats 100%。笔者认为优化到 beats 100% 才算是把这题做出感觉了。有好几道 Hard 题,笔者都用暴力解法 AC 了,然后只 beats 了 5%。这题就如同没做一样。而且面试中如果给了这样的答案,面试官也不会满意,“还有没有更优解?”。如果通过自己的思考能给出更优解,面试官会更满意一些。
-
-LeetCode 统计代码运行时长会有波动的,相同的代码提交 10 次可能就会 beats 100% 了。笔者开始没有发现这个问题,很多题用正确的代码连续交了很多次,一年提交 3400+ 次,导致我的正确率也变的奇高。😢
-
-当然,如果还有其他更优美的解法,也能 beats 100% 的,欢迎提交 PR,笔者和大家一起学习。
-
-## 目标读者
-
-想通过 LeetCode 提高算法能力的编程爱好者。
-
-
-## 编程语言
-
-本书的算法全部用 Go 语言实现。
-
-## 使用说明
-
-- 本电子书的左上角有搜索栏,可以迅速帮你找到你想看的章节和题号。
-- 本电子书每页都接入了 Gitalk,每一页的最下方都有评论框可以评论,如果没有显示出来,请检查自己的网络。
-- 关于题解,笔者建议这样使用:先自己读题,思考如何解题。如果 15 分钟还没有思路,那么先看笔者的解题思路,但是不要看代码。有思路以后自己用代码实现一遍。如果完全不会写,那就看笔者提供的代码,找出自己到底哪里不会写,找出问题记下来,这就是自己要弥补的知识漏洞。如果自己实现出来了,提交以后有错误,自己先 debug。AC 以后没有到 100% 也先自己思考如何优化。如果每道题自己都能优化到 100% 了,那么一段时间以后进步会很大。所以总的来说,实在没思路,看解题思路;实在优化不到 100%,看看代码。
-
-## 互动与勘误
-
-如果书中文章有所遗漏,欢迎点击所在页面下边的 edit 按钮进行评论和互动,感谢您的支持与帮助。
-
-## 最后
-
-一起开始刷题吧~
-
-
-
-本作品采用 [知识署名-非商业性使用-禁止演绎 (BY-NC-ND) 4.0 国际许可协议](https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode.zh-Hans) 进行许可。
-
-题解里面的所有题目版权均归 [LeetCode](https://leetcode.com/) 和 [力扣中国](https://leetcode-cn.com/) 所有
-
\ No newline at end of file
diff --git a/website/content/docs/example/_index.md b/website/content/docs/example/_index.md
deleted file mode 100644
index 4835b7ca0..000000000
--- a/website/content/docs/example/_index.md
+++ /dev/null
@@ -1,71 +0,0 @@
----
-weight: 1
-bookFlatSection: true
-title: "Example Site"
----
-
-# Introduction
-
-## Ferre hinnitibus erat accipitrem dixi Troiae tollens
-
-Lorem markdownum, a quoque nutu est *quodcumque mandasset* veluti. Passim
-inportuna totidemque nympha fert; repetens pendent, poenarum guttura sed vacet
-non, mortali undas. Omnis pharetramque gramen portentificisque membris servatum
-novabis fallit de nubibus atque silvas mihi. **Dixit repetitaque Quid**; verrit
-longa; sententia [mandat](http://pastor-ad.io/questussilvas) quascumque nescio
-solebat [litore](http://lacrimas-ab.net/); noctes. *Hostem haerentem* circuit
-[plenaque tamen](http://www.sine.io/in).
-
-- Pedum ne indigenae finire invergens carpebat
-- Velit posses summoque
-- De fumos illa foret
-
-## Est simul fameque tauri qua ad
-
-Locum nullus nisi vomentes. Ab Persea sermone vela, miratur aratro; eandem
-Argolicas gener.
-
-## Me sol
-
-Nec dis certa fuit socer, Nonacria **dies** manet tacitaque sibi? Sucis est
-iactata Castrumque iudex, et iactato quoque terraeque es tandem et maternos
-vittis. Lumina litus bene poenamque animos callem ne tuas in leones illam dea
-cadunt genus, et pleno nunc in quod. Anumque crescentesque sanguinis
-[progenies](http://www.late.net/alimentavirides) nuribus rustica tinguet. Pater
-omnes liquido creditis noctem.
-
- if (mirrored(icmp_dvd_pim, 3, smbMirroredHard) != lion(clickImportQueue,
- viralItunesBalancing, bankruptcy_file_pptp)) {
- file += ip_cybercrime_suffix;
- }
- if (runtimeSmartRom == netMarketingWord) {
- virusBalancingWin *= scriptPromptBespoke + raster(post_drive,
- windowsSli);
- cd = address_hertz_trojan;
- soap_ccd.pcbServerGigahertz(asp_hardware_isa, offlinePeopleware, nui);
- } else {
- megabyte.api = modem_flowchart - web + syntaxHalftoneAddress;
- }
- if (3 < mebibyteNetworkAnimated) {
- pharming_regular_error *= jsp_ribbon + algorithm * recycleMediaKindle(
- dvrSyntax, cdma);
- adf_sla *= hoverCropDrive;
- templateNtfs = -1 - vertical;
- } else {
- expressionCompressionVariable.bootMulti = white_eup_javascript(
- table_suffix);
- guidPpiPram.tracerouteLinux += rtfTerabyteQuicktime(1,
- managementRosetta(webcamActivex), 740874);
- }
- var virusTweetSsl = nullGigo;
-
-## Trepident sitimque
-
-Sentiet et ferali errorem fessam, coercet superbus, Ascaniumque in pennis
-mediis; dolor? Vidit imi **Aeacon** perfida propositos adde, tua Somni Fluctibus
-errante lustrat non.
-
-Tamen inde, vos videt e flammis Scythica parantem rupisque pectora umbras. Haec
-ficta canistris repercusso simul ego aris Dixit! Esse Fama trepidare hunc
-crescendo vigor ululasse vertice *exspatiantur* celer tepidique petita aversata
-oculis iussa est me ferro.
diff --git a/website/content/docs/example/collapsed/3rd-level/4th-level.md b/website/content/docs/example/collapsed/3rd-level/4th-level.md
deleted file mode 100644
index aa451f19e..000000000
--- a/website/content/docs/example/collapsed/3rd-level/4th-level.md
+++ /dev/null
@@ -1,12 +0,0 @@
-# 4th Level of Menu
-
-## Caesorum illa tu sentit micat vestes papyriferi
-
-Inde aderam facti; Theseus vis de tauri illa peream. Oculos **uberaque** non
-regisque vobis cursuque, opus venit quam vulnera. Et maiora necemque, lege modo;
-gestanda nitidi, vero? Dum ne pectoraque testantur.
-
-Venasque repulsa Samos qui, exspectatum eram animosque hinc, [aut
-manes](http://www.creveratnon.net/apricaaetheriis), Assyrii. Cupiens auctoribus
-pariter rubet, profana magni super nocens. Vos ius sibilat inpar turba visae
-iusto! Sedes ante dum superest **extrema**.
diff --git a/website/content/docs/example/collapsed/3rd-level/_index.md b/website/content/docs/example/collapsed/3rd-level/_index.md
deleted file mode 100644
index cc0100f3c..000000000
--- a/website/content/docs/example/collapsed/3rd-level/_index.md
+++ /dev/null
@@ -1,26 +0,0 @@
-# 3rd Level of Menu
-
-Nefas discordemque domino montes numen tum humili nexilibusque exit, Iove. Quae
-miror esse, scelerisque Melaneus viribus. Miseri laurus. Hoc est proposita me
-ante aliquid, aura inponere candidioribus quidque accendit bella, sumpta.
-Intravit quam erat figentem hunc, motus de fontes parvo tempestate.
-
- iscsi_virus = pitch(json_in_on(eupViral),
- northbridge_services_troubleshooting, personal(
- firmware_rw.trash_rw_crm.device(interactive_gopher_personal,
- software, -1), megabit, ergonomicsSoftware(cmyk_usb_panel,
- mips_whitelist_duplex, cpa)));
- if (5) {
- managementNetwork += dma - boolean;
- kilohertz_token = 2;
- honeypot_affiliate_ergonomics = fiber;
- }
- mouseNorthbridge = byte(nybble_xmp_modem.horse_subnet(
- analogThroughputService * graphicPoint, drop(daw_bit, dnsIntranet),
- gateway_ospf), repository.domain_key.mouse(serverData(fileNetwork,
- trim_duplex_file), cellTapeDirect, token_tooltip_mashup(
- ripcordingMashup)));
- module_it = honeypot_driver(client_cold_dvr(593902, ripping_frequency) +
- coreLog.joystick(componentUdpLink), windows_expansion_touchscreen);
- bashGigabit.external.reality(2, server_hardware_codec.flops.ebookSampling(
- ciscNavigationBacklink, table + cleanDriver), indexProtocolIsp);
diff --git a/website/content/docs/example/collapsed/_index.md b/website/content/docs/example/collapsed/_index.md
deleted file mode 100644
index 806bc2efa..000000000
--- a/website/content/docs/example/collapsed/_index.md
+++ /dev/null
@@ -1,23 +0,0 @@
----
-bookCollapseSection: true
-weight: 20
----
-
-# Collapsed Level of Menu
-
-## Cognita laeva illo fracta
-
-Lorem markdownum pavent auras, surgit nunc cingentibus libet **Laomedonque que**
-est. Pastor [An](http://est.org/ire.aspx) arbor filia foedat, ne [fugit
-aliter](http://www.indiciumturbam.org/moramquid.php), per. Helicona illas et
-callida neptem est *Oresitrophos* caput, dentibus est venit. Tenet reddite
-[famuli](http://www.antro-et.net/) praesentem fortibus, quaeque vis foret si
-frondes *gelidos* gravidae circumtulit [inpulit armenta
-nativum](http://incurvasustulit.io/illi-virtute.html).
-
-1. Te at cruciabere vides rubentis manebo
-2. Maturuit in praetemptat ruborem ignara postquam habitasse
-3. Subitarum supplevit quoque fontesque venabula spretis modo
-4. Montis tot est mali quasque gravis
-5. Quinquennem domus arsit ipse
-6. Pellem turis pugnabant locavit
diff --git a/website/content/docs/example/hidden.md b/website/content/docs/example/hidden.md
deleted file mode 100644
index df7cb9ebb..000000000
--- a/website/content/docs/example/hidden.md
+++ /dev/null
@@ -1,52 +0,0 @@
----
-bookHidden: true
----
-
-# This page is hidden in menu
-
-# Quondam non pater est dignior ille Eurotas
-
-## Latent te facies
-
-Lorem markdownum arma ignoscas vocavit quoque ille texit mandata mentis ultimus,
-frementes, qui in vel. Hippotades Peleus [pennas
-conscia](http://gratia.net/tot-qua.php) cuiquam Caeneus quas.
-
-- Pater demittere evincitque reddunt
-- Maxime adhuc pressit huc Danaas quid freta
-- Soror ego
-- Luctus linguam saxa ultroque prior Tatiumque inquit
-- Saepe liquitur subita superata dederat Anius sudor
-
-## Cum honorum Latona
-
-O fallor [in sustinui
-iussorum](http://www.spectataharundine.org/aquas-relinquit.html) equidem.
-Nymphae operi oris alii fronde parens dumque, in auro ait mox ingenti proxima
-iamdudum maius?
-
- reality(burnDocking(apache_nanometer),
- pad.property_data_programming.sectorBrowserPpga(dataMask, 37,
- recycleRup));
- intellectualVaporwareUser += -5 * 4;
- traceroute_key_upnp /= lag_optical(android.smb(thyristorTftp));
- surge_host_golden = mca_compact_device(dual_dpi_opengl, 33,
- commerce_add_ppc);
- if (lun_ipv) {
- verticalExtranet(1, thumbnail_ttl, 3);
- bar_graphics_jpeg(chipset - sector_xmp_beta);
- }
-
-## Fronde cetera dextrae sequens pennis voce muneris
-
-Acta cretus diem restet utque; move integer, oscula non inspirat, noctisque
-scelus! Nantemque in suas vobis quamvis, et labori!
-
- var runtimeDiskCompiler = home - array_ad_software;
- if (internic > disk) {
- emoticonLockCron += 37 + bps - 4;
- wan_ansi_honeypot.cardGigaflops = artificialStorageCgi;
- simplex -= downloadAccess;
- }
- var volumeHardeningAndroid = pixel + tftp + onProcessorUnmount;
- sector(memory(firewire + interlaced, wired));
\ No newline at end of file
diff --git a/website/content/docs/example/table-of-contents/_index.md b/website/content/docs/example/table-of-contents/_index.md
deleted file mode 100644
index c7ee0d872..000000000
--- a/website/content/docs/example/table-of-contents/_index.md
+++ /dev/null
@@ -1,85 +0,0 @@
----
-weight: 10
----
-
-# Ubi loqui
-
-## Mentem genus facietque salire tempus bracchia
-
-Lorem markdownum partu paterno Achillem. Habent amne generosi aderant ad pellem
-nec erat sustinet merces columque haec et, dixit minus nutrit accipiam subibis
-subdidit. Temeraria servatum agros qui sed fulva facta. Primum ultima, dedit,
-suo quisque linguae medentes fixo: tum petis.
-
-## Rapit vocant si hunc siste adspice
-
-Ora precari Patraeque Neptunia, dixit Danae [Cithaeron
-armaque](http://mersis-an.org/litoristum) maxima in **nati Coniugis** templis
-fluidove. Effugit usus nec ingreditur agmen *ac manus* conlato. Nullis vagis
-nequiquam vultibus aliquos altera *suum venis* teneas fretum. Armos [remotis
-hoc](http://tutum.io/me) sine ferrea iuncta quam!
-
-## Locus fuit caecis
-
-Nefas discordemque domino montes numen tum humili nexilibusque exit, Iove. Quae
-miror esse, scelerisque Melaneus viribus. Miseri laurus. Hoc est proposita me
-ante aliquid, aura inponere candidioribus quidque accendit bella, sumpta.
-Intravit quam erat figentem hunc, motus de fontes parvo tempestate.
-
- iscsi_virus = pitch(json_in_on(eupViral),
- northbridge_services_troubleshooting, personal(
- firmware_rw.trash_rw_crm.device(interactive_gopher_personal,
- software, -1), megabit, ergonomicsSoftware(cmyk_usb_panel,
- mips_whitelist_duplex, cpa)));
- if (5) {
- managementNetwork += dma - boolean;
- kilohertz_token = 2;
- honeypot_affiliate_ergonomics = fiber;
- }
- mouseNorthbridge = byte(nybble_xmp_modem.horse_subnet(
- analogThroughputService * graphicPoint, drop(daw_bit, dnsIntranet),
- gateway_ospf), repository.domain_key.mouse(serverData(fileNetwork,
- trim_duplex_file), cellTapeDirect, token_tooltip_mashup(
- ripcordingMashup)));
- module_it = honeypot_driver(client_cold_dvr(593902, ripping_frequency) +
- coreLog.joystick(componentUdpLink), windows_expansion_touchscreen);
- bashGigabit.external.reality(2, server_hardware_codec.flops.ebookSampling(
- ciscNavigationBacklink, table + cleanDriver), indexProtocolIsp);
-
-## Placabilis coactis nega ingemuit ignoscat nimia non
-
-Frontis turba. Oculi gravis est Delphice; *inque praedaque* sanguine manu non.
-
- if (ad_api) {
- zif += usb.tiffAvatarRate(subnet, digital_rt) + exploitDrive;
- gigaflops(2 - bluetooth, edi_asp_memory.gopher(queryCursor, laptop),
- panel_point_firmware);
- spyware_bash.statePopApplet = express_netbios_digital(
- insertion_troubleshooting.brouter(recordFolderUs), 65);
- }
- recursionCoreRay = -5;
- if (hub == non) {
- portBoxVirus = soundWeb(recursive_card(rwTechnologyLeopard),
- font_radcab, guidCmsScalable + reciprocalMatrixPim);
- left.bug = screenshot;
- } else {
- tooltipOpacity = raw_process_permalink(webcamFontUser, -1);
- executable_router += tape;
- }
- if (tft) {
- bandwidthWeb *= social_page;
- } else {
- regular += 611883;
- thumbnail /= system_lag_keyboard;
- }
-
-## Caesorum illa tu sentit micat vestes papyriferi
-
-Inde aderam facti; Theseus vis de tauri illa peream. Oculos **uberaque** non
-regisque vobis cursuque, opus venit quam vulnera. Et maiora necemque, lege modo;
-gestanda nitidi, vero? Dum ne pectoraque testantur.
-
-Venasque repulsa Samos qui, exspectatum eram animosque hinc, [aut
-manes](http://www.creveratnon.net/apricaaetheriis), Assyrii. Cupiens auctoribus
-pariter rubet, profana magni super nocens. Vos ius sibilat inpar turba visae
-iusto! Sedes ante dum superest **extrema**.
diff --git a/website/content/docs/example/table-of-contents/with-toc.md b/website/content/docs/example/table-of-contents/with-toc.md
deleted file mode 100644
index 5345c668a..000000000
--- a/website/content/docs/example/table-of-contents/with-toc.md
+++ /dev/null
@@ -1,64 +0,0 @@
----
-title: With ToC
-weight: 1
----
-# Caput vino delphine in tamen vias
-
-## Cognita laeva illo fracta
-
-Lorem markdownum pavent auras, surgit nunc cingentibus libet **Laomedonque que**
-est. Pastor [An](http://est.org/ire.aspx) arbor filia foedat, ne [fugit
-aliter](http://www.indiciumturbam.org/moramquid.php), per. Helicona illas et
-callida neptem est *Oresitrophos* caput, dentibus est venit. Tenet reddite
-[famuli](http://www.antro-et.net/) praesentem fortibus, quaeque vis foret si
-frondes *gelidos* gravidae circumtulit [inpulit armenta
-nativum](http://incurvasustulit.io/illi-virtute.html).
-
-1. Te at cruciabere vides rubentis manebo
-2. Maturuit in praetemptat ruborem ignara postquam habitasse
-3. Subitarum supplevit quoque fontesque venabula spretis modo
-4. Montis tot est mali quasque gravis
-5. Quinquennem domus arsit ipse
-6. Pellem turis pugnabant locavit
-
-## Natus quaerere
-
-Pectora et sine mulcere, coniuge dum tincta incurvae. Quis iam; est dextra
-Peneosque, metuis a verba, primo. Illa sed colloque suis: magno: gramen, aera
-excutiunt concipit.
-
-> Phrygiae petendo suisque extimuit, super, pars quod audet! Turba negarem.
-> Fuerat attonitus; et dextra retinet sidera ulnas undas instimulat vacuae
-> generis? *Agnus* dabat et ignotis dextera, sic tibi pacis **feriente at mora**
-> euhoeque *comites hostem* vestras Phineus. Vultuque sanguine dominoque [metuit
-> risi](http://iuvat.org/eundem.php) fama vergit summaque meus clarissimus
-> artesque tinguebat successor nominis cervice caelicolae.
-
-## Limitibus misere sit
-
-Aurea non fata repertis praerupit feruntur simul, meae hosti lentaque *citius
-levibus*, cum sede dixit, Phaethon texta. *Albentibus summos* multifidasque
-iungitur loquendi an pectore, mihi ursaque omnia adfata, aeno parvumque in animi
-perlucentes. Epytus agis ait vixque clamat ornum adversam spondet, quid sceptra
-ipsum **est**. Reseret nec; saeva suo passu debentia linguam terga et aures et
-cervix [de](http://www.amnem.io/pervenit.aspx) ubera. Coercet gelidumque manus,
-doluit volvitur induta?
-
-## Enim sua
-
-Iuvenilior filia inlustre templa quidem herbis permittat trahens huic. In
-cruribus proceres sole crescitque *fata*, quos quos; merui maris se non tamen
-in, mea.
-
-## Germana aves pignus tecta
-
-Mortalia rudibusque caelum cognosceret tantum aquis redito felicior texit, nec,
-aris parvo acre. Me parum contulerant multi tenentem, gratissime suis; vultum tu
-occupat deficeret corpora, sonum. E Actaea inplevit Phinea concepit nomenque
-potest sanguine captam nulla et, in duxisses campis non; mercede. Dicere cur
-Leucothoen obitum?
-
-Postibus mittam est *nubibus principium pluma*, exsecratur facta et. Iunge
-Mnemonidas pallamque pars; vere restitit alis flumina quae **quoque**, est
-ignara infestus Pyrrha. Di ducis terris maculatum At sede praemia manes
-nullaque!
diff --git a/website/content/docs/example/table-of-contents/without-toc.md b/website/content/docs/example/table-of-contents/without-toc.md
deleted file mode 100644
index 9b1631883..000000000
--- a/website/content/docs/example/table-of-contents/without-toc.md
+++ /dev/null
@@ -1,59 +0,0 @@
----
-title: Without ToC
-weight: 2
-bookToc: false
----
-
-# At me ipso nepotibus nunc celebratior genus
-
-## Tanto oblite
-
-Lorem markdownum pectora novis patenti igne sua opus aurae feras materiaque
-illic demersit imago et aristas questaque posset. Vomit quoque suo inhaesuro
-clara. Esse cumque, per referri triste. Ut exponit solisque communis in tendens
-vincetis agisque iamque huic bene ante vetat omina Thebae rates. Aeacus servat
-admonitu concidit, ad resimas vultus et rugas vultu **dignamque** Siphnon.
-
-Quam iugulum regia simulacra, plus meruit humo pecorumque haesit, ab discedunt
-dixit: ritu pharetramque. Exul Laurenti orantem modo, per densum missisque labor
-manibus non colla unum, obiectat. Tu pervia collo, fessus quae Cretenque Myconon
-crate! Tegumenque quae invisi sudore per vocari quaque plus ventis fluidos. Nodo
-perque, fugisse pectora sorores.
-
-## Summe promissa supple vadit lenius
-
-Quibus largis latebris aethera versato est, ait sentiat faciemque. Aequata alis
-nec Caeneus exululat inclite corpus est, ire **tibi** ostendens et tibi. Rigent
-et vires dique possent lumina; **eadem** dixit poma funeribus paret et felix
-reddebant ventis utile lignum.
-
-1. Remansit notam Stygia feroxque
-2. Et dabit materna
-3. Vipereas Phrygiaeque umbram sollicito cruore conlucere suus
-4. Quarum Elis corniger
-5. Nec ieiunia dixit
-
-Vertitur mos ortu ramosam contudit dumque; placabat ac lumen. Coniunx Amoris
-spatium poenamque cavernis Thebae Pleiadasque ponunt, rapiare cum quae parum
-nimium rima.
-
-## Quidem resupinus inducto solebat una facinus quae
-
-Credulitas iniqua praepetibus paruit prospexit, voce poena, sub rupit sinuatur,
-quin suum ventorumque arcadiae priori. Soporiferam erat formamque, fecit,
-invergens, nymphae mutat fessas ait finge.
-
-1. Baculum mandataque ne addere capiti violentior
-2. Altera duas quam hoc ille tenues inquit
-3. Sicula sidereus latrantis domoque ratae polluit comites
-4. Possit oro clausura namque se nunc iuvenisque
-5. Faciem posuit
-6. Quodque cum ponunt novercae nata vestrae aratra
-
-Ite extrema Phrygiis, patre dentibus, tonso perculit, enim blanda, manibus fide
-quos caput armis, posse! Nocendo fas Alcyonae lacertis structa ferarum manus
-fulmen dubius, saxa caelum effuge extremis fixum tumor adfecit **bella**,
-potentes? Dum nec insidiosa tempora tegit
-[spirarunt](http://mihiferre.net/iuvenes-peto.html). Per lupi pars foliis,
-porreximus humum negant sunt subposuere Sidone steterant auro. Memoraverit sine:
-ferrum idem Orion caelum heres gerebat fixis?
diff --git a/website/content/docs/shortcodes/_index.md b/website/content/docs/shortcodes/_index.md
deleted file mode 100644
index 9bb0430cb..000000000
--- a/website/content/docs/shortcodes/_index.md
+++ /dev/null
@@ -1,3 +0,0 @@
----
-bookFlatSection: true
----
diff --git a/website/content/docs/shortcodes/buttons.md b/website/content/docs/shortcodes/buttons.md
deleted file mode 100644
index c2ef1e755..000000000
--- a/website/content/docs/shortcodes/buttons.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# Buttons
-
-Buttons are styled links that can lead to local page or external link.
-
-## Example
-
-```tpl
-{{* button relref="/" [class="..."] */>}}Get Home{{* /button */>}}
-{{* button href="https://github.com/alex-shpak/hugo-book" */>}}Contribute{{* /button */>}}
-```
-
-{{< button relref="/" >}}Get Home{{< /button >}}
-{{< button href="https://github.com/alex-shpak/hugo-book" >}}Contribute{{< /button >}}
diff --git a/website/content/docs/shortcodes/columns.md b/website/content/docs/shortcodes/columns.md
deleted file mode 100644
index 4df396a67..000000000
--- a/website/content/docs/shortcodes/columns.md
+++ /dev/null
@@ -1,45 +0,0 @@
-# Columns
-
-Columns help organize shorter pieces of content horizontally for readability.
-
-
-```html
-{{* columns */>}}
-# Left Content
-Lorem markdownum insigne...
-
-<--->
-
-# Mid Content
-Lorem markdownum insigne...
-
-<--->
-
-# Right Content
-Lorem markdownum insigne...
-{{* /columns */>}}
-```
-
-## Example
-
-{{< columns >}}
-## Left Content
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
-Miseratus fonte Ditis conubia.
-
-<--->
-
-## Mid Content
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter!
-
-<--->
-
-## Right Content
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
-Miseratus fonte Ditis conubia.
-{{< /columns >}}
diff --git a/website/content/docs/shortcodes/details.md b/website/content/docs/shortcodes/details.md
deleted file mode 100644
index 248bafd97..000000000
--- a/website/content/docs/shortcodes/details.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# Details
-
-Details shortcode is a helper for `details` html5 element. It is going to replace `expand` shortcode.
-
-## Example
-```tpl
-{{* details "Title" [open] */>}}
-## Markdown content
-Lorem markdownum insigne...
-{{* /details */>}}
-```
-```tpl
-{{* details title="Title" open=true */>}}
-## Markdown content
-Lorem markdownum insigne...
-{{* /details */>}}
-```
-
-{{< details "Title" open >}}
-## Markdown content
-Lorem markdownum insigne...
-{{< /details >}}
diff --git a/website/content/docs/shortcodes/expand.md b/website/content/docs/shortcodes/expand.md
deleted file mode 100644
index c62520f3f..000000000
--- a/website/content/docs/shortcodes/expand.md
+++ /dev/null
@@ -1,35 +0,0 @@
-# Expand
-
-Expand shortcode can help to decrease clutter on screen by hiding part of text. Expand content by clicking on it.
-
-## Example
-### Default
-
-```tpl
-{{* expand */>}}
-## Markdown content
-Lorem markdownum insigne...
-{{* /expand */>}}
-```
-
-{{< expand >}}
-## Markdown content
-Lorem markdownum insigne...
-{{< /expand >}}
-
-### With Custom Label
-
-```tpl
-{{* expand "Custom Label" "..." */>}}
-## Markdown content
-Lorem markdownum insigne...
-{{* /expand */>}}
-```
-
-{{< expand "Custom Label" "..." >}}
-## Markdown content
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
-Miseratus fonte Ditis conubia.
-{{< /expand >}}
diff --git a/website/content/docs/shortcodes/hints.md b/website/content/docs/shortcodes/hints.md
deleted file mode 100644
index 3477113de..000000000
--- a/website/content/docs/shortcodes/hints.md
+++ /dev/null
@@ -1,32 +0,0 @@
-# Hints
-
-Hint shortcode can be used as hint/alerts/notification block.
-There are 3 colors to choose: `info`, `warning` and `danger`.
-
-```tpl
-{{* hint [info|warning|danger] */>}}
-**Markdown content**
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-{{* /hint */>}}
-```
-
-## Example
-
-{{< hint info >}}
-**Markdown content**
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-{{< /hint >}}
-
-{{< hint warning >}}
-**Markdown content**
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-{{< /hint >}}
-
-{{< hint danger >}}
-**Markdown content**
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-{{< /hint >}}
diff --git a/website/content/docs/shortcodes/katex.md b/website/content/docs/shortcodes/katex.md
deleted file mode 100644
index 4beeaa004..000000000
--- a/website/content/docs/shortcodes/katex.md
+++ /dev/null
@@ -1,28 +0,0 @@
-# KaTeX
-
-KaTeX shortcode let you render math typesetting in markdown document. See [KaTeX](https://katex.org/)
-
-## Example
-{{< columns >}}
-
-```latex
-{{* katex [display] [class="text-center"] */>}}
-f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
-{{* /katex */>}}
-```
-
-<--->
-
-{{< katex display >}}
-f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
-{{< /katex >}}
-
-{{< /columns >}}
-
-## Display Mode Example
-
-Here is some inline example: {{< katex >}}\pi(x){{< /katex >}}, rendered in the same line. And below is `display` example, having `display: block`
-{{< katex display >}}
-f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
-{{< /katex >}}
-Text continues here.
diff --git a/website/content/docs/shortcodes/mermaid.md b/website/content/docs/shortcodes/mermaid.md
deleted file mode 100644
index 3a617bcc0..000000000
--- a/website/content/docs/shortcodes/mermaid.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Mermaid Chart
-
-[Mermaid](https://mermaidjs.github.io/) is library for generating svg charts and diagrams from text.
-
-## Example
-
-{{< columns >}}
-```tpl
-{{* mermaid [class="text-center"]*/>}}
-sequenceDiagram
- Alice->>Bob: Hello Bob, how are you?
- alt is sick
- Bob->>Alice: Not so good :(
- else is well
- Bob->>Alice: Feeling fresh like a daisy
- end
- opt Extra response
- Bob->>Alice: Thanks for asking
- end
-{{* /mermaid */>}}
-```
-
-<--->
-
-{{< mermaid >}}
-sequenceDiagram
- Alice->>Bob: Hello Bob, how are you?
- alt is sick
- Bob->>Alice: Not so good :(
- else is well
- Bob->>Alice: Feeling fresh like a daisy
- end
- opt Extra response
- Bob->>Alice: Thanks for asking
- end
-{{< /mermaid >}}
-
-{{< /columns >}}
diff --git a/website/content/docs/shortcodes/section/_index.md b/website/content/docs/shortcodes/section/_index.md
deleted file mode 100644
index bd5db38b3..000000000
--- a/website/content/docs/shortcodes/section/_index.md
+++ /dev/null
@@ -1,15 +0,0 @@
----
-bookCollapseSection: true
----
-
-# Section
-
-Section renders pages in section as definition list, using title and description.
-
-## Example
-
-```tpl
-{{* section */>}}
-```
-
-{{}}
diff --git a/website/content/docs/shortcodes/section/page1.md b/website/content/docs/shortcodes/section/page1.md
deleted file mode 100644
index 960800143..000000000
--- a/website/content/docs/shortcodes/section/page1.md
+++ /dev/null
@@ -1 +0,0 @@
-# Page 1
diff --git a/website/content/docs/shortcodes/section/page2.md b/website/content/docs/shortcodes/section/page2.md
deleted file mode 100644
index f310be332..000000000
--- a/website/content/docs/shortcodes/section/page2.md
+++ /dev/null
@@ -1 +0,0 @@
-# Page 2
diff --git a/website/content/docs/shortcodes/tabs.md b/website/content/docs/shortcodes/tabs.md
deleted file mode 100644
index 096892c67..000000000
--- a/website/content/docs/shortcodes/tabs.md
+++ /dev/null
@@ -1,50 +0,0 @@
-# Tabs
-
-Tabs let you organize content by context, for example installation instructions for each supported platform.
-
-```tpl
-{{* tabs "uniqueid" */>}}
-{{* tab "MacOS" */>}} # MacOS Content {{* /tab */>}}
-{{* tab "Linux" */>}} # Linux Content {{* /tab */>}}
-{{* tab "Windows" */>}} # Windows Content {{* /tab */>}}
-{{* /tabs */>}}
-```
-
-## Example
-
-{{< tabs "uniqueid" >}}
-{{< tab "MacOS" >}}
-# MacOS
-
-This is tab **MacOS** content.
-
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
-Miseratus fonte Ditis conubia.
-{{< /tab >}}
-
-{{< tab "Linux" >}}
-
-# Linux
-
-This is tab **Linux** content.
-
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
-Miseratus fonte Ditis conubia.
-{{< /tab >}}
-
-{{< tab "Windows" >}}
-
-# Windows
-
-This is tab **Windows** content.
-
-Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
-stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
-protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
-Miseratus fonte Ditis conubia.
-{{< /tab >}}
-{{< /tabs >}}
diff --git a/website/content/en/_index.md b/website/content/en/_index.md
new file mode 100644
index 000000000..2faff6432
--- /dev/null
+++ b/website/content/en/_index.md
@@ -0,0 +1,115 @@
+---
+header:
+ - type: typewriter
+ methods:
+ - typeString: Hello world!
+ - pauseFor: 2500
+ - deleteAll: true
+ - typeString: Strings can be removed
+ - pauseFor: 2500
+ - deleteChars: 7
+ - typeString: altered!
+ - pauseFor: 2500
+ options:
+ loop: true
+ autoStart: false
+ height: 190
+ paddingX: 50
+ align: center
+ fontSize: 44
+ fontColor: yellow
+
+ - type: text
+ height: 200
+ paddingX: 50
+ paddingY: 0
+ align: center
+ title:
+ - HUGO
+ subtitle:
+ - The world’s fastest framework for building websites
+ titleColor:
+ titleShadow: true
+ titleFontSize: 44
+ subtitleColor:
+ subtitleCursive: true
+ subtitleFontSize: 18
+ spaceBetweenTitleSubtitle: 16
+
+ - type: img
+ imageSrc: images/header/background.jpg
+ imageSize: cover
+ imageRepeat: no-repeat
+ imagePosition: center
+ height: 235
+ paddingX: 50
+ paddingY: 0
+ align: center
+ title:
+ -
+ subtitle:
+ -
+ titleColor:
+ titleShadow: false
+ titleFontSize: 44
+ subtitleColor:
+ subtitleCursive: false
+ subtitleFontSize: 16
+ spaceBetweenTitleSubtitle: 20
+
+ - type: slide
+ height: 235
+ options:
+ startSlide: 0
+ auto: 5000
+ draggable: true
+ autoRestart: true
+ continuous: true
+ disableScroll: true
+ stopPropagation: true
+ slide:
+ - paddingX: 50
+ paddingY: 0
+ align: left
+ imageSrc: images/header/background.jpg
+ imageSize: cover
+ imageRepeat: no-repeat
+ imagePosition: center
+ title:
+ - header title1
+ subtitle:
+ - header subtitle1
+ titleFontSize: 44
+ subtitleFontSize: 16
+ spaceBetweenTitleSubtitle: 20
+
+ - paddingX: 50
+ paddingY: 0
+ align: center
+ imageSrc: images/header/background.jpg
+ imageSize: cover
+ imageRepeat: no-repeat
+ imagePosition: center
+ title:
+ - header title2
+ subtitle:
+ - header subtitle2
+ titleFontSize: 44
+ subtitleFontSize: 16
+ spaceBetweenTitleSubtitle: 20
+
+ - paddingX: 50
+ paddingY: 0
+ align: right
+ imageSrc: images/header/background.jpg
+ imageSize: cover
+ imageRepeat: no-repeat
+ imagePosition: center
+ title:
+ - header title3
+ subtitle:
+ - header subtitle3
+ titleFontSize: 44
+ subtitleFontSize: 16
+ spaceBetweenTitleSubtitle: 20
+---
\ No newline at end of file
diff --git a/website/content/en/about/index.md b/website/content/en/about/index.md
new file mode 100644
index 000000000..182343f5f
--- /dev/null
+++ b/website/content/en/about/index.md
@@ -0,0 +1,27 @@
++++
+title = "About"
+description = "Hugo, the world’s fastest framework for building websites"
+type = "about"
+date = "2019-02-28"
++++
+
+Written in Go, Hugo is an open source static site generator available under the [Apache Licence 2.0.](https://github.com/gohugoio/hugo/blob/master/LICENSE) Hugo supports TOML, YAML and JSON data file types, Markdown and HTML content files and uses shortcodes to add rich content. Other notable features are taxonomies, multilingual mode, image processing, custom output formats, HTML/CSS/JS minification and support for Sass SCSS workflows.
+
+Hugo makes use of a variety of open source projects including:
+
+* https://github.com/russross/blackfriday
+* https://github.com/alecthomas/chroma
+* https://github.com/muesli/smartcrop
+* https://github.com/spf13/cobra
+* https://github.com/spf13/viper
+
+Hugo is ideal for blogs, corporate websites, creative portfolios, online magazines, single page applications or even a website with thousands of pages.
+
+Hugo is for people who want to hand code their own website without worrying about setting up complicated runtimes, dependencies and databases.
+
+Websites built with Hugo are extremelly fast, secure and can be deployed anywhere including, AWS, GitHub Pages, Heroku, Netlify and any other hosting provider.
+
+Learn more and contribute on [GitHub](https://github.com/gohugoio).
+
+
+
diff --git a/website/content/en/archive/_index.md b/website/content/en/archive/_index.md
new file mode 100644
index 000000000..acde72024
--- /dev/null
+++ b/website/content/en/archive/_index.md
@@ -0,0 +1,9 @@
+---
+title: "Archive"
+date: 2019-10-19T11:44:14+09:00
+type: "archive"
+description: Archive Page
+titleWrap: wrap
+---
+
+archive page
diff --git a/website/content/en/gallery/cartoon/index.md b/website/content/en/gallery/cartoon/index.md
new file mode 100644
index 000000000..23b8db215
--- /dev/null
+++ b/website/content/en/gallery/cartoon/index.md
@@ -0,0 +1,10 @@
+---
+title: "Cartoon"
+date: 2019-10-31T10:20:16+09:00
+type: "gallery"
+mode: "at-once" # at-once is a default value
+description: "cartoon gallery"
+image: images/feature2/bam.png
+---
+
+Sample images from [Pixabay](https://pixabay.com)
diff --git a/website/content/en/gallery/photo/index.md b/website/content/en/gallery/photo/index.md
new file mode 100644
index 000000000..14c484b46
--- /dev/null
+++ b/website/content/en/gallery/photo/index.md
@@ -0,0 +1,20 @@
+---
+title: Photo
+date: 2019-10-31T10:20:16+09:00
+description: Photo Gallery
+type: gallery
+mode: one-by-one
+description: "photo gallery"
+images:
+ - image: beach.jpg
+ caption: beach, women, car
+ - image: beautiful.jpg
+ caption: beautiful women
+ - image: people.jpg
+ caption: man
+ - image: child.jpg
+ caption: child
+image: images/feature2/gallery.png
+---
+
+Sample images from [Pixabay](https://pixabay.com)
diff --git a/website/content/en/posts/_index.md b/website/content/en/posts/_index.md
new file mode 100644
index 000000000..e0f80ce0e
--- /dev/null
+++ b/website/content/en/posts/_index.md
@@ -0,0 +1,7 @@
++++
+aliases = ["posts","articles","blog","showcase","docs"]
+title = "Posts"
+author = "Hugo Authors"
+tags = ["index"]
+description = "Post page"
++++
\ No newline at end of file
diff --git a/website/content/en/posts/emoji-support.md b/website/content/en/posts/emoji-support.md
new file mode 100644
index 000000000..1ce2e12e5
--- /dev/null
+++ b/website/content/en/posts/emoji-support.md
@@ -0,0 +1,56 @@
+---
+author: "Hugo Authors"
+title: "Emoji Support"
+date: 2019-12-16T12:00:06+09:00
+description: "Guide to emoji usage in Hugo"
+draft: false
+hideToc: false
+enableToc: true
+enableTocContent: false
+author: Kim
+authorEmoji: 👻
+tags:
+- emoji
+- gamoji
+- namoji
+- bamoji
+- amoji
+---
+
+Emoji can be enabled in a Hugo project in a number of ways.
+
+The [`emojify`](https://gohugo.io/functions/emojify/) function can be called directly in templates or [Inline Shortcodes](https://gohugo.io/templates/shortcode-templates/#inline-shortcodes).
+
+To enable emoji globally, set `enableEmoji` to `true` in your site’s [configuration](https://gohugo.io/getting-started/configuration/) and then you can type emoji shorthand codes directly in content files; e.g.
+
+
+
🙈:see_no_evil:🙉:hear_no_evil:🙊:speak_no_evil:
+
+
+The [Emoji cheat sheet](http://www.emoji-cheat-sheet.com/) is a useful reference for emoji shorthand codes.
+
+***
+
+**N.B.** The above steps enable Unicode Standard emoji characters and sequences in Hugo, however the rendering of these glyphs depends on the browser and the platform. To style the emoji you can either use a third party emoji font or a font stack; e.g.
+
+{{< highlight html >}}
+.emoji {
+font-family: Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols;
+}
+{{< /highlight >}}
+
+{{< css.inline >}}
+
+{{< /css.inline >}}
\ No newline at end of file
diff --git a/website/content/en/posts/markdown-syntax.md b/website/content/en/posts/markdown-syntax.md
new file mode 100644
index 000000000..5f8787e17
--- /dev/null
+++ b/website/content/en/posts/markdown-syntax.md
@@ -0,0 +1,151 @@
+---
+title: Markdown Syntax Guide
+date: 2019-12-20T12:00:06+09:00
+description: Sample article showcasing basic Markdown syntax and formatting for HTML elements.
+draft: false
+hideToc: false
+enableToc: true
+enableTocContent: true
+author: Choi
+authorEmoji: 🤖
+tags:
+- markdown
+- css
+- html
+- themes
+categories:
+- themes
+- syntax
+series:
+- Themes Guide
+image: images/feature1/markdown.png
+---
+
+This article offers a sample of basic Markdown syntax that can be used in Hugo content files, also it shows whether basic HTML elements are decorated with CSS in a Hugo theme.
+
+
+## Headings
+
+The following HTML `
`—`
` elements represent six levels of section headings. `
` is the highest section level while `
` is the lowest.
+
+# H1
+## H2
+### H3
+#### H4
+##### H5
+###### H6
+
+## Paragraph
+
+Xerum, quo qui aut unt expliquam qui dolut labo. Aque venitatiusda cum, voluptionse latur sitiae dolessi aut parist aut dollo enim qui voluptate ma dolestendit peritin re plis aut quas inctum laceat est volestemque commosa as cus endigna tectur, offic to cor sequas etum rerum idem sintibus eiur? Quianimin porecus evelectur, cum que nis nust voloribus ratem aut omnimi, sitatur? Quiatem. Nam, omnis sum am facea corem alique molestrunt et eos evelece arcillit ut aut eos eos nus, sin conecerem erum fuga. Ri oditatquam, ad quibus unda veliamenimin cusam et facea ipsamus es exerum sitate dolores editium rerore eost, temped molorro ratiae volorro te reribus dolorer sperchicium faceata tiustia prat.
+
+Itatur? Quiatae cullecum rem ent aut odis in re eossequodi nonsequ idebis ne sapicia is sinveli squiatum, core et que aut hariosam ex eat.
+
+## Blockquotes
+
+The blockquote element represents content that is quoted from another source, optionally with a citation which must be within a `footer` or `cite` element, and optionally with in-line changes such as annotations and abbreviations.
+
+#### Blockquote without attribution
+
+> Tiam, ad mint andaepu dandae nostion secatur sequo quae.
+> **Note** that you can use *Markdown syntax* within a blockquote.
+
+#### Blockquote with attribution
+
+> Don't communicate by sharing memory, share memory by communicating.
+> — Rob Pike[^1]
+
+
+[^1]: The above quote is excerpted from Rob Pike's [talk](https://www.youtube.com/watch?v=PAAkCSZUG1c) during Gopherfest, November 18, 2015.
+
+## Tables
+
+Tables aren't part of the core Markdown spec, but Hugo supports supports them out-of-the-box.
+
+ Name | Age
+--------|------
+ Bob | 27
+ Alice | 23
+
+#### Inline Markdown within tables
+
+| Inline | Markdown | In | Table |
+| ---------- | --------- | ----------------- | ---------- |
+| *italics* | **bold** | ~~strikethrough~~ | `code` |
+
+## Code Blocks
+
+#### Code block with backticks
+
+```
+html
+
+
+
+
+ Example HTML5 Document
+
+
+
Test
+
+
+```
+#### Code block indented with four spaces
+
+
+
+
+
+ Example HTML5 Document
+
+
+
Test
+
+
+
+#### Code block with Hugo's internal highlight shortcode
+{{< highlight html >}}
+
+
+
+
+ Example HTML5 Document
+
+
+
Test
+
+
+{{< /highlight >}}
+
+## List Types
+
+#### Ordered List
+
+1. First item
+2. Second item
+3. Third item
+
+#### Unordered List
+
+* List item
+* Another item
+* And another item
+
+#### Nested list
+
+* Item
+1. First Sub-item
+2. Second Sub-item
+
+## Other Elements — abbr, sub, sup, kbd, mark
+
+GIF is a bitmap image format.
+
+H2O
+
+Xn + Yn: Zn
+
+Press CTRL+ALT+Delete to end the session.
+
+Most salamanders are nocturnal, and hunt for insects, worms, and other small creatures.
+
diff --git a/website/content/en/posts/math-typesetting.md b/website/content/en/posts/math-typesetting.md
new file mode 100644
index 000000000..c0e0b3289
--- /dev/null
+++ b/website/content/en/posts/math-typesetting.md
@@ -0,0 +1,48 @@
+---
+author: Hugo Authors
+title: Math Typesetting
+date: 2019-12-17T12:00:06+09:00
+description: A brief guide to setup KaTeX
+draft: false
+hideToc: false
+enableToc: true
+enableTocContent: false
+author: Park
+authorEmoji: 👽
+libraries:
+- katex
+---
+
+{{< box >}}
+We need goldmark katex entension which is not yet we have:
+[https://github.com/gohugoio/hugo/issues/6544](https://github.com/gohugoio/hugo/issues/6544)
+{{< /box >}}
+
+Mathematical notation in a Hugo project can be enabled by using third party JavaScript libraries.
+
+
+In this example we will be using [KaTeX](https://katex.org/)
+
+- Create a partial under `/layouts/partials/math.html`
+- Within this partial reference the [Auto-render Extension](https://katex.org/docs/autorender.html) or host these scripts locally.
+- Include the partial in your templates like so:
+
+```
+{{ if or .Params.math .Site.Params.math }}
+{{ partial "math.html" . }}
+{{ end }}
+```
+- To enable KaTex globally set the parameter `math` to `true` in a project's configuration
+- To enable KaTex on a per page basis include the parameter `math: true` in content files.
+
+**Note:** Use the online reference of [Supported TeX Functions](https://katex.org/docs/supported.html)
+
+### Examples
+
+Inline math: $$ \varphi = \dfrac{1+\sqrt5}{2}= 1.6180339887… $$
+
+Block math:
+
+$$
+ \varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } }
+$$
\ No newline at end of file
diff --git a/website/content/en/posts/rich-content.md b/website/content/en/posts/rich-content.md
new file mode 100644
index 000000000..3e9173563
--- /dev/null
+++ b/website/content/en/posts/rich-content.md
@@ -0,0 +1,47 @@
+---
+title: "Rich Content"
+date: 2019-12-19T12:00:06+09:00
+description: "A brief description of Hugo Shortcodes"
+draft: false
+hideToc: false
+enableToc: true
+enableTocContent: false
+author: Lee
+authorEmoji: 👺
+tags:
+- shortcodes
+- privacy
+image: images/feature2/content.png
+---
+
+Hugo ships with several [Built-in Shortcodes](https://gohugo.io/content-management/shortcodes/#use-hugo-s-built-in-shortcodes) for rich content, along with a [Privacy Config](https://gohugo.io/about/hugo-and-gdpr/) and a set of Simple Shortcodes that enable static and no-JS versions of various social media embeds.
+
+---
+
+## Instagram Simple Shortcode
+
+{{< instagram_simple BGvuInzyFAe hidecaption >}}
+
+
+
+---
+
+## YouTube Privacy Enhanced Shortcode
+
+{{< youtube ZJthWmvUzzc >}}
+
+
+
+---
+
+## Twitter Simple Shortcode
+
+{{< twitter_simple 1085870671291310081 >}}
+
+
+
+---
+
+## Vimeo Simple Shortcode
+
+{{< vimeo_simple 48912912 >}}
diff --git a/website/content/en/posts/shortcodes.md b/website/content/en/posts/shortcodes.md
new file mode 100644
index 000000000..880f40f7b
--- /dev/null
+++ b/website/content/en/posts/shortcodes.md
@@ -0,0 +1,135 @@
+---
+title: "Shortcodes"
+date: 2020-01-25T06:40:51+09:00
+description: tabs, code-tabs, expand, alert, warning, notice, img, box
+draft: false
+hideToc: false
+enableToc: true
+enableTocContent: true
+tocPosition: inner
+tags:
+- shortcode
+series:
+-
+categories:
+-
+image: images/feature3/code-file.png
+---
+
+## Markdownify box
+
+{{< boxmd >}}
+This is **boxmd** shortcode
+{{< /boxmd >}}
+
+## Simple box
+
+{{< box >}}
+This is **box** shortcode
+{{< /box >}}
+
+## Code tabs
+
+Make it easy to switch between different code
+
+{{< codes java javascript >}}
+ {{< code >}}
+
+ ```java
+ System.out.println('Hello World!');
+ ```
+
+ {{< /code >}}
+
+ {{< code >}}
+
+ ```javascript
+ console.log('Hello World!');
+ ```
+
+ {{< /code >}}
+{{< /codes >}}
+
+## Tabs for general purpose
+
+{{< tabs Windows MacOS Ubuntu >}}
+ {{< tab >}}
+
+ ### Windows section
+
+ ```javascript
+ console.log('Hello World!');
+ ```
+
+ ⚠️Becareful that the content in the tab should be different from each other. The tab makes unique id hashes depending on the tab contents. So, If you just copy-paste the tabs with multiple times, since it has the same contents, the tab will not work.
+
+ {{< /tab >}}
+ {{< tab >}}
+
+ ### MacOS section
+
+ Hello world!
+ {{< /tab >}}
+ {{< tab >}}
+
+ ### Ubuntu section
+
+ Great!
+ {{< /tab >}}
+{{< /tabs >}}
+
+## Expand
+
+{{< expand "Expand me" >}}
+
+### Title
+
+contents
+
+{{< /expand >}}
+
+{{< expand "Expand me2" >}}
+
+### Title2
+
+contents2
+
+{{< /expand >}}
+
+## Alert
+
+Colored box
+
+{{< alert theme="warning" >}}
+**this** is a text
+{{< /alert >}}
+
+{{< alert theme="info" >}}
+**this** is a text
+{{< /alert >}}
+
+{{< alert theme="success" >}}
+**this** is a text
+{{< /alert >}}
+
+{{< alert theme="danger" >}}
+**this** is a text
+{{< /alert >}}
+
+## Notice
+
+{{< notice success >}}
+success text
+{{< /notice >}}
+
+{{< notice info >}}
+info text
+{{< /notice >}}
+
+{{< notice warning >}}
+warning text
+{{< /notice >}}
+
+{{< notice error >}}
+error text
+{{< /notice >}}
diff --git a/website/content/en/posts/syntax-highlight.md b/website/content/en/posts/syntax-highlight.md
new file mode 100644
index 000000000..c95f1f568
--- /dev/null
+++ b/website/content/en/posts/syntax-highlight.md
@@ -0,0 +1,326 @@
+---
+title: "Syntax highlighting"
+date: 2019-12-18T10:33:41+09:00
+description: "Syntax highlighting test"
+draft: false
+hideToc: false
+enableToc: true
+enableTocContent: false
+author: Jeus
+authorEmoji: 🎅
+pinned: true
+tags:
+- hugo
+series:
+-
+categories:
+- hugo
+image: images/feature2/color-palette.png
+---
+
+## Code Syntax Highlighting
+
+Verify the following code blocks render as code blocks and highlight properly.
+
+More about tuning syntax highlighting is the [Hugo documentation](https://gohugo.io/content-management/syntax-highlighting/).
+
+### Diff
+
+``` diff {hl_lines=[4,"6-7"]}
+*** /path/to/original ''timestamp''
+--- /path/to/new ''timestamp''
+***************
+*** 1 ****
+! This is a line.
+--- 1 ---
+! This is a replacement line.
+It is important to spell
+-removed line
++new line
+```
+
+```diff {hl_lines=[4,"6-7"], linenos=false}
+*** /path/to/original ''timestamp''
+--- /path/to/new ''timestamp''
+***************
+*** 1 ****
+! This is a line.
+--- 1 ---
+! This is a replacement line.
+It is important to spell
+-removed line
++new line
+```
+
+### Makefile
+
+``` makefile {linenos=false}
+CC=gcc
+CFLAGS=-I.
+
+hellomake: hellomake.o hellofunc.o
+ $(CC) -o hellomake hellomake.o hellofunc.o -I.
+```
+
+``` makefile
+CC=gcc
+CFLAGS=-I.
+
+hellomake: hellomake.o hellofunc.o
+ $(CC) -o hellomake hellomake.o hellofunc.o -I.
+```
+
+### JSON
+
+``` json
+{"employees":[
+ {"firstName":"John", "lastName":"Doe"},
+]}
+```
+
+### Markdown
+
+``` markdown
+**bold**
+*italics*
+[link](www.example.com)
+```
+
+### JavaScript
+
+``` javascript
+document.write('Hello, world!');
+```
+
+### CSS
+
+``` css
+body {
+ background-color: red;
+}
+```
+
+### Objective C
+
+``` objectivec
+#import
+
+int main (void)
+{
+ printf ("Hello world!\n");
+}
+```
+
+### Python
+
+``` python
+print "Hello, world!"
+```
+
+### XML
+
+``` xml
+
+
+ JohnDoe
+
+
+```
+
+### Perl
+
+``` perl
+print "Hello, World!\n";
+```
+
+### Bash
+
+``` bash
+echo "Hello World"
+```
+
+### PHP
+
+``` php
+ Hello World'; ?>
+```
+
+### CoffeeScript
+
+``` coffeescript
+console.log(“Hello world!”);
+```
+
+### C#
+
+``` cs
+using System;
+class Program
+{
+ public static void Main(string[] args)
+ {
+ Console.WriteLine("Hello, world!");
+ }
+}
+```
+
+### C++
+
+``` cpp
+#include
+
+main()
+{
+ cout << "Hello World!";
+ return 0;
+}
+```
+
+### SQL
+
+``` sql
+SELECT column_name,column_name
+FROM table_name;
+```
+
+### Go
+
+``` go
+package main
+import "fmt"
+func main() {
+ fmt.Println("Hello, 世界")
+}
+```
+
+### Ruby
+
+```ruby
+puts "Hello, world!"
+```
+
+### Java
+
+```java
+import javax.swing.JFrame; //Importing class JFrame
+import javax.swing.JLabel; //Importing class JLabel
+public class HelloWorld {
+ public static void main(String[] args) {
+ JFrame frame = new JFrame(); //Creating frame
+ frame.setTitle("Hi!"); //Setting title frame
+ frame.add(new JLabel("Hello, world!"));//Adding text to frame
+ frame.pack(); //Setting size to smallest
+ frame.setLocationRelativeTo(null); //Centering frame
+ frame.setVisible(true); //Showing frame
+ }
+}
+```
+
+### Latex Equation
+
+```latex
+\frac{d}{dx}\left( \int_{0}^{x} f(u)\,du\right)=f(x).
+```
+
+```javascript
+import {x, y} as p from 'point';
+const ANSWER = 42;
+
+class Car extends Vehicle {
+ constructor(speed, cost) {
+ super(speed);
+
+ var c = Symbol('cost');
+ this[c] = cost;
+
+ this.intro = `This is a car runs at
+ ${speed}.`;
+ }
+}
+
+for (let num of [1, 2, 3]) {
+ console.log(num + 0b111110111);
+}
+
+function $initHighlight(block, flags) {
+ try {
+ if (block.className.search(/\bno\-highlight\b/) != -1)
+ return processBlock(block.function, true, 0x0F) + ' class=""';
+ } catch (e) {
+ /* handle exception */
+ var e4x =
+