mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 01:44:56 +08:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
8796fe779f |
@ -0,0 +1,51 @@
|
||||
package leetcode
|
||||
|
||||
type ParkingSystem struct {
|
||||
Big int
|
||||
Medium int
|
||||
Small int
|
||||
}
|
||||
|
||||
func Constructor(big int, medium int, small int) ParkingSystem {
|
||||
return ParkingSystem{
|
||||
Big: big,
|
||||
Medium: medium,
|
||||
Small: small,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ParkingSystem) AddCar(carType int) bool {
|
||||
switch carType {
|
||||
case 1:
|
||||
{
|
||||
if this.Big > 0 {
|
||||
this.Big--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if this.Medium > 0 {
|
||||
this.Medium--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
if this.Small > 0 {
|
||||
this.Small--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Your ParkingSystem object will be instantiated and called as such:
|
||||
* obj := Constructor(big, medium, small);
|
||||
* param_1 := obj.AddCar(carType);
|
||||
*/
|
@ -0,0 +1,15 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Problem1603(t *testing.T) {
|
||||
obj := Constructor(1, 1, 0)
|
||||
fmt.Printf("obj = %v\n", obj)
|
||||
fmt.Printf("obj = %v\n", obj.AddCar(1))
|
||||
fmt.Printf("obj = %v\n", obj.AddCar(2))
|
||||
fmt.Printf("obj = %v\n", obj.AddCar(3))
|
||||
fmt.Printf("obj = %v\n", obj.AddCar(1))
|
||||
}
|
103
leetcode/1603.Design-Parking-System/README.md
Normal file
103
leetcode/1603.Design-Parking-System/README.md
Normal file
@ -0,0 +1,103 @@
|
||||
# [1603. Design Parking System](https://leetcode.com/problems/design-parking-system/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size.
|
||||
|
||||
Implement the `ParkingSystem` class:
|
||||
|
||||
- `ParkingSystem(int big, int medium, int small)` Initializes object of the `ParkingSystem` class. The number of slots for each parking space are given as part of the constructor.
|
||||
- `bool addCar(int carType)` Checks whether there is a parking space of `carType` for the car that wants to get into the parking lot. `carType` can be of three kinds: big, medium, or small, which are represented by `1`, `2`, and `3` respectively. **A car can only park in a parking space of its** `carType`. If there is no space available, return `false`, else park the car in that size space and return `true`.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input
|
||||
["ParkingSystem", "addCar", "addCar", "addCar", "addCar"]
|
||||
[[1, 1, 0], [1], [2], [3], [1]]
|
||||
Output
|
||||
[null, true, true, false, false]
|
||||
|
||||
Explanation
|
||||
ParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);
|
||||
parkingSystem.addCar(1); // return true because there is 1 available slot for a big car
|
||||
parkingSystem.addCar(2); // return true because there is 1 available slot for a medium car
|
||||
parkingSystem.addCar(3); // return false because there is no available slot for a small car
|
||||
parkingSystem.addCar(1); // return false because there is no available slot for a big car. It is already occupied.
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `0 <= big, medium, small <= 1000`
|
||||
- `carType` is `1`, `2`, or `3`
|
||||
- At most `1000` calls will be made to `addCar`
|
||||
|
||||
## 题目大意
|
||||
|
||||
请你给一个停车场设计一个停车系统。停车场总共有三种不同大小的车位:大,中和小,每种尺寸分别有固定数目的车位。
|
||||
|
||||
请你实现 ParkingSystem 类:
|
||||
|
||||
- ParkingSystem(int big, int medium, int small) 初始化 ParkingSystem 类,三个参数分别对应每种停车位的数目。
|
||||
- bool addCar(int carType) 检查是否有 carType 对应的停车位。 carType 有三种类型:大,中,小,分别用数字 1, 2 和 3 表示。一辆车只能停在 carType 对应尺寸的停车位中。如果没有空车位,请返回 false ,否则将该车停入车位并返回 true 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。分别用 3 个变量表示大,中和小车位。`addCar()` 判断这 3 个变量是否还有空车位即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
type ParkingSystem struct {
|
||||
Big int
|
||||
Medium int
|
||||
Small int
|
||||
}
|
||||
|
||||
func Constructor(big int, medium int, small int) ParkingSystem {
|
||||
return ParkingSystem{
|
||||
Big: big,
|
||||
Medium: medium,
|
||||
Small: small,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ParkingSystem) AddCar(carType int) bool {
|
||||
switch carType {
|
||||
case 1:
|
||||
{
|
||||
if this.Big > 0 {
|
||||
this.Big--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if this.Medium > 0 {
|
||||
this.Medium--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
if this.Small > 0 {
|
||||
this.Small--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Your ParkingSystem object will be instantiated and called as such:
|
||||
* obj := Constructor(big, medium, small);
|
||||
* param_1 := obj.AddCar(carType);
|
||||
*/
|
||||
```
|
@ -0,0 +1,18 @@
|
||||
package leetcode
|
||||
|
||||
import "sort"
|
||||
|
||||
func specialArray(nums []int) int {
|
||||
sort.Ints(nums)
|
||||
x := len(nums)
|
||||
for _, num := range nums {
|
||||
if num >= x {
|
||||
return x
|
||||
}
|
||||
x--
|
||||
if num >= x {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1608 struct {
|
||||
para1608
|
||||
ans1608
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1608 struct {
|
||||
nums []int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1608 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem1608(t *testing.T) {
|
||||
|
||||
qs := []question1608{
|
||||
|
||||
{
|
||||
para1608{[]int{3, 5}},
|
||||
ans1608{2},
|
||||
},
|
||||
|
||||
{
|
||||
para1608{[]int{0, 0}},
|
||||
ans1608{-1},
|
||||
},
|
||||
|
||||
{
|
||||
para1608{[]int{0, 4, 3, 0, 4}},
|
||||
ans1608{3},
|
||||
},
|
||||
|
||||
{
|
||||
para1608{[]int{3, 6, 7, 7, 0}},
|
||||
ans1608{-1},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1608------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1608, q.para1608
|
||||
fmt.Printf("【input】:%v 【output】:%v \n", p, specialArray(p.nums))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
# [1608. Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/)
|
||||
|
||||
## 题目
|
||||
|
||||
You are given an array `nums` of non-negative integers. `nums` is considered **special** if there exists a number `x` such that there are **exactly** `x` numbers in `nums` that are **greater than or equal to** `x`.
|
||||
|
||||
Notice that `x` **does not** have to be an element in `nums`.
|
||||
|
||||
Return `x` *if the array is **special**, otherwise, return* `-1`. It can be proven that if `nums` is special, the value for `x` is **unique**.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: nums = [3,5]
|
||||
Output: 2
|
||||
Explanation: There are 2 values (3 and 5) that are greater than or equal to 2.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: nums = [0,0]
|
||||
Output: -1
|
||||
Explanation: No numbers fit the criteria for x.
|
||||
If x = 0, there should be 0 numbers >= x, but there are 2.
|
||||
If x = 1, there should be 1 number >= x, but there are 0.
|
||||
If x = 2, there should be 2 numbers >= x, but there are 0.
|
||||
x cannot be greater since there are only 2 numbers in nums.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: nums = [0,4,3,0,4]
|
||||
Output: 3
|
||||
Explanation: There are 3 values that are greater than or equal to 3.
|
||||
```
|
||||
|
||||
**Example 4:**
|
||||
|
||||
```
|
||||
Input: nums = [3,6,7,7,0]
|
||||
Output: -1
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= nums.length <= 100`
|
||||
- `0 <= nums[i] <= 1000`
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个非负整数数组 nums 。如果存在一个数 x ,使得 nums 中恰好有 x 个元素 大于或者等于 x ,那么就称 nums 是一个 特殊数组 ,而 x 是该数组的 特征值 。(注意: x 不必 是 nums 的中的元素。)如果数组 nums 是一个 特殊数组 ,请返回它的特征值 x 。否则,返回 -1 。可以证明的是,如果 nums 是特殊数组,那么其特征值 x 是 唯一的 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。抓住题干中给的证明,特征值是唯一的。先将数组从小到大排序,下标的含义与特征值就等价了。下标 `i` 代表大于等于 `nums[i]` 的元素有 `len(nums) - i` 个,那么从第 0 个下标的元素开始遍历,如果这个元素都大于 `len(nums)`,那么后面 `len(nums)` 个元素也都大于等于它,特征值就找到了。如果特征值减一以后,仍然满足 `nums[i] >= x`,说明满足条件的值有多个,这一点不满足特征值唯一性,可以直接返回 -1 了。下标继续右移,特征值继续减一。如果最终循环结束依旧找不到特征值,返回 -1 。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
import "sort"
|
||||
|
||||
func specialArray(nums []int) int {
|
||||
sort.Ints(nums)
|
||||
x := len(nums)
|
||||
for _, num := range nums {
|
||||
if num >= x {
|
||||
return x
|
||||
}
|
||||
x--
|
||||
if num >= x {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
```
|
@ -0,0 +1,13 @@
|
||||
package leetcode
|
||||
|
||||
func countStudents(students []int, sandwiches []int) int {
|
||||
tmp, n, i := [2]int{}, len(students), 0
|
||||
for _, v := range students {
|
||||
tmp[v]++
|
||||
}
|
||||
for i < n && tmp[sandwiches[i]] > 0 {
|
||||
tmp[sandwiches[i]]--
|
||||
i++
|
||||
}
|
||||
return n - i
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1700 struct {
|
||||
para1700
|
||||
ans1700
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1700 struct {
|
||||
students []int
|
||||
sandwiches []int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1700 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem1700(t *testing.T) {
|
||||
|
||||
qs := []question1700{
|
||||
|
||||
{
|
||||
para1700{[]int{1, 1, 0, 0}, []int{0, 1, 0, 1}},
|
||||
ans1700{0},
|
||||
},
|
||||
|
||||
{
|
||||
para1700{[]int{1, 1, 1, 0, 0, 1}, []int{1, 0, 0, 0, 1, 1}},
|
||||
ans1700{3},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1700------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1700, q.para1700
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, countStudents(p.students, p.sandwiches))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
# [1700. Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers `0` and `1` respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.
|
||||
|
||||
The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a **stack**. At each step:
|
||||
|
||||
- If the student at the front of the queue **prefers** the sandwich on the top of the stack, they will **take it** and leave the queue.
|
||||
- Otherwise, they will **leave it** and go to the queue's end.
|
||||
|
||||
This continues until none of the queue students want to take the top sandwich and are thus unable to eat.
|
||||
|
||||
You are given two integer arrays `students` and `sandwiches` where `sandwiches[i]` is the type of the `ith` sandwich in the stack (`i = 0` is the top of the stack) and `students[j]` is the preference of the `jth` student in the initial queue (`j = 0` is the front of the queue). Return *the number of students that are unable to eat.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: students = [1,1,0,0], sandwiches = [0,1,0,1]
|
||||
Output: 0
|
||||
Explanation:
|
||||
- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].
|
||||
- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].
|
||||
- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].
|
||||
- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].
|
||||
- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].
|
||||
- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].
|
||||
- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].
|
||||
- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].
|
||||
Hence all students are able to eat.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]
|
||||
Output: 3
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= students.length, sandwiches.length <= 100`
|
||||
- `students.length == sandwiches.length`
|
||||
- `sandwiches[i]` is `0` or `1`.
|
||||
- `students[i]` is `0` or `1`.
|
||||
|
||||
## 题目大意
|
||||
|
||||
学校的自助午餐提供圆形和方形的三明治,分别用数字 0 和 1 表示。所有学生站在一个队列里,每个学生要么喜欢圆形的要么喜欢方形的。
|
||||
餐厅里三明治的数量与学生的数量相同。所有三明治都放在一个 栈 里,每一轮:
|
||||
|
||||
- 如果队列最前面的学生 喜欢 栈顶的三明治,那么会 拿走它 并离开队列。
|
||||
- 否则,这名学生会 放弃这个三明治 并回到队列的尾部。
|
||||
这个过程会一直持续到队列里所有学生都不喜欢栈顶的三明治为止。
|
||||
|
||||
给你两个整数数组 students 和 sandwiches ,其中 sandwiches[i] 是栈里面第 i 个三明治的类型(i = 0 是栈的顶部), students[j] 是初始队列里第 j 名学生对三明治的喜好(j = 0 是队列的最开始位置)。请你返回无法吃午餐的学生数量。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。按照题意,学生不管怎么轮流领三明治,如果数量够,经过多轮循环,总能领到。问题可以等价为,学生依次到队列前面领取三明治。2 个种类的三明治都摆好放在那里了。最终领不到三明治的学生都是因为喜欢的三明治不够发放了。按照这个思路,先统计 2 种三明治的总个数,然后减去学生对三明治的需求总数,剩下的学生即都是无法满足的。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func countStudents(students []int, sandwiches []int) int {
|
||||
tmp, n, i := [2]int{}, len(students), 0
|
||||
for _, v := range students {
|
||||
tmp[v]++
|
||||
}
|
||||
for i < n && tmp[sandwiches[i]] > 0 {
|
||||
tmp[sandwiches[i]]--
|
||||
i++
|
||||
}
|
||||
return n - i
|
||||
}
|
||||
```
|
@ -0,0 +1,20 @@
|
||||
package leetcode
|
||||
|
||||
import "sort"
|
||||
|
||||
func maximumUnits(boxTypes [][]int, truckSize int) int {
|
||||
sort.Slice(boxTypes, func(i, j int) bool {
|
||||
return boxTypes[i][1] > boxTypes[j][1]
|
||||
})
|
||||
res := 0
|
||||
for i := 0; truckSize > 0 && i < len(boxTypes); i++ {
|
||||
if truckSize >= boxTypes[i][0] {
|
||||
truckSize -= boxTypes[i][0]
|
||||
res += (boxTypes[i][1] * boxTypes[i][0])
|
||||
} else {
|
||||
res += (truckSize * boxTypes[i][1])
|
||||
truckSize = 0
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1710 struct {
|
||||
para1710
|
||||
ans1710
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1710 struct {
|
||||
boxTypes [][]int
|
||||
truckSize int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1710 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem1710(t *testing.T) {
|
||||
|
||||
qs := []question1710{
|
||||
|
||||
{
|
||||
para1710{[][]int{{1, 3}, {2, 2}, {3, 1}}, 4},
|
||||
ans1710{8},
|
||||
},
|
||||
|
||||
{
|
||||
para1710{[][]int{{5, 10}, {2, 5}, {4, 7}, {3, 9}}, 10},
|
||||
ans1710{91},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1710------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1710, q.para1710
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, maximumUnits(p.boxTypes, p.truckSize))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
77
leetcode/1710.Maximum-Units-on-a-Truck/README.md
Normal file
77
leetcode/1710.Maximum-Units-on-a-Truck/README.md
Normal file
@ -0,0 +1,77 @@
|
||||
# [1710. Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are assigned to put some amount of boxes onto **one truck**. You are given a 2D array `boxTypes`, where `boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]`:
|
||||
|
||||
- `numberOfBoxesi` is the number of boxes of type `i`.
|
||||
- `numberOfUnitsPerBoxi`is the number of units in each box of the type `i`.
|
||||
|
||||
You are also given an integer `truckSize`, which is the **maximum** number of **boxes** that can be put on the truck. You can choose any boxes to put on the truck as long as the number of boxes does not exceed `truckSize`.
|
||||
|
||||
Return *the **maximum** total number of **units** that can be put on the truck.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4
|
||||
Output: 8
|
||||
Explanation: There are:
|
||||
- 1 box of the first type that contains 3 units.
|
||||
- 2 boxes of the second type that contain 2 units each.
|
||||
- 3 boxes of the third type that contain 1 unit each.
|
||||
You can take all the boxes of the first and second types, and one box of the third type.
|
||||
The total number of units will be = (1 * 3) + (2 * 2) + (1 * 1) = 8.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: boxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10
|
||||
Output: 91
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= boxTypes.length <= 1000`
|
||||
- `1 <= numberOfBoxesi, numberOfUnitsPerBoxi <= 1000`
|
||||
- `1 <= truckSize <= 106`
|
||||
|
||||
## 题目大意
|
||||
|
||||
请你将一些箱子装在 一辆卡车 上。给你一个二维数组 boxTypes ,其中 boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi] :
|
||||
|
||||
- numberOfBoxesi 是类型 i 的箱子的数量。-
|
||||
- numberOfUnitsPerBoxi 是类型 i 每个箱子可以装载的单元数量。
|
||||
|
||||
整数 truckSize 表示卡车上可以装载 箱子 的 最大数量 。只要箱子数量不超过 truckSize ,你就可以选择任意箱子装到卡车上。返回卡车可以装载 单元 的 最大 总数。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。先将箱子按照单元数量从大到小排序。要想卡车装载单元数最大,那么需要尽量装单元数多的箱子。所以排序以后从单元数量多的箱子开始取。一直取至 truckSize 没有空间。累积的单元数即最大总数。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
import "sort"
|
||||
|
||||
func maximumUnits(boxTypes [][]int, truckSize int) int {
|
||||
sort.Slice(boxTypes, func(i, j int) bool {
|
||||
return boxTypes[i][1] > boxTypes[j][1]
|
||||
})
|
||||
res := 0
|
||||
for i := 0; truckSize > 0 && i < len(boxTypes); i++ {
|
||||
if truckSize >= boxTypes[i][0] {
|
||||
truckSize -= boxTypes[i][0]
|
||||
res += (boxTypes[i][1] * boxTypes[i][0])
|
||||
} else {
|
||||
res += (truckSize * boxTypes[i][1])
|
||||
truckSize = 0
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
```
|
@ -0,0 +1,13 @@
|
||||
package leetcode
|
||||
|
||||
func totalMoney(n int) int {
|
||||
res := 0
|
||||
for tmp, count := 1, 7; n > 0; tmp, count = tmp+1, 7 {
|
||||
for m := tmp; n > 0 && count > 0; m++ {
|
||||
res += m
|
||||
n--
|
||||
count--
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1716 struct {
|
||||
para1716
|
||||
ans1716
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1716 struct {
|
||||
n int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1716 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem1716(t *testing.T) {
|
||||
|
||||
qs := []question1716{
|
||||
|
||||
{
|
||||
para1716{4},
|
||||
ans1716{10},
|
||||
},
|
||||
|
||||
{
|
||||
para1716{10},
|
||||
ans1716{37},
|
||||
},
|
||||
|
||||
{
|
||||
para1716{20},
|
||||
ans1716{96},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1716------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1716, q.para1716
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, totalMoney(p.n))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
64
leetcode/1716.Calculate-Money-in-Leetcode-Bank/README.md
Normal file
64
leetcode/1716.Calculate-Money-in-Leetcode-Bank/README.md
Normal file
@ -0,0 +1,64 @@
|
||||
# [1716. Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
|
||||
|
||||
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
|
||||
|
||||
Given `n`, return *the total amount of money he will have in the Leetcode bank at the end of the* `nth` *day.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: n = 4
|
||||
Output: 10
|
||||
Explanation: After the 4th day, the total is 1 + 2 + 3 + 4 = 10.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: n = 10
|
||||
Output: 37
|
||||
Explanation: After the 10th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2nd Monday, Hercy only puts in $2.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: n = 20
|
||||
Output: 96
|
||||
Explanation: After the 20th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= n <= 1000`
|
||||
|
||||
## 题目大意
|
||||
|
||||
Hercy 想要为购买第一辆车存钱。他 每天 都往力扣银行里存钱。最开始,他在周一的时候存入 1 块钱。从周二到周日,他每天都比前一天多存入 1 块钱。在接下来每一个周一,他都会比 前一个周一 多存入 1 块钱。给你 n ,请你返回在第 n 天结束的时候他在力扣银行总共存了多少块钱。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。按照题意写 2 层循环即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func totalMoney(n int) int {
|
||||
res := 0
|
||||
for tmp, count := 1, 7; n > 0; tmp, count = tmp+1, 7 {
|
||||
for m := tmp; n > 0 && count > 0; m++ {
|
||||
res += m
|
||||
n--
|
||||
count--
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
```
|
10
leetcode/1720.Decode-XORed-Array/1720. Decode XORed Array.go
Normal file
10
leetcode/1720.Decode-XORed-Array/1720. Decode XORed Array.go
Normal file
@ -0,0 +1,10 @@
|
||||
package leetcode
|
||||
|
||||
func decode(encoded []int, first int) []int {
|
||||
arr := make([]int, len(encoded)+1)
|
||||
arr[0] = first
|
||||
for i, val := range encoded {
|
||||
arr[i+1] = arr[i] ^ val
|
||||
}
|
||||
return arr
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1720 struct {
|
||||
para1720
|
||||
ans1720
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1720 struct {
|
||||
encoded []int
|
||||
first int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1720 struct {
|
||||
one []int
|
||||
}
|
||||
|
||||
func Test_Problem1720(t *testing.T) {
|
||||
|
||||
qs := []question1720{
|
||||
|
||||
{
|
||||
para1720{[]int{1, 2, 3}, 1},
|
||||
ans1720{[]int{1, 0, 2, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
para1720{[]int{6, 2, 7, 3}, 4},
|
||||
ans1720{[]int{4, 2, 0, 7, 4}},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1720------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1720, q.para1720
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, decode(p.encoded, p.first))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
59
leetcode/1720.Decode-XORed-Array/README.md
Normal file
59
leetcode/1720.Decode-XORed-Array/README.md
Normal file
@ -0,0 +1,59 @@
|
||||
# [1720. Decode XORed Array](https://leetcode.com/problems/decode-xored-array/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
|
||||
|
||||
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
|
||||
|
||||
You are given the `encoded` array. You are also given an integer `first`, that is the first element of `arr`, i.e. `arr[0]`.
|
||||
|
||||
Return *the original array* `arr`. It can be proved that the answer exists and is unique.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: encoded = [1,2,3], first = 1
|
||||
Output: [1,0,2,1]
|
||||
Explanation: If arr = [1,0,2,1], then first = 1 and encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]
|
||||
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: encoded = [6,2,7,3], first = 4
|
||||
Output: [4,2,0,7,4]
|
||||
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `2 <= n <= 104`
|
||||
- `encoded.length == n - 1`
|
||||
- `0 <= encoded[i] <= 105`
|
||||
- `0 <= first <= 10^5`
|
||||
|
||||
## 题目大意
|
||||
|
||||
未知 整数数组 arr 由 n 个非负整数组成。经编码后变为长度为 n - 1 的另一个整数数组 encoded ,其中 encoded[i] = arr[i] XOR arr[i + 1] 。例如,arr = [1,0,2,1] 经编码后得到 encoded = [1,2,3] 。给你编码后的数组 encoded 和原数组 arr 的第一个元素 first(arr[0])。请解码返回原数组 arr 。可以证明答案存在并且是唯一的。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。按照题意,求返回解码以后的原数组,即将编码后的数组前后两两元素依次做异或 `XOR` 运算。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func decode(encoded []int, first int) []int {
|
||||
arr := make([]int, len(encoded)+1)
|
||||
arr[0] = first
|
||||
for i, val := range encoded {
|
||||
arr[i+1] = arr[i] ^ val
|
||||
}
|
||||
return arr
|
||||
}
|
||||
```
|
@ -0,0 +1,20 @@
|
||||
package leetcode
|
||||
|
||||
func countGoodRectangles(rectangles [][]int) int {
|
||||
minLength, count := 0, 0
|
||||
for i, _ := range rectangles {
|
||||
minSide := 0
|
||||
if rectangles[i][0] <= rectangles[i][1] {
|
||||
minSide = rectangles[i][0]
|
||||
} else {
|
||||
minSide = rectangles[i][1]
|
||||
}
|
||||
if minSide > minLength {
|
||||
minLength = minSide
|
||||
count = 1
|
||||
} else if minSide == minLength {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1725 struct {
|
||||
para1725
|
||||
ans1725
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1725 struct {
|
||||
rectangles [][]int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1725 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem1725(t *testing.T) {
|
||||
|
||||
qs := []question1725{
|
||||
|
||||
{
|
||||
para1725{[][]int{{5, 8}, {3, 9}, {5, 12}, {16, 5}}},
|
||||
ans1725{3},
|
||||
},
|
||||
|
||||
{
|
||||
para1725{[][]int{{2, 3}, {3, 7}, {4, 3}, {3, 7}}},
|
||||
ans1725{3},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1725------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1725, q.para1725
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, countGoodRectangles(p.rectangles))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
# [1725. Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are given an array `rectangles` where `rectangles[i] = [li, wi]` represents the `ith` rectangle of length `li` and width `wi`.
|
||||
|
||||
You can cut the `ith` rectangle to form a square with a side length of `k` if both `k <= li` and `k <= wi`. For example, if you have a rectangle `[4,6]`, you can cut it to get a square with a side length of at most `4`.
|
||||
|
||||
Let `maxLen` be the side length of the **largest** square you can obtain from any of the given rectangles.
|
||||
|
||||
Return *the **number** of rectangles that can make a square with a side length of* `maxLen`.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: rectangles = [[5,8],[3,9],[5,12],[16,5]]
|
||||
Output: 3
|
||||
Explanation: The largest squares you can get from each rectangle are of lengths [5,3,5,5].
|
||||
The largest possible square is of length 5, and you can get it out of 3 rectangles.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: rectangles = [[2,3],[3,7],[4,3],[3,7]]
|
||||
Output: 3
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= rectangles.length <= 1000`
|
||||
- `rectangles[i].length == 2`
|
||||
- `1 <= li, wi <= 10^9`
|
||||
- `li != wi`
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个数组 rectangles ,其中 rectangles[i] = [li, wi] 表示第 i 个矩形的长度为 li 、宽度为 wi 。如果存在 k 同时满足 k <= li 和 k <= wi ,就可以将第 i 个矩形切成边长为 k 的正方形。例如,矩形 [4,6] 可以切成边长最大为 4 的正方形。设 maxLen 为可以从矩形数组 rectangles 切分得到的 最大正方形 的边长。返回可以切出边长为 maxLen 的正方形的矩形 数目 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。扫描数组中的每一个矩形,先找到边长较小的那条边,作为正方形的边长。扫描过程中动态更新最大的正方形边长,并累加计数。循环一遍结束,输出最终计数值即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func countGoodRectangles(rectangles [][]int) int {
|
||||
minLength, count := 0, 0
|
||||
for i, _ := range rectangles {
|
||||
minSide := 0
|
||||
if rectangles[i][0] <= rectangles[i][1] {
|
||||
minSide = rectangles[i][0]
|
||||
} else {
|
||||
minSide = rectangles[i][1]
|
||||
}
|
||||
if minSide > minLength {
|
||||
minLength = minSide
|
||||
count = 1
|
||||
} else if minSide == minLength {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
```
|
@ -0,0 +1,12 @@
|
||||
package leetcode
|
||||
|
||||
func largestAltitude(gain []int) int {
|
||||
max, height := 0, 0
|
||||
for _, g := range gain {
|
||||
height += g
|
||||
if height > max {
|
||||
max = height
|
||||
}
|
||||
}
|
||||
return max
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1732 struct {
|
||||
para1732
|
||||
ans1732
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1732 struct {
|
||||
gain []int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1732 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem1732(t *testing.T) {
|
||||
|
||||
qs := []question1732{
|
||||
|
||||
{
|
||||
para1732{[]int{-5, 1, 5, 0, -7}},
|
||||
ans1732{1},
|
||||
},
|
||||
|
||||
{
|
||||
para1732{[]int{-4, -3, -2, -1, 4, 3, 2}},
|
||||
ans1732{0},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1732------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1732, q.para1732
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, largestAltitude(p.gain))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
55
leetcode/1732.Find-the-Highest-Altitude/README.md
Normal file
55
leetcode/1732.Find-the-Highest-Altitude/README.md
Normal file
@ -0,0 +1,55 @@
|
||||
# [1732. Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
There is a biker going on a road trip. The road trip consists of `n + 1` points at different altitudes. The biker starts his trip on point `0` with altitude equal `0`.
|
||||
|
||||
You are given an integer array `gain` of length `n` where `gain[i]` is the **net gain in altitude** between points `i` and `i + 1` for all (`0 <= i < n)`. Return *the **highest altitude** of a point.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: gain = [-5,1,5,0,-7]
|
||||
Output: 1
|
||||
Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: gain = [-4,-3,-2,-1,4,3,2]
|
||||
Output: 0
|
||||
Explanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `n == gain.length`
|
||||
- `1 <= n <= 100`
|
||||
- `100 <= gain[i] <= 100`
|
||||
|
||||
## 题目大意
|
||||
|
||||
有一个自行车手打算进行一场公路骑行,这条路线总共由 n + 1 个不同海拔的点组成。自行车手从海拔为 0 的点 0 开始骑行。给你一个长度为 n 的整数数组 gain ,其中 gain[i] 是点 i 和点 i + 1 的 净海拔高度差(0 <= i < n)。请你返回 最高点的海拔 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。循环数组依次从第一个海拔点开始还原每个海拔点,动态记录最大高度。循环结束输出最大高度即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func largestAltitude(gain []int) int {
|
||||
max, height := 0, 0
|
||||
for _, g := range gain {
|
||||
height += g
|
||||
if height > max {
|
||||
max = height
|
||||
}
|
||||
}
|
||||
return max
|
||||
}
|
||||
```
|
@ -0,0 +1,25 @@
|
||||
package leetcode
|
||||
|
||||
func maximumTime(time string) string {
|
||||
timeb := []byte(time)
|
||||
if timeb[3] == '?' {
|
||||
timeb[3] = '5'
|
||||
}
|
||||
if timeb[4] == '?' {
|
||||
timeb[4] = '9'
|
||||
}
|
||||
if timeb[0] == '?' {
|
||||
if int(timeb[1]-'0') > 3 && int(timeb[1]-'0') < 10 {
|
||||
timeb[0] = '1'
|
||||
} else {
|
||||
timeb[0] = '2'
|
||||
}
|
||||
}
|
||||
if timeb[1] == '?' {
|
||||
timeb[1] = '9'
|
||||
}
|
||||
if timeb[0] == '2' && timeb[1] == '9' {
|
||||
timeb[1] = '3'
|
||||
}
|
||||
return string(timeb)
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1736 struct {
|
||||
para1736
|
||||
ans1736
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1736 struct {
|
||||
time string
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1736 struct {
|
||||
one string
|
||||
}
|
||||
|
||||
func Test_Problem1736(t *testing.T) {
|
||||
|
||||
qs := []question1736{
|
||||
|
||||
{
|
||||
para1736{"2?:?0"},
|
||||
ans1736{"23:50"},
|
||||
},
|
||||
|
||||
{
|
||||
para1736{"0?:3?"},
|
||||
ans1736{"09:39"},
|
||||
},
|
||||
|
||||
{
|
||||
para1736{"1?:22"},
|
||||
ans1736{"19:22"},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1736------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1736, q.para1736
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, maximumTime(p.time))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
# [1736. Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are given a string `time` in the form of `hh:mm`, where some of the digits in the string are hidden (represented by `?`).
|
||||
|
||||
The valid times are those inclusively between `00:00` and `23:59`.
|
||||
|
||||
Return *the latest valid time you can get from* `time` *by replacing the hidden* *digits*.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: time = "2?:?0"
|
||||
Output: "23:50"
|
||||
Explanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: time = "0?:3?"
|
||||
Output: "09:39"
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: time = "1?:22"
|
||||
Output: "19:22"
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `time` is in the format `hh:mm`.
|
||||
- It is guaranteed that you can produce a valid time from the given string.
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个字符串 time ,格式为 hh:mm(小时:分钟),其中某几位数字被隐藏(用 ? 表示)。有效的时间为 00:00 到 23:59 之间的所有时间,包括 00:00 和 23:59 。替换 time 中隐藏的数字,返回你可以得到的最晚有效时间。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。根据题意,需要找到最晚的有效时间。枚举时间 4 个位置即可。如果第 3 个位置是 ?,那么它最晚时间是 5;如果第 4 个位置是 ?,那么它最晚时间是 9;如果第 2 个位置是 ?,那么它最晚时间是 9;如果第 1 个位置是 ?,根据第 2 个位置判断,如果第 2 个位置是大于 3 的数,那么第一个位置最晚时间是 1,如果第 2 个位置是小于 3 的数那么第一个位置最晚时间是 2 。按照上述规则即可还原最晚时间。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func maximumTime(time string) string {
|
||||
timeb := []byte(time)
|
||||
if timeb[3] == '?' {
|
||||
timeb[3] = '5'
|
||||
}
|
||||
if timeb[4] == '?' {
|
||||
timeb[4] = '9'
|
||||
}
|
||||
if timeb[0] == '?' {
|
||||
if int(timeb[1]-'0') > 3 && int(timeb[1]-'0') < 10 {
|
||||
timeb[0] = '1'
|
||||
} else {
|
||||
timeb[0] = '2'
|
||||
}
|
||||
}
|
||||
if timeb[1] == '?' {
|
||||
timeb[1] = '9'
|
||||
}
|
||||
if timeb[0] == '2' && timeb[1] == '9' {
|
||||
timeb[1] = '3'
|
||||
}
|
||||
return string(timeb)
|
||||
}
|
||||
```
|
@ -0,0 +1,17 @@
|
||||
package leetcode
|
||||
|
||||
func countBalls(lowLimit int, highLimit int) int {
|
||||
buckets, maxBall := [46]int{}, 0
|
||||
for i := lowLimit; i <= highLimit; i++ {
|
||||
t := 0
|
||||
for j := i; j > 0; {
|
||||
t += j % 10
|
||||
j = j / 10
|
||||
}
|
||||
buckets[t]++
|
||||
if buckets[t] > maxBall {
|
||||
maxBall = buckets[t]
|
||||
}
|
||||
}
|
||||
return maxBall
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1742 struct {
|
||||
para1742
|
||||
ans1742
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1742 struct {
|
||||
lowLimit int
|
||||
highLimit int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1742 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem1742(t *testing.T) {
|
||||
|
||||
qs := []question1742{
|
||||
|
||||
{
|
||||
para1742{1, 10},
|
||||
ans1742{2},
|
||||
},
|
||||
|
||||
{
|
||||
para1742{5, 15},
|
||||
ans1742{2},
|
||||
},
|
||||
|
||||
{
|
||||
para1742{19, 28},
|
||||
ans1742{2},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1742------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1742, q.para1742
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, countBalls(p.lowLimit, p.highLimit))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
81
leetcode/1742.Maximum-Number-of-Balls-in-a-Box/README.md
Normal file
81
leetcode/1742.Maximum-Number-of-Balls-in-a-Box/README.md
Normal file
@ -0,0 +1,81 @@
|
||||
# [1742. Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are working in a ball factory where you have `n` balls numbered from `lowLimit` up to `highLimit` **inclusive** (i.e., `n == highLimit - lowLimit + 1`), and an infinite number of boxes numbered from `1` to `infinity`.
|
||||
|
||||
Your job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's number. For example, the ball number `321` will be put in the box number `3 + 2 + 1 = 6` and the ball number `10` will be put in the box number `1 + 0 = 1`.
|
||||
|
||||
Given two integers `lowLimit` and `highLimit`, return *the number of balls in the box with the most balls.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: lowLimit = 1, highLimit = 10
|
||||
Output: 2
|
||||
Explanation:
|
||||
Box Number: 1 2 3 4 5 6 7 8 9 10 11 ...
|
||||
Ball Count: 2 1 1 1 1 1 1 1 1 0 0 ...
|
||||
Box 1 has the most number of balls with 2 balls.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: lowLimit = 5, highLimit = 15
|
||||
Output: 2
|
||||
Explanation:
|
||||
Box Number: 1 2 3 4 5 6 7 8 9 10 11 ...
|
||||
Ball Count: 1 1 1 1 2 2 1 1 1 0 0 ...
|
||||
Boxes 5 and 6 have the most number of balls with 2 balls in each.
|
||||
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: lowLimit = 19, highLimit = 28
|
||||
Output: 2
|
||||
Explanation:
|
||||
Box Number: 1 2 3 4 5 6 7 8 9 10 11 12 ...
|
||||
Ball Count: 0 1 1 1 1 1 1 1 1 2 0 0 ...
|
||||
Box 10 has the most number of balls with 2 balls.
|
||||
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= lowLimit <= highLimit <= 10^5`
|
||||
|
||||
## 题目大意
|
||||
|
||||
你在一家生产小球的玩具厂工作,有 n 个小球,编号从 lowLimit 开始,到 highLimit 结束(包括 lowLimit 和 highLimit ,即 n == highLimit - lowLimit + 1)。另有无限数量的盒子,编号从 1 到 infinity 。你的工作是将每个小球放入盒子中,其中盒子的编号应当等于小球编号上每位数字的和。例如,编号 321 的小球应当放入编号 3 + 2 + 1 = 6 的盒子,而编号 10 的小球应当放入编号 1 + 0 = 1 的盒子。
|
||||
|
||||
给你两个整数 lowLimit 和 highLimit ,返回放有最多小球的盒子中的小球数量。如果有多个盒子都满足放有最多小球,只需返回其中任一盒子的小球数量。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。循环遍历一遍数组,依次计算出所有小球的编号各位数字累加和,并且动态维护放有小球最多的数目。循环结束,输出最多小球个数即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func countBalls(lowLimit int, highLimit int) int {
|
||||
buckets, maxBall := [46]int{}, 0
|
||||
for i := lowLimit; i <= highLimit; i++ {
|
||||
t := 0
|
||||
for j := i; j > 0; {
|
||||
t += j % 10
|
||||
j = j / 10
|
||||
}
|
||||
buckets[t]++
|
||||
if buckets[t] > maxBall {
|
||||
maxBall = buckets[t]
|
||||
}
|
||||
}
|
||||
return maxBall
|
||||
}
|
||||
```
|
@ -0,0 +1,17 @@
|
||||
package leetcode
|
||||
|
||||
func sumOfUnique(nums []int) int {
|
||||
freq, res := make(map[int]int), 0
|
||||
for _, v := range nums {
|
||||
if _, ok := freq[v]; !ok {
|
||||
freq[v] = 0
|
||||
}
|
||||
freq[v]++
|
||||
}
|
||||
for k, v := range freq {
|
||||
if v == 1 {
|
||||
res += k
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1748 struct {
|
||||
para1748
|
||||
ans1748
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1748 struct {
|
||||
nums []int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1748 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem1748(t *testing.T) {
|
||||
|
||||
qs := []question1748{
|
||||
|
||||
{
|
||||
para1748{[]int{1, 2, 3, 2}},
|
||||
ans1748{4},
|
||||
},
|
||||
|
||||
{
|
||||
para1748{[]int{1, 1, 1, 1, 1}},
|
||||
ans1748{0},
|
||||
},
|
||||
|
||||
{
|
||||
para1748{[]int{1, 2, 3, 4, 5}},
|
||||
ans1748{15},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1748------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1748, q.para1748
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, sumOfUnique(p.nums))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
67
leetcode/1748.Sum-of-Unique-Elements/README.md
Normal file
67
leetcode/1748.Sum-of-Unique-Elements/README.md
Normal file
@ -0,0 +1,67 @@
|
||||
# [1748. Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are given an integer array `nums`. The unique elements of an array are the elements that appear **exactly once** in the array.
|
||||
|
||||
Return *the **sum** of all the unique elements of* `nums`.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: nums = [1,2,3,2]
|
||||
Output: 4
|
||||
Explanation: The unique elements are [1,3], and the sum is 4.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: nums = [1,1,1,1,1]
|
||||
Output: 0
|
||||
Explanation: There are no unique elements, and the sum is 0.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: nums = [1,2,3,4,5]
|
||||
Output: 15
|
||||
Explanation: The unique elements are [1,2,3,4,5], and the sum is 15.
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= nums.length <= 100`
|
||||
- `1 <= nums[i] <= 100`
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个整数数组 `nums` 。数组中唯一元素是那些只出现 **恰好一次** 的元素。请你返回 `nums` 中唯一元素的 **和** 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。利用 map 统计出每个元素出现的频次。再累加所有频次为 1 的元素,最后输出累加和即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func sumOfUnique(nums []int) int {
|
||||
freq, res := make(map[int]int), 0
|
||||
for _, v := range nums {
|
||||
if _, ok := freq[v]; !ok {
|
||||
freq[v] = 0
|
||||
}
|
||||
freq[v]++
|
||||
}
|
||||
for k, v := range freq {
|
||||
if v == 1 {
|
||||
res += k
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
```
|
@ -0,0 +1,14 @@
|
||||
package leetcode
|
||||
|
||||
func check(nums []int) bool {
|
||||
count := 0
|
||||
for i := 0; i < len(nums)-1; i++ {
|
||||
if nums[i] > nums[i+1] {
|
||||
count++
|
||||
if count > 1 || nums[0] < nums[len(nums)-1] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1752 struct {
|
||||
para1752
|
||||
ans1752
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1752 struct {
|
||||
nums []int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1752 struct {
|
||||
one bool
|
||||
}
|
||||
|
||||
func Test_Problem1752(t *testing.T) {
|
||||
|
||||
qs := []question1752{
|
||||
|
||||
{
|
||||
para1752{[]int{3, 4, 5, 1, 2}},
|
||||
ans1752{true},
|
||||
},
|
||||
|
||||
{
|
||||
para1752{[]int{2, 1, 3, 4}},
|
||||
ans1752{false},
|
||||
},
|
||||
|
||||
{
|
||||
para1752{[]int{1, 2, 3}},
|
||||
ans1752{true},
|
||||
},
|
||||
|
||||
{
|
||||
para1752{[]int{1, 1, 1}},
|
||||
ans1752{true},
|
||||
},
|
||||
|
||||
{
|
||||
para1752{[]int{2, 1}},
|
||||
ans1752{true},
|
||||
},
|
||||
|
||||
{
|
||||
para1752{[]int{1, 3, 2, 4}},
|
||||
ans1752{false},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1752------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1752, q.para1752
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, check(p.nums))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
86
leetcode/1752.Check-if-Array-Is-Sorted-and-Rotated/README.md
Normal file
86
leetcode/1752.Check-if-Array-Is-Sorted-and-Rotated/README.md
Normal file
@ -0,0 +1,86 @@
|
||||
# [1752. Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
Given an array `nums`, return `true` *if the array was originally sorted in non-decreasing order, then rotated **some** number of positions (including zero)*. Otherwise, return `false`.
|
||||
|
||||
There may be **duplicates** in the original array.
|
||||
|
||||
**Note:** An array `A` rotated by `x` positions results in an array `B` of the same length such that `A[i] == B[(i+x) % A.length]`, where `%` is the modulo operation.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: nums = [3,4,5,1,2]
|
||||
Output: true
|
||||
Explanation: [1,2,3,4,5] is the original sorted array.
|
||||
You can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2].
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: nums = [2,1,3,4]
|
||||
Output: false
|
||||
Explanation: There is no sorted array once rotated that can make nums.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: nums = [1,2,3]
|
||||
Output: true
|
||||
Explanation: [1,2,3] is the original sorted array.
|
||||
You can rotate the array by x = 0 positions (i.e. no rotation) to make nums.
|
||||
```
|
||||
|
||||
**Example 4:**
|
||||
|
||||
```
|
||||
Input: nums = [1,1,1]
|
||||
Output: true
|
||||
Explanation: [1,1,1] is the original sorted array.
|
||||
You can rotate any number of positions to make nums.
|
||||
```
|
||||
|
||||
**Example 5:**
|
||||
|
||||
```
|
||||
Input: nums = [2,1]
|
||||
Output: true
|
||||
Explanation: [1,2] is the original sorted array.
|
||||
You can rotate the array by x = 5 positions to begin on the element of value 2: [2,1].
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= nums.length <= 100`
|
||||
- `1 <= nums[i] <= 100`
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个数组 nums 。nums 的源数组中,所有元素与 nums 相同,但按非递减顺序排列。如果 nums 能够由源数组轮转若干位置(包括 0 个位置)得到,则返回 true ;否则,返回 false 。源数组中可能存在 重复项 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。从头扫描一遍数组,找出相邻两个元素递减的数对。如果递减的数对只有 1 个,则有可能是轮转得来的,超过 1 个,则返回 false。题干里面还提到可能有多个重复元素,针对这一情况还需要判断一下 `nums[0]` 和 `nums[len(nums)-1]` 。如果是相同元素,`nums[0] < nums[len(nums)-1]`,并且数组中间还存在一对递减的数对,这时候也是 false。判断好上述这 2 种情况,本题得解。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func check(nums []int) bool {
|
||||
count := 0
|
||||
for i := 0; i < len(nums)-1; i++ {
|
||||
if nums[i] > nums[i+1] {
|
||||
count++
|
||||
if count > 1 || nums[0] < nums[len(nums)-1] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
```
|
@ -0,0 +1,18 @@
|
||||
package leetcode
|
||||
|
||||
func minOperations(s string) int {
|
||||
res := 0
|
||||
for i := 0; i < len(s); i++ {
|
||||
if int(s[i]-'0') != i%2 {
|
||||
res++
|
||||
}
|
||||
}
|
||||
return min(res, len(s)-res)
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a > b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question1758 struct {
|
||||
para1758
|
||||
ans1758
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para1758 struct {
|
||||
s string
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans1758 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem1758(t *testing.T) {
|
||||
|
||||
qs := []question1758{
|
||||
|
||||
{
|
||||
para1758{"0100"},
|
||||
ans1758{1},
|
||||
},
|
||||
|
||||
{
|
||||
para1758{"10"},
|
||||
ans1758{0},
|
||||
},
|
||||
|
||||
{
|
||||
para1758{"1111"},
|
||||
ans1758{2},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 1758------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans1758, q.para1758
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, minOperations(p.s))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
# [1758. Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are given a string `s` consisting only of the characters `'0'` and `'1'`. In one operation, you can change any `'0'` to `'1'` or vice versa.
|
||||
|
||||
The string is called alternating if no two adjacent characters are equal. For example, the string `"010"` is alternating, while the string `"0100"` is not.
|
||||
|
||||
Return *the **minimum** number of operations needed to make* `s` *alternating*.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: s = "0100"
|
||||
Output: 1
|
||||
Explanation: If you change the last character to '1', s will be "0101", which is alternating.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: s = "10"
|
||||
Output: 0
|
||||
Explanation: s is already alternating.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: s = "1111"
|
||||
Output: 2
|
||||
Explanation: You need two operations to reach "0101" or "1010".
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= s.length <= 104`
|
||||
- `s[i]` is either `'0'` or `'1'`.
|
||||
|
||||
## 题目大意
|
||||
|
||||
你将得到一个仅包含字符“ 0”和“ 1”的字符串 `s`。 在一项操作中,你可以将任何 `'0'` 更改为 `'1'`,反之亦然。 如果两个相邻字符都不相等,则该字符串称为交替字符串。 例如,字符串“ 010”是交替的,而字符串“ 0100”则不是。 返回使 `s` 交替所需的最小操作数。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。利用数组下标奇偶交替性来判断交替字符串。交替字符串有 2 种,一个是 `'01010101……'` 还有一个是 `'1010101010……'`,这两个只需要计算出一个即可,另外一个利用 `len(s) - res` 就是答案。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func minOperations(s string) int {
|
||||
res := 0
|
||||
for i := 0; i < len(s); i++ {
|
||||
if int(s[i]-'0') != i%2 {
|
||||
res++
|
||||
}
|
||||
}
|
||||
return min(res, len(s)-res)
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a > b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
```
|
@ -106,5 +106,5 @@ func maxNumEdgesToRemove(n int, edges [][]int) int {
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1500~1599/1573.Number-of-Ways-to-Split-a-String/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1614.Maximum-Nesting-Depth-of-the-Parentheses/">下一页➡️</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1603.Design-Parking-System/">下一页➡️</a></p>
|
||||
</div>
|
||||
|
@ -0,0 +1,110 @@
|
||||
# [1603. Design Parking System](https://leetcode.com/problems/design-parking-system/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size.
|
||||
|
||||
Implement the `ParkingSystem` class:
|
||||
|
||||
- `ParkingSystem(int big, int medium, int small)` Initializes object of the `ParkingSystem` class. The number of slots for each parking space are given as part of the constructor.
|
||||
- `bool addCar(int carType)` Checks whether there is a parking space of `carType` for the car that wants to get into the parking lot. `carType` can be of three kinds: big, medium, or small, which are represented by `1`, `2`, and `3` respectively. **A car can only park in a parking space of its** `carType`. If there is no space available, return `false`, else park the car in that size space and return `true`.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input
|
||||
["ParkingSystem", "addCar", "addCar", "addCar", "addCar"]
|
||||
[[1, 1, 0], [1], [2], [3], [1]]
|
||||
Output
|
||||
[null, true, true, false, false]
|
||||
|
||||
Explanation
|
||||
ParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);
|
||||
parkingSystem.addCar(1); // return true because there is 1 available slot for a big car
|
||||
parkingSystem.addCar(2); // return true because there is 1 available slot for a medium car
|
||||
parkingSystem.addCar(3); // return false because there is no available slot for a small car
|
||||
parkingSystem.addCar(1); // return false because there is no available slot for a big car. It is already occupied.
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `0 <= big, medium, small <= 1000`
|
||||
- `carType` is `1`, `2`, or `3`
|
||||
- At most `1000` calls will be made to `addCar`
|
||||
|
||||
## 题目大意
|
||||
|
||||
请你给一个停车场设计一个停车系统。停车场总共有三种不同大小的车位:大,中和小,每种尺寸分别有固定数目的车位。
|
||||
|
||||
请你实现 ParkingSystem 类:
|
||||
|
||||
- ParkingSystem(int big, int medium, int small) 初始化 ParkingSystem 类,三个参数分别对应每种停车位的数目。
|
||||
- bool addCar(int carType) 检查是否有 carType 对应的停车位。 carType 有三种类型:大,中,小,分别用数字 1, 2 和 3 表示。一辆车只能停在 carType 对应尺寸的停车位中。如果没有空车位,请返回 false ,否则将该车停入车位并返回 true 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。分别用 3 个变量表示大,中和小车位。`addCar()` 判断这 3 个变量是否还有空车位即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
type ParkingSystem struct {
|
||||
Big int
|
||||
Medium int
|
||||
Small int
|
||||
}
|
||||
|
||||
func Constructor(big int, medium int, small int) ParkingSystem {
|
||||
return ParkingSystem{
|
||||
Big: big,
|
||||
Medium: medium,
|
||||
Small: small,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ParkingSystem) AddCar(carType int) bool {
|
||||
switch carType {
|
||||
case 1:
|
||||
{
|
||||
if this.Big > 0 {
|
||||
this.Big--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if this.Medium > 0 {
|
||||
this.Medium--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
if this.Small > 0 {
|
||||
this.Small--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Your ParkingSystem object will be instantiated and called as such:
|
||||
* obj := Constructor(big, medium, small);
|
||||
* param_1 := obj.AddCar(carType);
|
||||
*/
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1500~1599/1579.Remove-Max-Number-of-Edges-to-Keep-Graph-Fully-Traversable/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1608.Special-Array-With-X-Elements-Greater-Than-or-Equal-X/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,87 @@
|
||||
# [1608. Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/)
|
||||
|
||||
## 题目
|
||||
|
||||
You are given an array `nums` of non-negative integers. `nums` is considered **special** if there exists a number `x` such that there are **exactly** `x` numbers in `nums` that are **greater than or equal to** `x`.
|
||||
|
||||
Notice that `x` **does not** have to be an element in `nums`.
|
||||
|
||||
Return `x` *if the array is **special**, otherwise, return* `-1`. It can be proven that if `nums` is special, the value for `x` is **unique**.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: nums = [3,5]
|
||||
Output: 2
|
||||
Explanation: There are 2 values (3 and 5) that are greater than or equal to 2.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: nums = [0,0]
|
||||
Output: -1
|
||||
Explanation: No numbers fit the criteria for x.
|
||||
If x = 0, there should be 0 numbers >= x, but there are 2.
|
||||
If x = 1, there should be 1 number >= x, but there are 0.
|
||||
If x = 2, there should be 2 numbers >= x, but there are 0.
|
||||
x cannot be greater since there are only 2 numbers in nums.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: nums = [0,4,3,0,4]
|
||||
Output: 3
|
||||
Explanation: There are 3 values that are greater than or equal to 3.
|
||||
```
|
||||
|
||||
**Example 4:**
|
||||
|
||||
```
|
||||
Input: nums = [3,6,7,7,0]
|
||||
Output: -1
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= nums.length <= 100`
|
||||
- `0 <= nums[i] <= 1000`
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个非负整数数组 nums 。如果存在一个数 x ,使得 nums 中恰好有 x 个元素 大于或者等于 x ,那么就称 nums 是一个 特殊数组 ,而 x 是该数组的 特征值 。(注意: x 不必 是 nums 的中的元素。)如果数组 nums 是一个 特殊数组 ,请返回它的特征值 x 。否则,返回 -1 。可以证明的是,如果 nums 是特殊数组,那么其特征值 x 是 唯一的 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。抓住题干中给的证明,特征值是唯一的。先将数组从小到大排序,下标的含义与特征值就等价了。下标 `i` 代表大于等于 `nums[i]` 的元素有 `len(nums) - i` 个,那么从第 0 个下标的元素开始遍历,如果这个元素都大于 `len(nums)`,那么后面 `len(nums)` 个元素也都大于等于它,特征值就找到了。如果特征值减一以后,仍然满足 `nums[i] >= x`,说明满足条件的值有多个,这一点不满足特征值唯一性,可以直接返回 -1 了。下标继续右移,特征值继续减一。如果最终循环结束依旧找不到特征值,返回 -1 。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
import "sort"
|
||||
|
||||
func specialArray(nums []int) int {
|
||||
sort.Ints(nums)
|
||||
x := len(nums)
|
||||
for _, num := range nums {
|
||||
if num >= x {
|
||||
return x
|
||||
}
|
||||
x--
|
||||
if num >= x {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1603.Design-Parking-System/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1614.Maximum-Nesting-Depth-of-the-Parentheses/">下一页➡️</a></p>
|
||||
</div>
|
@ -104,6 +104,6 @@ func max(a, b int) int {
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1500~1599/1579.Remove-Max-Number-of-Edges-to-Keep-Graph-Fully-Traversable/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1608.Special-Array-With-X-Elements-Greater-Than-or-Equal-X/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1619.Mean-of-Array-After-Removing-Some-Elements/">下一页➡️</a></p>
|
||||
</div>
|
||||
|
@ -114,5 +114,5 @@ func max(a, b int) int {
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1695.Maximum-Erasure-Value/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1704.Determine-if-String-Halves-Are-Alike/">下一页➡️</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1700.Number-of-Students-Unable-to-Eat-Lunch/">下一页➡️</a></p>
|
||||
</div>
|
||||
|
@ -0,0 +1,86 @@
|
||||
# [1700. Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers `0` and `1` respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.
|
||||
|
||||
The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a **stack**. At each step:
|
||||
|
||||
- If the student at the front of the queue **prefers** the sandwich on the top of the stack, they will **take it** and leave the queue.
|
||||
- Otherwise, they will **leave it** and go to the queue's end.
|
||||
|
||||
This continues until none of the queue students want to take the top sandwich and are thus unable to eat.
|
||||
|
||||
You are given two integer arrays `students` and `sandwiches` where `sandwiches[i]` is the type of the `ith` sandwich in the stack (`i = 0` is the top of the stack) and `students[j]` is the preference of the `jth` student in the initial queue (`j = 0` is the front of the queue). Return *the number of students that are unable to eat.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: students = [1,1,0,0], sandwiches = [0,1,0,1]
|
||||
Output: 0
|
||||
Explanation:
|
||||
- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].
|
||||
- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].
|
||||
- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].
|
||||
- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].
|
||||
- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].
|
||||
- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].
|
||||
- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].
|
||||
- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].
|
||||
Hence all students are able to eat.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]
|
||||
Output: 3
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= students.length, sandwiches.length <= 100`
|
||||
- `students.length == sandwiches.length`
|
||||
- `sandwiches[i]` is `0` or `1`.
|
||||
- `students[i]` is `0` or `1`.
|
||||
|
||||
## 题目大意
|
||||
|
||||
学校的自助午餐提供圆形和方形的三明治,分别用数字 0 和 1 表示。所有学生站在一个队列里,每个学生要么喜欢圆形的要么喜欢方形的。
|
||||
餐厅里三明治的数量与学生的数量相同。所有三明治都放在一个 栈 里,每一轮:
|
||||
|
||||
- 如果队列最前面的学生 喜欢 栈顶的三明治,那么会 拿走它 并离开队列。
|
||||
- 否则,这名学生会 放弃这个三明治 并回到队列的尾部。
|
||||
这个过程会一直持续到队列里所有学生都不喜欢栈顶的三明治为止。
|
||||
|
||||
给你两个整数数组 students 和 sandwiches ,其中 sandwiches[i] 是栈里面第 i 个三明治的类型(i = 0 是栈的顶部), students[j] 是初始队列里第 j 名学生对三明治的喜好(j = 0 是队列的最开始位置)。请你返回无法吃午餐的学生数量。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。按照题意,学生不管怎么轮流领三明治,如果数量够,经过多轮循环,总能领到。问题可以等价为,学生依次到队列前面领取三明治。2 个种类的三明治都摆好放在那里了。最终领不到三明治的学生都是因为喜欢的三明治不够发放了。按照这个思路,先统计 2 种三明治的总个数,然后减去学生对三明治的需求总数,剩下的学生即都是无法满足的。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func countStudents(students []int, sandwiches []int) int {
|
||||
tmp, n, i := [2]int{}, len(students), 0
|
||||
for _, v := range students {
|
||||
tmp[v]++
|
||||
}
|
||||
for i < n && tmp[sandwiches[i]] > 0 {
|
||||
tmp[sandwiches[i]]--
|
||||
i++
|
||||
}
|
||||
return n - i
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1696.Jump-Game-VI/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1704.Determine-if-String-Halves-Are-Alike/">下一页➡️</a></p>
|
||||
</div>
|
@ -72,9 +72,10 @@ func numVowels(x string) int {
|
||||
}
|
||||
return res
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1600~1699/1696.Jump-Game-VI/">⬅️上一页</a></p>
|
||||
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1700.Number-of-Students-Unable-to-Eat-Lunch/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1710.Maximum-Units-on-a-Truck/">下一页➡️</a></p>
|
||||
</div>
|
||||
|
@ -0,0 +1,84 @@
|
||||
# [1710. Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are assigned to put some amount of boxes onto **one truck**. You are given a 2D array `boxTypes`, where `boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]`:
|
||||
|
||||
- `numberOfBoxesi` is the number of boxes of type `i`.
|
||||
- `numberOfUnitsPerBoxi`is the number of units in each box of the type `i`.
|
||||
|
||||
You are also given an integer `truckSize`, which is the **maximum** number of **boxes** that can be put on the truck. You can choose any boxes to put on the truck as long as the number of boxes does not exceed `truckSize`.
|
||||
|
||||
Return *the **maximum** total number of **units** that can be put on the truck.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4
|
||||
Output: 8
|
||||
Explanation: There are:
|
||||
- 1 box of the first type that contains 3 units.
|
||||
- 2 boxes of the second type that contain 2 units each.
|
||||
- 3 boxes of the third type that contain 1 unit each.
|
||||
You can take all the boxes of the first and second types, and one box of the third type.
|
||||
The total number of units will be = (1 * 3) + (2 * 2) + (1 * 1) = 8.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: boxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10
|
||||
Output: 91
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= boxTypes.length <= 1000`
|
||||
- `1 <= numberOfBoxesi, numberOfUnitsPerBoxi <= 1000`
|
||||
- `1 <= truckSize <= 106`
|
||||
|
||||
## 题目大意
|
||||
|
||||
请你将一些箱子装在 一辆卡车 上。给你一个二维数组 boxTypes ,其中 boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi] :
|
||||
|
||||
- numberOfBoxesi 是类型 i 的箱子的数量。-
|
||||
- numberOfUnitsPerBoxi 是类型 i 每个箱子可以装载的单元数量。
|
||||
|
||||
整数 truckSize 表示卡车上可以装载 箱子 的 最大数量 。只要箱子数量不超过 truckSize ,你就可以选择任意箱子装到卡车上。返回卡车可以装载 单元 的 最大 总数。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。先将箱子按照单元数量从大到小排序。要想卡车装载单元数最大,那么需要尽量装单元数多的箱子。所以排序以后从单元数量多的箱子开始取。一直取至 truckSize 没有空间。累积的单元数即最大总数。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
import "sort"
|
||||
|
||||
func maximumUnits(boxTypes [][]int, truckSize int) int {
|
||||
sort.Slice(boxTypes, func(i, j int) bool {
|
||||
return boxTypes[i][1] > boxTypes[j][1]
|
||||
})
|
||||
res := 0
|
||||
for i := 0; truckSize > 0 && i < len(boxTypes); i++ {
|
||||
if truckSize >= boxTypes[i][0] {
|
||||
truckSize -= boxTypes[i][0]
|
||||
res += (boxTypes[i][1] * boxTypes[i][0])
|
||||
} else {
|
||||
res += (truckSize * boxTypes[i][1])
|
||||
truckSize = 0
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1704.Determine-if-String-Halves-Are-Alike/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1716.Calculate-Money-in-Leetcode-Bank/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,71 @@
|
||||
# [1716. Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
Hercy wants to save money for his first car. He puts money in the Leetcode bank **every day**.
|
||||
|
||||
He starts by putting in `$1` on Monday, the first day. Every day from Tuesday to Sunday, he will put in `$1` more than the day before. On every subsequent Monday, he will put in `$1` more than the **previous Monday**.
|
||||
|
||||
Given `n`, return *the total amount of money he will have in the Leetcode bank at the end of the* `nth` *day.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: n = 4
|
||||
Output: 10
|
||||
Explanation: After the 4th day, the total is 1 + 2 + 3 + 4 = 10.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: n = 10
|
||||
Output: 37
|
||||
Explanation: After the 10th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2nd Monday, Hercy only puts in $2.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: n = 20
|
||||
Output: 96
|
||||
Explanation: After the 20th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= n <= 1000`
|
||||
|
||||
## 题目大意
|
||||
|
||||
Hercy 想要为购买第一辆车存钱。他 每天 都往力扣银行里存钱。最开始,他在周一的时候存入 1 块钱。从周二到周日,他每天都比前一天多存入 1 块钱。在接下来每一个周一,他都会比 前一个周一 多存入 1 块钱。给你 n ,请你返回在第 n 天结束的时候他在力扣银行总共存了多少块钱。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。按照题意写 2 层循环即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func totalMoney(n int) int {
|
||||
res := 0
|
||||
for tmp, count := 1, 7; n > 0; tmp, count = tmp+1, 7 {
|
||||
for m := tmp; n > 0 && count > 0; m++ {
|
||||
res += m
|
||||
n--
|
||||
count--
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1710.Maximum-Units-on-a-Truck/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1720.Decode-XORed-Array/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,66 @@
|
||||
# [1720. Decode XORed Array](https://leetcode.com/problems/decode-xored-array/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
There is a **hidden** integer array `arr` that consists of `n` non-negative integers.
|
||||
|
||||
It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = arr[i] XOR arr[i + 1]`. For example, if `arr = [1,0,2,1]`, then `encoded = [1,2,3]`.
|
||||
|
||||
You are given the `encoded` array. You are also given an integer `first`, that is the first element of `arr`, i.e. `arr[0]`.
|
||||
|
||||
Return *the original array* `arr`. It can be proved that the answer exists and is unique.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: encoded = [1,2,3], first = 1
|
||||
Output: [1,0,2,1]
|
||||
Explanation: If arr = [1,0,2,1], then first = 1 and encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]
|
||||
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: encoded = [6,2,7,3], first = 4
|
||||
Output: [4,2,0,7,4]
|
||||
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `2 <= n <= 104`
|
||||
- `encoded.length == n - 1`
|
||||
- `0 <= encoded[i] <= 105`
|
||||
- `0 <= first <= 10^5`
|
||||
|
||||
## 题目大意
|
||||
|
||||
未知 整数数组 arr 由 n 个非负整数组成。经编码后变为长度为 n - 1 的另一个整数数组 encoded ,其中 encoded[i] = arr[i] XOR arr[i + 1] 。例如,arr = [1,0,2,1] 经编码后得到 encoded = [1,2,3] 。给你编码后的数组 encoded 和原数组 arr 的第一个元素 first(arr[0])。请解码返回原数组 arr 。可以证明答案存在并且是唯一的。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。按照题意,求返回解码以后的原数组,即将编码后的数组前后两两元素依次做异或 `XOR` 运算。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func decode(encoded []int, first int) []int {
|
||||
arr := make([]int, len(encoded)+1)
|
||||
arr[0] = first
|
||||
for i, val := range encoded {
|
||||
arr[i+1] = arr[i] ^ val
|
||||
}
|
||||
return arr
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1716.Calculate-Money-in-Leetcode-Bank/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1725.Number-Of-Rectangles-That-Can-Form-The-Largest-Square/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,75 @@
|
||||
# [1725. Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are given an array `rectangles` where `rectangles[i] = [li, wi]` represents the `ith` rectangle of length `li` and width `wi`.
|
||||
|
||||
You can cut the `ith` rectangle to form a square with a side length of `k` if both `k <= li` and `k <= wi`. For example, if you have a rectangle `[4,6]`, you can cut it to get a square with a side length of at most `4`.
|
||||
|
||||
Let `maxLen` be the side length of the **largest** square you can obtain from any of the given rectangles.
|
||||
|
||||
Return *the **number** of rectangles that can make a square with a side length of* `maxLen`.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: rectangles = [[5,8],[3,9],[5,12],[16,5]]
|
||||
Output: 3
|
||||
Explanation: The largest squares you can get from each rectangle are of lengths [5,3,5,5].
|
||||
The largest possible square is of length 5, and you can get it out of 3 rectangles.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: rectangles = [[2,3],[3,7],[4,3],[3,7]]
|
||||
Output: 3
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= rectangles.length <= 1000`
|
||||
- `rectangles[i].length == 2`
|
||||
- `1 <= li, wi <= 10^9`
|
||||
- `li != wi`
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个数组 rectangles ,其中 rectangles[i] = [li, wi] 表示第 i 个矩形的长度为 li 、宽度为 wi 。如果存在 k 同时满足 k <= li 和 k <= wi ,就可以将第 i 个矩形切成边长为 k 的正方形。例如,矩形 [4,6] 可以切成边长最大为 4 的正方形。设 maxLen 为可以从矩形数组 rectangles 切分得到的 最大正方形 的边长。返回可以切出边长为 maxLen 的正方形的矩形 数目 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。扫描数组中的每一个矩形,先找到边长较小的那条边,作为正方形的边长。扫描过程中动态更新最大的正方形边长,并累加计数。循环一遍结束,输出最终计数值即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func countGoodRectangles(rectangles [][]int) int {
|
||||
minLength, count := 0, 0
|
||||
for i, _ := range rectangles {
|
||||
minSide := 0
|
||||
if rectangles[i][0] <= rectangles[i][1] {
|
||||
minSide = rectangles[i][0]
|
||||
} else {
|
||||
minSide = rectangles[i][1]
|
||||
}
|
||||
if minSide > minLength {
|
||||
minLength = minSide
|
||||
count = 1
|
||||
} else if minSide == minLength {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1720.Decode-XORed-Array/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1732.Find-the-Highest-Altitude/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,62 @@
|
||||
# [1732. Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
There is a biker going on a road trip. The road trip consists of `n + 1` points at different altitudes. The biker starts his trip on point `0` with altitude equal `0`.
|
||||
|
||||
You are given an integer array `gain` of length `n` where `gain[i]` is the **net gain in altitude** between points `i` and `i + 1` for all (`0 <= i < n)`. Return *the **highest altitude** of a point.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: gain = [-5,1,5,0,-7]
|
||||
Output: 1
|
||||
Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: gain = [-4,-3,-2,-1,4,3,2]
|
||||
Output: 0
|
||||
Explanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `n == gain.length`
|
||||
- `1 <= n <= 100`
|
||||
- `100 <= gain[i] <= 100`
|
||||
|
||||
## 题目大意
|
||||
|
||||
有一个自行车手打算进行一场公路骑行,这条路线总共由 n + 1 个不同海拔的点组成。自行车手从海拔为 0 的点 0 开始骑行。给你一个长度为 n 的整数数组 gain ,其中 gain[i] 是点 i 和点 i + 1 的 净海拔高度差(0 <= i < n)。请你返回 最高点的海拔 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。循环数组依次从第一个海拔点开始还原每个海拔点,动态记录最大高度。循环结束输出最大高度即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func largestAltitude(gain []int) int {
|
||||
max, height := 0, 0
|
||||
for _, g := range gain {
|
||||
height += g
|
||||
if height > max {
|
||||
max = height
|
||||
}
|
||||
}
|
||||
return max
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1725.Number-Of-Rectangles-That-Can-Form-The-Largest-Square/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1736.Latest-Time-by-Replacing-Hidden-Digits/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,82 @@
|
||||
# [1736. Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are given a string `time` in the form of `hh:mm`, where some of the digits in the string are hidden (represented by `?`).
|
||||
|
||||
The valid times are those inclusively between `00:00` and `23:59`.
|
||||
|
||||
Return *the latest valid time you can get from* `time` *by replacing the hidden* *digits*.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: time = "2?:?0"
|
||||
Output: "23:50"
|
||||
Explanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: time = "0?:3?"
|
||||
Output: "09:39"
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: time = "1?:22"
|
||||
Output: "19:22"
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `time` is in the format `hh:mm`.
|
||||
- It is guaranteed that you can produce a valid time from the given string.
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个字符串 time ,格式为 hh:mm(小时:分钟),其中某几位数字被隐藏(用 ? 表示)。有效的时间为 00:00 到 23:59 之间的所有时间,包括 00:00 和 23:59 。替换 time 中隐藏的数字,返回你可以得到的最晚有效时间。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。根据题意,需要找到最晚的有效时间。枚举时间 4 个位置即可。如果第 3 个位置是 ?,那么它最晚时间是 5;如果第 4 个位置是 ?,那么它最晚时间是 9;如果第 2 个位置是 ?,那么它最晚时间是 9;如果第 1 个位置是 ?,根据第 2 个位置判断,如果第 2 个位置是大于 3 的数,那么第一个位置最晚时间是 1,如果第 2 个位置是小于 3 的数那么第一个位置最晚时间是 2 。按照上述规则即可还原最晚时间。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func maximumTime(time string) string {
|
||||
timeb := []byte(time)
|
||||
if timeb[3] == '?' {
|
||||
timeb[3] = '5'
|
||||
}
|
||||
if timeb[4] == '?' {
|
||||
timeb[4] = '9'
|
||||
}
|
||||
if timeb[0] == '?' {
|
||||
if int(timeb[1]-'0') > 3 && int(timeb[1]-'0') < 10 {
|
||||
timeb[0] = '1'
|
||||
} else {
|
||||
timeb[0] = '2'
|
||||
}
|
||||
}
|
||||
if timeb[1] == '?' {
|
||||
timeb[1] = '9'
|
||||
}
|
||||
if timeb[0] == '2' && timeb[1] == '9' {
|
||||
timeb[1] = '3'
|
||||
}
|
||||
return string(timeb)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1732.Find-the-Highest-Altitude/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1742.Maximum-Number-of-Balls-in-a-Box/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,88 @@
|
||||
# [1742. Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are working in a ball factory where you have `n` balls numbered from `lowLimit` up to `highLimit` **inclusive** (i.e., `n == highLimit - lowLimit + 1`), and an infinite number of boxes numbered from `1` to `infinity`.
|
||||
|
||||
Your job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's number. For example, the ball number `321` will be put in the box number `3 + 2 + 1 = 6` and the ball number `10` will be put in the box number `1 + 0 = 1`.
|
||||
|
||||
Given two integers `lowLimit` and `highLimit`, return *the number of balls in the box with the most balls.*
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: lowLimit = 1, highLimit = 10
|
||||
Output: 2
|
||||
Explanation:
|
||||
Box Number: 1 2 3 4 5 6 7 8 9 10 11 ...
|
||||
Ball Count: 2 1 1 1 1 1 1 1 1 0 0 ...
|
||||
Box 1 has the most number of balls with 2 balls.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: lowLimit = 5, highLimit = 15
|
||||
Output: 2
|
||||
Explanation:
|
||||
Box Number: 1 2 3 4 5 6 7 8 9 10 11 ...
|
||||
Ball Count: 1 1 1 1 2 2 1 1 1 0 0 ...
|
||||
Boxes 5 and 6 have the most number of balls with 2 balls in each.
|
||||
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: lowLimit = 19, highLimit = 28
|
||||
Output: 2
|
||||
Explanation:
|
||||
Box Number: 1 2 3 4 5 6 7 8 9 10 11 12 ...
|
||||
Ball Count: 0 1 1 1 1 1 1 1 1 2 0 0 ...
|
||||
Box 10 has the most number of balls with 2 balls.
|
||||
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= lowLimit <= highLimit <= 10^5`
|
||||
|
||||
## 题目大意
|
||||
|
||||
你在一家生产小球的玩具厂工作,有 n 个小球,编号从 lowLimit 开始,到 highLimit 结束(包括 lowLimit 和 highLimit ,即 n == highLimit - lowLimit + 1)。另有无限数量的盒子,编号从 1 到 infinity 。你的工作是将每个小球放入盒子中,其中盒子的编号应当等于小球编号上每位数字的和。例如,编号 321 的小球应当放入编号 3 + 2 + 1 = 6 的盒子,而编号 10 的小球应当放入编号 1 + 0 = 1 的盒子。
|
||||
|
||||
给你两个整数 lowLimit 和 highLimit ,返回放有最多小球的盒子中的小球数量。如果有多个盒子都满足放有最多小球,只需返回其中任一盒子的小球数量。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。循环遍历一遍数组,依次计算出所有小球的编号各位数字累加和,并且动态维护放有小球最多的数目。循环结束,输出最多小球个数即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func countBalls(lowLimit int, highLimit int) int {
|
||||
buckets, maxBall := [46]int{}, 0
|
||||
for i := lowLimit; i <= highLimit; i++ {
|
||||
t := 0
|
||||
for j := i; j > 0; {
|
||||
t += j % 10
|
||||
j = j / 10
|
||||
}
|
||||
buckets[t]++
|
||||
if buckets[t] > maxBall {
|
||||
maxBall = buckets[t]
|
||||
}
|
||||
}
|
||||
return maxBall
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1736.Latest-Time-by-Replacing-Hidden-Digits/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1748.Sum-of-Unique-Elements/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,74 @@
|
||||
# [1748. Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are given an integer array `nums`. The unique elements of an array are the elements that appear **exactly once** in the array.
|
||||
|
||||
Return *the **sum** of all the unique elements of* `nums`.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: nums = [1,2,3,2]
|
||||
Output: 4
|
||||
Explanation: The unique elements are [1,3], and the sum is 4.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: nums = [1,1,1,1,1]
|
||||
Output: 0
|
||||
Explanation: There are no unique elements, and the sum is 0.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: nums = [1,2,3,4,5]
|
||||
Output: 15
|
||||
Explanation: The unique elements are [1,2,3,4,5], and the sum is 15.
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= nums.length <= 100`
|
||||
- `1 <= nums[i] <= 100`
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个整数数组 `nums` 。数组中唯一元素是那些只出现 **恰好一次** 的元素。请你返回 `nums` 中唯一元素的 **和** 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。利用 map 统计出每个元素出现的频次。再累加所有频次为 1 的元素,最后输出累加和即可。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func sumOfUnique(nums []int) int {
|
||||
freq, res := make(map[int]int), 0
|
||||
for _, v := range nums {
|
||||
if _, ok := freq[v]; !ok {
|
||||
freq[v] = 0
|
||||
}
|
||||
freq[v]++
|
||||
}
|
||||
for k, v := range freq {
|
||||
if v == 1 {
|
||||
res += k
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1742.Maximum-Number-of-Balls-in-a-Box/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1752.Check-if-Array-Is-Sorted-and-Rotated/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,93 @@
|
||||
# [1752. Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
Given an array `nums`, return `true` *if the array was originally sorted in non-decreasing order, then rotated **some** number of positions (including zero)*. Otherwise, return `false`.
|
||||
|
||||
There may be **duplicates** in the original array.
|
||||
|
||||
**Note:** An array `A` rotated by `x` positions results in an array `B` of the same length such that `A[i] == B[(i+x) % A.length]`, where `%` is the modulo operation.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: nums = [3,4,5,1,2]
|
||||
Output: true
|
||||
Explanation: [1,2,3,4,5] is the original sorted array.
|
||||
You can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2].
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: nums = [2,1,3,4]
|
||||
Output: false
|
||||
Explanation: There is no sorted array once rotated that can make nums.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: nums = [1,2,3]
|
||||
Output: true
|
||||
Explanation: [1,2,3] is the original sorted array.
|
||||
You can rotate the array by x = 0 positions (i.e. no rotation) to make nums.
|
||||
```
|
||||
|
||||
**Example 4:**
|
||||
|
||||
```
|
||||
Input: nums = [1,1,1]
|
||||
Output: true
|
||||
Explanation: [1,1,1] is the original sorted array.
|
||||
You can rotate any number of positions to make nums.
|
||||
```
|
||||
|
||||
**Example 5:**
|
||||
|
||||
```
|
||||
Input: nums = [2,1]
|
||||
Output: true
|
||||
Explanation: [1,2] is the original sorted array.
|
||||
You can rotate the array by x = 5 positions to begin on the element of value 2: [2,1].
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= nums.length <= 100`
|
||||
- `1 <= nums[i] <= 100`
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个数组 nums 。nums 的源数组中,所有元素与 nums 相同,但按非递减顺序排列。如果 nums 能够由源数组轮转若干位置(包括 0 个位置)得到,则返回 true ;否则,返回 false 。源数组中可能存在 重复项 。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。从头扫描一遍数组,找出相邻两个元素递减的数对。如果递减的数对只有 1 个,则有可能是轮转得来的,超过 1 个,则返回 false。题干里面还提到可能有多个重复元素,针对这一情况还需要判断一下 `nums[0]` 和 `nums[len(nums)-1]` 。如果是相同元素,`nums[0] < nums[len(nums)-1]`,并且数组中间还存在一对递减的数对,这时候也是 false。判断好上述这 2 种情况,本题得解。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func check(nums []int) bool {
|
||||
count := 0
|
||||
for i := 0; i < len(nums)-1; i++ {
|
||||
if nums[i] > nums[i+1] {
|
||||
count++
|
||||
if count > 1 || nums[0] < nums[len(nums)-1] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1748.Sum-of-Unique-Elements/">⬅️上一页</a></p>
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1758.Minimum-Changes-To-Make-Alternating-Binary-String/">下一页➡️</a></p>
|
||||
</div>
|
@ -0,0 +1,75 @@
|
||||
# [1758. Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
You are given a string `s` consisting only of the characters `'0'` and `'1'`. In one operation, you can change any `'0'` to `'1'` or vice versa.
|
||||
|
||||
The string is called alternating if no two adjacent characters are equal. For example, the string `"010"` is alternating, while the string `"0100"` is not.
|
||||
|
||||
Return *the **minimum** number of operations needed to make* `s` *alternating*.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: s = "0100"
|
||||
Output: 1
|
||||
Explanation: If you change the last character to '1', s will be "0101", which is alternating.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: s = "10"
|
||||
Output: 0
|
||||
Explanation: s is already alternating.
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: s = "1111"
|
||||
Output: 2
|
||||
Explanation: You need two operations to reach "0101" or "1010".
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= s.length <= 104`
|
||||
- `s[i]` is either `'0'` or `'1'`.
|
||||
|
||||
## 题目大意
|
||||
|
||||
你将得到一个仅包含字符“ 0”和“ 1”的字符串 `s`。 在一项操作中,你可以将任何 `'0'` 更改为 `'1'`,反之亦然。 如果两个相邻字符都不相等,则该字符串称为交替字符串。 例如,字符串“ 010”是交替的,而字符串“ 0100”则不是。 返回使 `s` 交替所需的最小操作数。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题。利用数组下标奇偶交替性来判断交替字符串。交替字符串有 2 种,一个是 `'01010101……'` 还有一个是 `'1010101010……'`,这两个只需要计算出一个即可,另外一个利用 `len(s) - res` 就是答案。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
package leetcode
|
||||
|
||||
func minOperations(s string) int {
|
||||
res := 0
|
||||
for i := 0; i < len(s); i++ {
|
||||
if int(s[i]-'0') != i%2 {
|
||||
res++
|
||||
}
|
||||
}
|
||||
return min(res, len(s)-res)
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a > b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/1700~1799/1752.Check-if-Array-Is-Sorted-and-Rotated/">⬅️上一页</a></p>
|
||||
|
@ -11,7 +11,7 @@ weight: 1
|
||||
|0001|Two Sum|[Go]({{< relref "/ChapterFour/0001~0099/0001.Two-Sum.md" >}})|Easy| O(n)| O(n)||46.4%|
|
||||
|0004|Median of Two Sorted Arrays|[Go]({{< relref "/ChapterFour/0001~0099/0004.Median-of-Two-Sorted-Arrays.md" >}})|Hard||||31.0%|
|
||||
|0011|Container With Most Water|[Go]({{< relref "/ChapterFour/0001~0099/0011.Container-With-Most-Water.md" >}})|Medium| O(n)| O(1)||52.4%|
|
||||
|0015|3Sum|[Go]({{< relref "/ChapterFour/0001~0099/0015.3Sum.md" >}})|Medium| O(n^2)| O(n)|❤️|27.9%|
|
||||
|0015|3Sum|[Go]({{< relref "/ChapterFour/0001~0099/0015.3Sum.md" >}})|Medium| O(n^2)| O(n)|❤️|28.0%|
|
||||
|0016|3Sum Closest|[Go]({{< relref "/ChapterFour/0001~0099/0016.3Sum-Closest.md" >}})|Medium| O(n^2)| O(1)|❤️|46.3%|
|
||||
|0018|4Sum|[Go]({{< relref "/ChapterFour/0001~0099/0018.4Sum.md" >}})|Medium| O(n^3)| O(n^2)|❤️|34.8%|
|
||||
|0026|Remove Duplicates from Sorted Array|[Go]({{< relref "/ChapterFour/0001~0099/0026.Remove-Duplicates-from-Sorted-Array.md" >}})|Easy| O(n)| O(1)||46.5%|
|
||||
@ -23,7 +23,7 @@ weight: 1
|
||||
|0039|Combination Sum|[Go]({{< relref "/ChapterFour/0001~0099/0039.Combination-Sum.md" >}})|Medium| O(n log n)| O(n)||59.1%|
|
||||
|0040|Combination Sum II|[Go]({{< relref "/ChapterFour/0001~0099/0040.Combination-Sum-II.md" >}})|Medium| O(n log n)| O(n)||50.0%|
|
||||
|0041|First Missing Positive|[Go]({{< relref "/ChapterFour/0001~0099/0041.First-Missing-Positive.md" >}})|Hard| O(n)| O(n)||33.6%|
|
||||
|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0001~0099/0042.Trapping-Rain-Water.md" >}})|Hard| O(n)| O(1)|❤️|51.0%|
|
||||
|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0001~0099/0042.Trapping-Rain-Water.md" >}})|Hard| O(n)| O(1)|❤️|51.1%|
|
||||
|0048|Rotate Image|[Go]({{< relref "/ChapterFour/0001~0099/0048.Rotate-Image.md" >}})|Medium| O(n)| O(1)||59.8%|
|
||||
|0053|Maximum Subarray|[Go]({{< relref "/ChapterFour/0001~0099/0053.Maximum-Subarray.md" >}})|Easy| O(n)| O(n)||47.7%|
|
||||
|0054|Spiral Matrix|[Go]({{< relref "/ChapterFour/0001~0099/0054.Spiral-Matrix.md" >}})|Medium| O(n)| O(n^2)||35.9%|
|
||||
@ -35,7 +35,7 @@ weight: 1
|
||||
|0063|Unique Paths II|[Go]({{< relref "/ChapterFour/0001~0099/0063.Unique-Paths-II.md" >}})|Medium| O(n^2)| O(n^2)||35.2%|
|
||||
|0064|Minimum Path Sum|[Go]({{< relref "/ChapterFour/0001~0099/0064.Minimum-Path-Sum.md" >}})|Medium| O(n^2)| O(n^2)||56.1%|
|
||||
|0066|Plus One|[Go]({{< relref "/ChapterFour/0001~0099/0066.Plus-One.md" >}})|Easy||||42.3%|
|
||||
|0074|Search a 2D Matrix|[Go]({{< relref "/ChapterFour/0001~0099/0074.Search-a-2D-Matrix.md" >}})|Medium||||37.6%|
|
||||
|0074|Search a 2D Matrix|[Go]({{< relref "/ChapterFour/0001~0099/0074.Search-a-2D-Matrix.md" >}})|Medium||||37.7%|
|
||||
|0075|Sort Colors|[Go]({{< relref "/ChapterFour/0001~0099/0075.Sort-Colors.md" >}})|Medium| O(n)| O(1)|❤️|49.3%|
|
||||
|0078|Subsets|[Go]({{< relref "/ChapterFour/0001~0099/0078.Subsets.md" >}})|Medium| O(n^2)| O(n)|❤️|64.9%|
|
||||
|0079|Word Search|[Go]({{< relref "/ChapterFour/0001~0099/0079.Word-Search.md" >}})|Medium| O(n^2)| O(n^2)|❤️|36.7%|
|
||||
@ -101,7 +101,7 @@ weight: 1
|
||||
|0891|Sum of Subsequence Widths|[Go]({{< relref "/ChapterFour/0800~0899/0891.Sum-of-Subsequence-Widths.md" >}})|Hard| O(n log n)| O(1)||33.0%|
|
||||
|0896|Monotonic Array|[Go]({{< relref "/ChapterFour/0800~0899/0896.Monotonic-Array.md" >}})|Easy||||58.0%|
|
||||
|0907|Sum of Subarray Minimums|[Go]({{< relref "/ChapterFour/0900~0999/0907.Sum-of-Subarray-Minimums.md" >}})|Medium| O(n)| O(n)|❤️|33.1%|
|
||||
|0914|X of a Kind in a Deck of Cards|[Go]({{< relref "/ChapterFour/0900~0999/0914.X-of-a-Kind-in-a-Deck-of-Cards.md" >}})|Easy||||34.3%|
|
||||
|0914|X of a Kind in a Deck of Cards|[Go]({{< relref "/ChapterFour/0900~0999/0914.X-of-a-Kind-in-a-Deck-of-Cards.md" >}})|Easy||||34.2%|
|
||||
|0918|Maximum Sum Circular Subarray|[Go]({{< relref "/ChapterFour/0900~0999/0918.Maximum-Sum-Circular-Subarray.md" >}})|Medium||||34.2%|
|
||||
|0922|Sort Array By Parity II|[Go]({{< relref "/ChapterFour/0900~0999/0922.Sort-Array-By-Parity-II.md" >}})|Easy| O(n)| O(1)||70.5%|
|
||||
|0969|Pancake Sorting|[Go]({{< relref "/ChapterFour/0900~0999/0969.Pancake-Sorting.md" >}})|Medium| O(n)| O(1)|❤️|68.6%|
|
||||
@ -120,7 +120,7 @@ weight: 1
|
||||
|1089|Duplicate Zeros|[Go]({{< relref "/ChapterFour/1000~1099/1089.Duplicate-Zeros.md" >}})|Easy||||51.9%|
|
||||
|1122|Relative Sort Array|[Go]({{< relref "/ChapterFour/1100~1199/1122.Relative-Sort-Array.md" >}})|Easy||||68.1%|
|
||||
|1128|Number of Equivalent Domino Pairs|[Go]({{< relref "/ChapterFour/1100~1199/1128.Number-of-Equivalent-Domino-Pairs.md" >}})|Easy||||46.6%|
|
||||
|1157|Online Majority Element In Subarray|[Go]({{< relref "/ChapterFour/1100~1199/1157.Online-Majority-Element-In-Subarray.md" >}})|Hard||||39.6%|
|
||||
|1157|Online Majority Element In Subarray|[Go]({{< relref "/ChapterFour/1100~1199/1157.Online-Majority-Element-In-Subarray.md" >}})|Hard||||39.7%|
|
||||
|1160|Find Words That Can Be Formed by Characters|[Go]({{< relref "/ChapterFour/1100~1199/1160.Find-Words-That-Can-Be-Formed-by-Characters.md" >}})|Easy||||67.9%|
|
||||
|1170|Compare Strings by Frequency of the Smallest Character|[Go]({{< relref "/ChapterFour/1100~1199/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md" >}})|Medium||||59.6%|
|
||||
|1184|Distance Between Bus Stops|[Go]({{< relref "/ChapterFour/1100~1199/1184.Distance-Between-Bus-Stops.md" >}})|Easy||||54.1%|
|
||||
@ -151,14 +151,21 @@ weight: 1
|
||||
|1480|Running Sum of 1d Array|[Go]({{< relref "/ChapterFour/1400~1499/1480.Running-Sum-of-1d-Array.md" >}})|Easy||||89.2%|
|
||||
|1512|Number of Good Pairs|[Go]({{< relref "/ChapterFour/1500~1599/1512.Number-of-Good-Pairs.md" >}})|Easy||||87.7%|
|
||||
|1539|Kth Missing Positive Number|[Go]({{< relref "/ChapterFour/1500~1599/1539.Kth-Missing-Positive-Number.md" >}})|Easy||||55.1%|
|
||||
|1608|Special Array With X Elements Greater Than or Equal X|[Go]({{< relref "/ChapterFour/1600~1699/1608.Special-Array-With-X-Elements-Greater-Than-or-Equal-X.md" >}})|Easy||||61.6%|
|
||||
|1619|Mean of Array After Removing Some Elements|[Go]({{< relref "/ChapterFour/1600~1699/1619.Mean-of-Array-After-Removing-Some-Elements.md" >}})|Easy||||65.2%|
|
||||
|1629|Slowest Key|[Go]({{< relref "/ChapterFour/1600~1699/1629.Slowest-Key.md" >}})|Easy||||59.2%|
|
||||
|1636|Sort Array by Increasing Frequency|[Go]({{< relref "/ChapterFour/1600~1699/1636.Sort-Array-by-Increasing-Frequency.md" >}})|Easy||||66.8%|
|
||||
|1640|Check Array Formation Through Concatenation|[Go]({{< relref "/ChapterFour/1600~1699/1640.Check-Array-Formation-Through-Concatenation.md" >}})|Easy||||60.1%|
|
||||
|1646|Get Maximum in Generated Array|[Go]({{< relref "/ChapterFour/1600~1699/1646.Get-Maximum-in-Generated-Array.md" >}})|Easy||||53.4%|
|
||||
|1646|Get Maximum in Generated Array|[Go]({{< relref "/ChapterFour/1600~1699/1646.Get-Maximum-in-Generated-Array.md" >}})|Easy||||53.5%|
|
||||
|1652|Defuse the Bomb|[Go]({{< relref "/ChapterFour/1600~1699/1652.Defuse-the-Bomb.md" >}})|Easy||||63.0%|
|
||||
|1656|Design an Ordered Stream|[Go]({{< relref "/ChapterFour/1600~1699/1656.Design-an-Ordered-Stream.md" >}})|Easy||||82.3%|
|
||||
|1672|Richest Customer Wealth|[Go]({{< relref "/ChapterFour/1600~1699/1672.Richest-Customer-Wealth.md" >}})|Easy||||88.4%|
|
||||
|1700|Number of Students Unable to Eat Lunch|[Go]({{< relref "/ChapterFour/1700~1799/1700.Number-of-Students-Unable-to-Eat-Lunch.md" >}})|Easy||||68.9%|
|
||||
|1732|Find the Highest Altitude|[Go]({{< relref "/ChapterFour/1700~1799/1732.Find-the-Highest-Altitude.md" >}})|Easy||||81.6%|
|
||||
|1742|Maximum Number of Balls in a Box|[Go]({{< relref "/ChapterFour/1700~1799/1742.Maximum-Number-of-Balls-in-a-Box.md" >}})|Easy||||74.8%|
|
||||
|1748|Sum of Unique Elements|[Go]({{< relref "/ChapterFour/1700~1799/1748.Sum-of-Unique-Elements.md" >}})|Easy||||77.3%|
|
||||
|1752|Check if Array Is Sorted and Rotated|[Go]({{< relref "/ChapterFour/1700~1799/1752.Check-if-Array-Is-Sorted-and-Rotated.md" >}})|Easy||||68.3%|
|
||||
|1758|Minimum Changes To Make Alternating Binary String|[Go]({{< relref "/ChapterFour/1700~1799/1758.Minimum-Changes-To-Make-Alternating-Binary-String.md" >}})|Easy||||60.8%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
||||
|
@ -115,7 +115,7 @@ func updateMatrix_BFS(matrix [][]int) [][]int {
|
||||
|0079|Word Search|[Go]({{< relref "/ChapterFour/0001~0099/0079.Word-Search.md" >}})|Medium| O(n^2)| O(n^2)|❤️|36.7%|
|
||||
|0089|Gray Code|[Go]({{< relref "/ChapterFour/0001~0099/0089.Gray-Code.md" >}})|Medium| O(n)| O(1)||50.3%|
|
||||
|0090|Subsets II|[Go]({{< relref "/ChapterFour/0001~0099/0090.Subsets-II.md" >}})|Medium| O(n^2)| O(n)|❤️|48.7%|
|
||||
|0093|Restore IP Addresses|[Go]({{< relref "/ChapterFour/0001~0099/0093.Restore-IP-Addresses.md" >}})|Medium| O(n)| O(n)|❤️|37.4%|
|
||||
|0093|Restore IP Addresses|[Go]({{< relref "/ChapterFour/0001~0099/0093.Restore-IP-Addresses.md" >}})|Medium| O(n)| O(n)|❤️|37.5%|
|
||||
|0126|Word Ladder II|[Go]({{< relref "/ChapterFour/0100~0199/0126.Word-Ladder-II.md" >}})|Hard| O(n)| O(n^2)|❤️|23.6%|
|
||||
|0131|Palindrome Partitioning|[Go]({{< relref "/ChapterFour/0100~0199/0131.Palindrome-Partitioning.md" >}})|Medium| O(n)| O(n^2)|❤️|51.8%|
|
||||
|0211|Design Add and Search Words Data Structure|[Go]({{< relref "/ChapterFour/0200~0299/0211.Design-Add-and-Search-Words-Data-Structure.md" >}})|Medium| O(n)| O(n)|❤️|40.1%|
|
||||
@ -130,8 +130,8 @@ func updateMatrix_BFS(matrix [][]int) [][]int {
|
||||
|0980|Unique Paths III|[Go]({{< relref "/ChapterFour/0900~0999/0980.Unique-Paths-III.md" >}})|Hard| O(n log n)| O(n)||77.2%|
|
||||
|0996|Number of Squareful Arrays|[Go]({{< relref "/ChapterFour/0900~0999/0996.Number-of-Squareful-Arrays.md" >}})|Hard| O(n log n)| O(n) ||48.3%|
|
||||
|1079|Letter Tile Possibilities|[Go]({{< relref "/ChapterFour/1000~1099/1079.Letter-Tile-Possibilities.md" >}})|Medium| O(n^2)| O(1)|❤️|75.9%|
|
||||
|1641|Count Sorted Vowel Strings|[Go]({{< relref "/ChapterFour/1600~1699/1641.Count-Sorted-Vowel-Strings.md" >}})|Medium||||76.9%|
|
||||
|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1600~1699/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.3%|
|
||||
|1641|Count Sorted Vowel Strings|[Go]({{< relref "/ChapterFour/1600~1699/1641.Count-Sorted-Vowel-Strings.md" >}})|Medium||||76.8%|
|
||||
|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1600~1699/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.4%|
|
||||
|1659|Maximize Grid Happiness|[Go]({{< relref "/ChapterFour/1600~1699/1659.Maximize-Grid-Happiness.md" >}})|Hard||||35.3%|
|
||||
|1681|Minimum Incompatibility|[Go]({{< relref "/ChapterFour/1600~1699/1681.Minimum-Incompatibility.md" >}})|Hard||||35.4%|
|
||||
|1688|Count of Matches in Tournament|[Go]({{< relref "/ChapterFour/1600~1699/1688.Count-of-Matches-in-Tournament.md" >}})|Easy||||82.5%|
|
||||
|
@ -138,7 +138,7 @@ func peakIndexInMountainArray(A []int) int {
|
||||
|0035|Search Insert Position|[Go]({{< relref "/ChapterFour/0001~0099/0035.Search-Insert-Position.md" >}})|Easy||||42.8%|
|
||||
|0050|Pow(x, n)|[Go]({{< relref "/ChapterFour/0001~0099/0050.Powx-n.md" >}})|Medium| O(log n)| O(1)||30.9%|
|
||||
|0069|Sqrt(x)|[Go]({{< relref "/ChapterFour/0001~0099/0069.Sqrtx.md" >}})|Easy| O(log n)| O(1)||35.0%|
|
||||
|0074|Search a 2D Matrix|[Go]({{< relref "/ChapterFour/0001~0099/0074.Search-a-2D-Matrix.md" >}})|Medium||||37.6%|
|
||||
|0074|Search a 2D Matrix|[Go]({{< relref "/ChapterFour/0001~0099/0074.Search-a-2D-Matrix.md" >}})|Medium||||37.7%|
|
||||
|0081|Search in Rotated Sorted Array II|[Go]({{< relref "/ChapterFour/0001~0099/0081.Search-in-Rotated-Sorted-Array-II.md" >}})|Medium||||33.5%|
|
||||
|0153|Find Minimum in Rotated Sorted Array|[Go]({{< relref "/ChapterFour/0100~0199/0153.Find-Minimum-in-Rotated-Sorted-Array.md" >}})|Medium||||46.1%|
|
||||
|0154|Find Minimum in Rotated Sorted Array II|[Go]({{< relref "/ChapterFour/0100~0199/0154.Find-Minimum-in-Rotated-Sorted-Array-II.md" >}})|Hard||||42.0%|
|
||||
@ -146,7 +146,7 @@ func peakIndexInMountainArray(A []int) int {
|
||||
|0167|Two Sum II - Input array is sorted|[Go]({{< relref "/ChapterFour/0100~0199/0167.Two-Sum-II---Input-array-is-sorted.md" >}})|Easy| O(n)| O(1)||55.6%|
|
||||
|0174|Dungeon Game|[Go]({{< relref "/ChapterFour/0100~0199/0174.Dungeon-Game.md" >}})|Hard||||33.3%|
|
||||
|0209|Minimum Size Subarray Sum|[Go]({{< relref "/ChapterFour/0200~0299/0209.Minimum-Size-Subarray-Sum.md" >}})|Medium| O(n)| O(1)||39.4%|
|
||||
|0222|Count Complete Tree Nodes|[Go]({{< relref "/ChapterFour/0200~0299/0222.Count-Complete-Tree-Nodes.md" >}})|Medium| O(n)| O(1)||49.1%|
|
||||
|0222|Count Complete Tree Nodes|[Go]({{< relref "/ChapterFour/0200~0299/0222.Count-Complete-Tree-Nodes.md" >}})|Medium| O(n)| O(1)||49.2%|
|
||||
|0230|Kth Smallest Element in a BST|[Go]({{< relref "/ChapterFour/0200~0299/0230.Kth-Smallest-Element-in-a-BST.md" >}})|Medium| O(n)| O(1)||62.5%|
|
||||
|0240|Search a 2D Matrix II|[Go]({{< relref "/ChapterFour/0200~0299/0240.Search-a-2D-Matrix-II.md" >}})|Medium||||44.4%|
|
||||
|0275|H-Index II|[Go]({{< relref "/ChapterFour/0200~0299/0275.H-Index-II.md" >}})|Medium||||36.3%|
|
||||
@ -162,7 +162,7 @@ func peakIndexInMountainArray(A []int) int {
|
||||
|0392|Is Subsequence|[Go]({{< relref "/ChapterFour/0300~0399/0392.Is-Subsequence.md" >}})|Easy| O(n)| O(1)||49.5%|
|
||||
|0410|Split Array Largest Sum|[Go]({{< relref "/ChapterFour/0400~0499/0410.Split-Array-Largest-Sum.md" >}})|Hard||||46.3%|
|
||||
|0436|Find Right Interval|[Go]({{< relref "/ChapterFour/0400~0499/0436.Find-Right-Interval.md" >}})|Medium||||48.5%|
|
||||
|0441|Arranging Coins|[Go]({{< relref "/ChapterFour/0400~0499/0441.Arranging-Coins.md" >}})|Easy||||42.3%|
|
||||
|0441|Arranging Coins|[Go]({{< relref "/ChapterFour/0400~0499/0441.Arranging-Coins.md" >}})|Easy||||42.4%|
|
||||
|0454|4Sum II|[Go]({{< relref "/ChapterFour/0400~0499/0454.4Sum-II.md" >}})|Medium| O(n^2)| O(n) ||54.6%|
|
||||
|0475|Heaters|[Go]({{< relref "/ChapterFour/0400~0499/0475.Heaters.md" >}})|Medium||||33.6%|
|
||||
|0483|Smallest Good Base|[Go]({{< relref "/ChapterFour/0400~0499/0483.Smallest-Good-Base.md" >}})|Hard||||36.2%|
|
||||
@ -177,23 +177,23 @@ func peakIndexInMountainArray(A []int) int {
|
||||
|0719|Find K-th Smallest Pair Distance|[Go]({{< relref "/ChapterFour/0700~0799/0719.Find-K-th-Smallest-Pair-Distance.md" >}})|Hard||||32.5%|
|
||||
|0744|Find Smallest Letter Greater Than Target|[Go]({{< relref "/ChapterFour/0700~0799/0744.Find-Smallest-Letter-Greater-Than-Target.md" >}})|Easy||||45.6%|
|
||||
|0778|Swim in Rising Water|[Go]({{< relref "/ChapterFour/0700~0799/0778.Swim-in-Rising-Water.md" >}})|Hard||||54.8%|
|
||||
|0786|K-th Smallest Prime Fraction|[Go]({{< relref "/ChapterFour/0700~0799/0786.K-th-Smallest-Prime-Fraction.md" >}})|Hard||||42.3%|
|
||||
|0786|K-th Smallest Prime Fraction|[Go]({{< relref "/ChapterFour/0700~0799/0786.K-th-Smallest-Prime-Fraction.md" >}})|Hard||||42.4%|
|
||||
|0793|Preimage Size of Factorial Zeroes Function|[Go]({{< relref "/ChapterFour/0700~0799/0793.Preimage-Size-of-Factorial-Zeroes-Function.md" >}})|Hard||||40.7%|
|
||||
|0852|Peak Index in a Mountain Array|[Go]({{< relref "/ChapterFour/0800~0899/0852.Peak-Index-in-a-Mountain-Array.md" >}})|Easy||||71.7%|
|
||||
|0862|Shortest Subarray with Sum at Least K|[Go]({{< relref "/ChapterFour/0800~0899/0862.Shortest-Subarray-with-Sum-at-Least-K.md" >}})|Hard||||25.2%|
|
||||
|0875|Koko Eating Bananas|[Go]({{< relref "/ChapterFour/0800~0899/0875.Koko-Eating-Bananas.md" >}})|Medium||||53.5%|
|
||||
|0878|Nth Magical Number|[Go]({{< relref "/ChapterFour/0800~0899/0878.Nth-Magical-Number.md" >}})|Hard||||28.8%|
|
||||
|0878|Nth Magical Number|[Go]({{< relref "/ChapterFour/0800~0899/0878.Nth-Magical-Number.md" >}})|Hard||||28.9%|
|
||||
|0887|Super Egg Drop|[Go]({{< relref "/ChapterFour/0800~0899/0887.Super-Egg-Drop.md" >}})|Hard||||27.1%|
|
||||
|0911|Online Election|[Go]({{< relref "/ChapterFour/0900~0999/0911.Online-Election.md" >}})|Medium||||51.2%|
|
||||
|0911|Online Election|[Go]({{< relref "/ChapterFour/0900~0999/0911.Online-Election.md" >}})|Medium||||51.3%|
|
||||
|0927|Three Equal Parts|[Go]({{< relref "/ChapterFour/0900~0999/0927.Three-Equal-Parts.md" >}})|Hard||||34.6%|
|
||||
|0981|Time Based Key-Value Store|[Go]({{< relref "/ChapterFour/0900~0999/0981.Time-Based-Key-Value-Store.md" >}})|Medium||||54.1%|
|
||||
|1011|Capacity To Ship Packages Within D Days|[Go]({{< relref "/ChapterFour/1000~1099/1011.Capacity-To-Ship-Packages-Within-D-Days.md" >}})|Medium||||59.7%|
|
||||
|1111|Maximum Nesting Depth of Two Valid Parentheses Strings|[Go]({{< relref "/ChapterFour/1100~1199/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings.md" >}})|Medium||||72.7%|
|
||||
|1157|Online Majority Element In Subarray|[Go]({{< relref "/ChapterFour/1100~1199/1157.Online-Majority-Element-In-Subarray.md" >}})|Hard||||39.6%|
|
||||
|1157|Online Majority Element In Subarray|[Go]({{< relref "/ChapterFour/1100~1199/1157.Online-Majority-Element-In-Subarray.md" >}})|Hard||||39.7%|
|
||||
|1170|Compare Strings by Frequency of the Smallest Character|[Go]({{< relref "/ChapterFour/1100~1199/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md" >}})|Medium||||59.6%|
|
||||
|1201|Ugly Number III|[Go]({{< relref "/ChapterFour/1200~1299/1201.Ugly-Number-III.md" >}})|Medium||||26.4%|
|
||||
|1235|Maximum Profit in Job Scheduling|[Go]({{< relref "/ChapterFour/1200~1299/1235.Maximum-Profit-in-Job-Scheduling.md" >}})|Hard||||47.4%|
|
||||
|1283|Find the Smallest Divisor Given a Threshold|[Go]({{< relref "/ChapterFour/1200~1299/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md" >}})|Medium||||49.4%|
|
||||
|1283|Find the Smallest Divisor Given a Threshold|[Go]({{< relref "/ChapterFour/1200~1299/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md" >}})|Medium||||49.5%|
|
||||
|1300|Sum of Mutated Array Closest to Target|[Go]({{< relref "/ChapterFour/1300~1399/1300.Sum-of-Mutated-Array-Closest-to-Target.md" >}})|Medium||||43.2%|
|
||||
|1631|Path With Minimum Effort|[Go]({{< relref "/ChapterFour/1600~1699/1631.Path-With-Minimum-Effort.md" >}})|Medium||||50.1%|
|
||||
|1649|Create Sorted Array through Instructions|[Go]({{< relref "/ChapterFour/1600~1699/1649.Create-Sorted-Array-through-Instructions.md" >}})|Hard||||36.3%|
|
||||
|
@ -64,7 +64,7 @@ X & ~X = 0
|
||||
|0397|Integer Replacement|[Go]({{< relref "/ChapterFour/0300~0399/0397.Integer-Replacement.md" >}})|Medium| O(n)| O(1)||33.5%|
|
||||
|0401|Binary Watch|[Go]({{< relref "/ChapterFour/0400~0499/0401.Binary-Watch.md" >}})|Easy| O(1)| O(1)||48.4%|
|
||||
|0405|Convert a Number to Hexadecimal|[Go]({{< relref "/ChapterFour/0400~0499/0405.Convert-a-Number-to-Hexadecimal.md" >}})|Easy| O(n)| O(1)||44.4%|
|
||||
|0421|Maximum XOR of Two Numbers in an Array|[Go]({{< relref "/ChapterFour/0400~0499/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md" >}})|Medium| O(n)| O(1)|❤️|54.1%|
|
||||
|0421|Maximum XOR of Two Numbers in an Array|[Go]({{< relref "/ChapterFour/0400~0499/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md" >}})|Medium| O(n)| O(1)|❤️|54.0%|
|
||||
|0461|Hamming Distance|[Go]({{< relref "/ChapterFour/0400~0499/0461.Hamming-Distance.md" >}})|Easy| O(n)| O(1)||73.2%|
|
||||
|0476|Number Complement|[Go]({{< relref "/ChapterFour/0400~0499/0476.Number-Complement.md" >}})|Easy| O(n)| O(1)||65.1%|
|
||||
|0477|Total Hamming Distance|[Go]({{< relref "/ChapterFour/0400~0499/0477.Total-Hamming-Distance.md" >}})|Medium| O(n)| O(1)||50.6%|
|
||||
@ -74,11 +74,10 @@ X & ~X = 0
|
||||
|0784|Letter Case Permutation|[Go]({{< relref "/ChapterFour/0700~0799/0784.Letter-Case-Permutation.md" >}})|Medium| O(n)| O(1)||66.5%|
|
||||
|0898|Bitwise ORs of Subarrays|[Go]({{< relref "/ChapterFour/0800~0899/0898.Bitwise-ORs-of-Subarrays.md" >}})|Medium| O(n)| O(1)||34.1%|
|
||||
|1290|Convert Binary Number in a Linked List to Integer|[Go]({{< relref "/ChapterFour/1200~1299/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md" >}})|Easy||||81.8%|
|
||||
|1720|Decode XORed Array|[Go]({{< relref "/ChapterFour/1700~1799/1720.Decode-XORed-Array.md" >}})|Easy||||85.7%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
<div style="display: flex;justify-content: space-between;align-items: center;">
|
||||
<p><a href="https://books.halfrost.com/leetcode/ChapterTwo/Sort/">⬅️上一页</a></p>
|
||||
|
@ -13,7 +13,7 @@ weight: 10
|
||||
|0102|Binary Tree Level Order Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0102.Binary-Tree-Level-Order-Traversal.md" >}})|Medium| O(n)| O(1)||56.5%|
|
||||
|0103|Binary Tree Zigzag Level Order Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})|Medium| O(n)| O(n)||50.0%|
|
||||
|0107|Binary Tree Level Order Traversal II|[Go]({{< relref "/ChapterFour/0100~0199/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})|Easy| O(n)| O(1)||55.1%|
|
||||
|0111|Minimum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0100~0199/0111.Minimum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||39.4%|
|
||||
|0111|Minimum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0100~0199/0111.Minimum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||39.5%|
|
||||
|0126|Word Ladder II|[Go]({{< relref "/ChapterFour/0100~0199/0126.Word-Ladder-II.md" >}})|Hard| O(n)| O(n^2)|❤️|23.6%|
|
||||
|0127|Word Ladder|[Go]({{< relref "/ChapterFour/0100~0199/0127.Word-Ladder.md" >}})|Hard| O(n)| O(n)||31.7%|
|
||||
|0130|Surrounded Regions|[Go]({{< relref "/ChapterFour/0100~0199/0130.Surrounded-Regions.md" >}})|Medium||||29.3%|
|
||||
@ -24,14 +24,14 @@ weight: 10
|
||||
|0513|Find Bottom Left Tree Value|[Go]({{< relref "/ChapterFour/0500~0599/0513.Find-Bottom-Left-Tree-Value.md" >}})|Medium||||62.5%|
|
||||
|0515|Find Largest Value in Each Tree Row|[Go]({{< relref "/ChapterFour/0500~0599/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})|Medium| O(n)| O(n)||62.2%|
|
||||
|0529|Minesweeper|[Go]({{< relref "/ChapterFour/0500~0599/0529.Minesweeper.md" >}})|Medium||||61.0%|
|
||||
|0542|01 Matrix|[Go]({{< relref "/ChapterFour/0500~0599/0542.01-Matrix.md" >}})|Medium| O(n)| O(1)||40.8%|
|
||||
|0785|Is Graph Bipartite?|[Go]({{< relref "/ChapterFour/0700~0799/0785.Is-Graph-Bipartite.md" >}})|Medium||||48.3%|
|
||||
|0542|01 Matrix|[Go]({{< relref "/ChapterFour/0500~0599/0542.01-Matrix.md" >}})|Medium| O(n)| O(1)||40.9%|
|
||||
|0785|Is Graph Bipartite?|[Go]({{< relref "/ChapterFour/0700~0799/0785.Is-Graph-Bipartite.md" >}})|Medium||||48.6%|
|
||||
|0815|Bus Routes|[Go]({{< relref "/ChapterFour/0800~0899/0815.Bus-Routes.md" >}})|Hard||||43.3%|
|
||||
|0863|All Nodes Distance K in Binary Tree|[Go]({{< relref "/ChapterFour/0800~0899/0863.All-Nodes-Distance-K-in-Binary-Tree.md" >}})|Medium||||57.8%|
|
||||
|0864|Shortest Path to Get All Keys|[Go]({{< relref "/ChapterFour/0800~0899/0864.Shortest-Path-to-Get-All-Keys.md" >}})|Hard||||41.9%|
|
||||
|0987|Vertical Order Traversal of a Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0987.Vertical-Order-Traversal-of-a-Binary-Tree.md" >}})|Hard||||38.7%|
|
||||
|0987|Vertical Order Traversal of a Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0987.Vertical-Order-Traversal-of-a-Binary-Tree.md" >}})|Hard||||38.8%|
|
||||
|0993|Cousins in Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0993.Cousins-in-Binary-Tree.md" >}})|Easy| O(n)| O(1)||52.3%|
|
||||
|1091|Shortest Path in Binary Matrix|[Go]({{< relref "/ChapterFour/1000~1099/1091.Shortest-Path-in-Binary-Matrix.md" >}})|Medium||||39.8%|
|
||||
|1091|Shortest Path in Binary Matrix|[Go]({{< relref "/ChapterFour/1000~1099/1091.Shortest-Path-in-Binary-Matrix.md" >}})|Medium||||40.0%|
|
||||
|1306|Jump Game III|[Go]({{< relref "/ChapterFour/1300~1399/1306.Jump-Game-III.md" >}})|Medium||||62.6%|
|
||||
|1319|Number of Operations to Make Network Connected|[Go]({{< relref "/ChapterFour/1300~1399/1319.Number-of-Operations-to-Make-Network-Connected.md" >}})|Medium||||55.4%|
|
||||
|1654|Minimum Jumps to Reach Home|[Go]({{< relref "/ChapterFour/1600~1699/1654.Minimum-Jumps-to-Reach-Home.md" >}})|Medium||||26.0%|
|
||||
|
@ -20,8 +20,8 @@ weight: 9
|
||||
|0108|Convert Sorted Array to Binary Search Tree|[Go]({{< relref "/ChapterFour/0100~0199/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})|Easy| O(n)| O(1)||60.3%|
|
||||
|0109|Convert Sorted List to Binary Search Tree|[Go]({{< relref "/ChapterFour/0100~0199/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})|Medium| O(log n)| O(n)||50.1%|
|
||||
|0110|Balanced Binary Tree|[Go]({{< relref "/ChapterFour/0100~0199/0110.Balanced-Binary-Tree.md" >}})|Easy| O(n)| O(1)||44.7%|
|
||||
|0111|Minimum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0100~0199/0111.Minimum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||39.4%|
|
||||
|0112|Path Sum|[Go]({{< relref "/ChapterFour/0100~0199/0112.Path-Sum.md" >}})|Easy| O(n)| O(1)||42.3%|
|
||||
|0111|Minimum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0100~0199/0111.Minimum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||39.5%|
|
||||
|0112|Path Sum|[Go]({{< relref "/ChapterFour/0100~0199/0112.Path-Sum.md" >}})|Easy| O(n)| O(1)||42.4%|
|
||||
|0113|Path Sum II|[Go]({{< relref "/ChapterFour/0100~0199/0113.Path-Sum-II.md" >}})|Medium| O(n)| O(1)||49.0%|
|
||||
|0114|Flatten Binary Tree to Linked List|[Go]({{< relref "/ChapterFour/0100~0199/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})|Medium| O(n)| O(1)||51.8%|
|
||||
|0124|Binary Tree Maximum Path Sum|[Go]({{< relref "/ChapterFour/0100~0199/0124.Binary-Tree-Maximum-Path-Sum.md" >}})|Hard| O(n)| O(1)||35.4%|
|
||||
@ -44,21 +44,21 @@ weight: 9
|
||||
|0526|Beautiful Arrangement|[Go]({{< relref "/ChapterFour/0500~0599/0526.Beautiful-Arrangement.md" >}})|Medium||||61.8%|
|
||||
|0529|Minesweeper|[Go]({{< relref "/ChapterFour/0500~0599/0529.Minesweeper.md" >}})|Medium||||61.0%|
|
||||
|0538|Convert BST to Greater Tree|[Go]({{< relref "/ChapterFour/0500~0599/0538.Convert-BST-to-Greater-Tree.md" >}})|Medium||||59.2%|
|
||||
|0542|01 Matrix|[Go]({{< relref "/ChapterFour/0500~0599/0542.01-Matrix.md" >}})|Medium| O(n)| O(1)||40.8%|
|
||||
|0542|01 Matrix|[Go]({{< relref "/ChapterFour/0500~0599/0542.01-Matrix.md" >}})|Medium| O(n)| O(1)||40.9%|
|
||||
|0547|Number of Provinces|[Go]({{< relref "/ChapterFour/0500~0599/0547.Number-of-Provinces.md" >}})|Medium||||60.4%|
|
||||
|0563|Binary Tree Tilt|[Go]({{< relref "/ChapterFour/0500~0599/0563.Binary-Tree-Tilt.md" >}})|Easy||||52.9%|
|
||||
|0638|Shopping Offers|[Go]({{< relref "/ChapterFour/0600~0699/0638.Shopping-Offers.md" >}})|Medium||||52.8%|
|
||||
|0685|Redundant Connection II|[Go]({{< relref "/ChapterFour/0600~0699/0685.Redundant-Connection-II.md" >}})|Hard||||33.0%|
|
||||
|0695|Max Area of Island|[Go]({{< relref "/ChapterFour/0600~0699/0695.Max-Area-of-Island.md" >}})|Medium||||64.6%|
|
||||
|0721|Accounts Merge|[Go]({{< relref "/ChapterFour/0700~0799/0721.Accounts-Merge.md" >}})|Medium||||51.6%|
|
||||
|0721|Accounts Merge|[Go]({{< relref "/ChapterFour/0700~0799/0721.Accounts-Merge.md" >}})|Medium||||51.7%|
|
||||
|0733|Flood Fill|[Go]({{< relref "/ChapterFour/0700~0799/0733.Flood-Fill.md" >}})|Easy||||55.9%|
|
||||
|0753|Cracking the Safe|[Go]({{< relref "/ChapterFour/0700~0799/0753.Cracking-the-Safe.md" >}})|Hard||||52.3%|
|
||||
|0756|Pyramid Transition Matrix|[Go]({{< relref "/ChapterFour/0700~0799/0756.Pyramid-Transition-Matrix.md" >}})|Medium||||55.5%|
|
||||
|0778|Swim in Rising Water|[Go]({{< relref "/ChapterFour/0700~0799/0778.Swim-in-Rising-Water.md" >}})|Hard||||54.8%|
|
||||
|0785|Is Graph Bipartite?|[Go]({{< relref "/ChapterFour/0700~0799/0785.Is-Graph-Bipartite.md" >}})|Medium||||48.3%|
|
||||
|0785|Is Graph Bipartite?|[Go]({{< relref "/ChapterFour/0700~0799/0785.Is-Graph-Bipartite.md" >}})|Medium||||48.6%|
|
||||
|0802|Find Eventual Safe States|[Go]({{< relref "/ChapterFour/0800~0899/0802.Find-Eventual-Safe-States.md" >}})|Medium||||49.8%|
|
||||
|0834|Sum of Distances in Tree|[Go]({{< relref "/ChapterFour/0800~0899/0834.Sum-of-Distances-in-Tree.md" >}})|Hard||||45.9%|
|
||||
|0839|Similar String Groups|[Go]({{< relref "/ChapterFour/0800~0899/0839.Similar-String-Groups.md" >}})|Hard||||40.5%|
|
||||
|0839|Similar String Groups|[Go]({{< relref "/ChapterFour/0800~0899/0839.Similar-String-Groups.md" >}})|Hard||||40.6%|
|
||||
|0841|Keys and Rooms|[Go]({{< relref "/ChapterFour/0800~0899/0841.Keys-and-Rooms.md" >}})|Medium||||65.4%|
|
||||
|0851|Loud and Rich|[Go]({{< relref "/ChapterFour/0800~0899/0851.Loud-and-Rich.md" >}})|Medium||||52.6%|
|
||||
|0863|All Nodes Distance K in Binary Tree|[Go]({{< relref "/ChapterFour/0800~0899/0863.All-Nodes-Distance-K-in-Binary-Tree.md" >}})|Medium||||57.8%|
|
||||
@ -71,7 +71,7 @@ weight: 9
|
||||
|0968|Binary Tree Cameras|[Go]({{< relref "/ChapterFour/0900~0999/0968.Binary-Tree-Cameras.md" >}})|Hard||||38.7%|
|
||||
|0979|Distribute Coins in Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0979.Distribute-Coins-in-Binary-Tree.md" >}})|Medium||||69.7%|
|
||||
|0980|Unique Paths III|[Go]({{< relref "/ChapterFour/0900~0999/0980.Unique-Paths-III.md" >}})|Hard| O(n log n)| O(n)||77.2%|
|
||||
|0987|Vertical Order Traversal of a Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0987.Vertical-Order-Traversal-of-a-Binary-Tree.md" >}})|Hard||||38.7%|
|
||||
|0987|Vertical Order Traversal of a Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0987.Vertical-Order-Traversal-of-a-Binary-Tree.md" >}})|Hard||||38.8%|
|
||||
|1020|Number of Enclaves|[Go]({{< relref "/ChapterFour/1000~1099/1020.Number-of-Enclaves.md" >}})|Medium||||58.9%|
|
||||
|1026|Maximum Difference Between Node and Ancestor|[Go]({{< relref "/ChapterFour/1000~1099/1026.Maximum-Difference-Between-Node-and-Ancestor.md" >}})|Medium||||69.4%|
|
||||
|1028|Recover a Tree From Preorder Traversal|[Go]({{< relref "/ChapterFour/1000~1099/1028.Recover-a-Tree-From-Preorder-Traversal.md" >}})|Hard||||70.9%|
|
||||
|
@ -9,7 +9,7 @@ weight: 7
|
||||
|
||||
| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
|
||||
|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
|
||||
|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0001~0099/0042.Trapping-Rain-Water.md" >}})|Hard||||51.0%|
|
||||
|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0001~0099/0042.Trapping-Rain-Water.md" >}})|Hard||||51.1%|
|
||||
|0053|Maximum Subarray|[Go]({{< relref "/ChapterFour/0001~0099/0053.Maximum-Subarray.md" >}})|Easy| O(n)| O(n)||47.7%|
|
||||
|0062|Unique Paths|[Go]({{< relref "/ChapterFour/0001~0099/0062.Unique-Paths.md" >}})|Medium| O(n^2)| O(n^2)||55.9%|
|
||||
|0063|Unique Paths II|[Go]({{< relref "/ChapterFour/0001~0099/0063.Unique-Paths-II.md" >}})|Medium| O(n^2)| O(n^2)||35.2%|
|
||||
@ -17,7 +17,7 @@ weight: 7
|
||||
|0070|Climbing Stairs|[Go]({{< relref "/ChapterFour/0001~0099/0070.Climbing-Stairs.md" >}})|Easy| O(n)| O(n)||48.6%|
|
||||
|0091|Decode Ways|[Go]({{< relref "/ChapterFour/0001~0099/0091.Decode-Ways.md" >}})|Medium| O(n)| O(n)||26.5%|
|
||||
|0095|Unique Binary Search Trees II|[Go]({{< relref "/ChapterFour/0001~0099/0095.Unique-Binary-Search-Trees-II.md" >}})|Medium||||42.4%|
|
||||
|0096|Unique Binary Search Trees|[Go]({{< relref "/ChapterFour/0001~0099/0096.Unique-Binary-Search-Trees.md" >}})|Medium| O(n)| O(n)||54.3%|
|
||||
|0096|Unique Binary Search Trees|[Go]({{< relref "/ChapterFour/0001~0099/0096.Unique-Binary-Search-Trees.md" >}})|Medium| O(n)| O(n)||54.4%|
|
||||
|0120|Triangle|[Go]({{< relref "/ChapterFour/0100~0199/0120.Triangle.md" >}})|Medium| O(n^2)| O(n)||45.7%|
|
||||
|0121|Best Time to Buy and Sell Stock|[Go]({{< relref "/ChapterFour/0100~0199/0121.Best-Time-to-Buy-and-Sell-Stock.md" >}})|Easy| O(n)| O(1)||51.5%|
|
||||
|0131|Palindrome Partitioning|[Go]({{< relref "/ChapterFour/0100~0199/0131.Palindrome-Partitioning.md" >}})|Medium||||51.8%|
|
||||
@ -56,13 +56,13 @@ weight: 7
|
||||
|1235|Maximum Profit in Job Scheduling|[Go]({{< relref "/ChapterFour/1200~1299/1235.Maximum-Profit-in-Job-Scheduling.md" >}})|Hard||||47.4%|
|
||||
|1423|Maximum Points You Can Obtain from Cards|[Go]({{< relref "/ChapterFour/1400~1499/1423.Maximum-Points-You-Can-Obtain-from-Cards.md" >}})|Medium||||46.6%|
|
||||
|1463|Cherry Pickup II|[Go]({{< relref "/ChapterFour/1400~1499/1463.Cherry-Pickup-II.md" >}})|Hard||||69.3%|
|
||||
|1641|Count Sorted Vowel Strings|[Go]({{< relref "/ChapterFour/1600~1699/1641.Count-Sorted-Vowel-Strings.md" >}})|Medium||||76.9%|
|
||||
|1641|Count Sorted Vowel Strings|[Go]({{< relref "/ChapterFour/1600~1699/1641.Count-Sorted-Vowel-Strings.md" >}})|Medium||||76.8%|
|
||||
|1654|Minimum Jumps to Reach Home|[Go]({{< relref "/ChapterFour/1600~1699/1654.Minimum-Jumps-to-Reach-Home.md" >}})|Medium||||26.0%|
|
||||
|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1600~1699/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.3%|
|
||||
|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1600~1699/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.4%|
|
||||
|1659|Maximize Grid Happiness|[Go]({{< relref "/ChapterFour/1600~1699/1659.Maximize-Grid-Happiness.md" >}})|Hard||||35.3%|
|
||||
|1664|Ways to Make a Fair Array|[Go]({{< relref "/ChapterFour/1600~1699/1664.Ways-to-Make-a-Fair-Array.md" >}})|Medium||||61.5%|
|
||||
|1690|Stone Game VII|[Go]({{< relref "/ChapterFour/1600~1699/1690.Stone-Game-VII.md" >}})|Medium||||47.6%|
|
||||
|1691|Maximum Height by Stacking Cuboids|[Go]({{< relref "/ChapterFour/1600~1699/1691.Maximum-Height-by-Stacking-Cuboids.md" >}})|Hard||||50.0%|
|
||||
|1691|Maximum Height by Stacking Cuboids|[Go]({{< relref "/ChapterFour/1600~1699/1691.Maximum-Height-by-Stacking-Cuboids.md" >}})|Hard||||49.9%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@ weight: 13
|
||||
|0242|Valid Anagram|[Go]({{< relref "/ChapterFour/0200~0299/0242.Valid-Anagram.md" >}})|Easy| O(n)| O(n) ||58.5%|
|
||||
|0274|H-Index|[Go]({{< relref "/ChapterFour/0200~0299/0274.H-Index.md" >}})|Medium| O(n)| O(n) ||36.3%|
|
||||
|0290|Word Pattern|[Go]({{< relref "/ChapterFour/0200~0299/0290.Word-Pattern.md" >}})|Easy| O(n)| O(n) ||38.3%|
|
||||
|0347|Top K Frequent Elements|[Go]({{< relref "/ChapterFour/0300~0399/0347.Top-K-Frequent-Elements.md" >}})|Medium| O(n)| O(n) ||62.3%|
|
||||
|0347|Top K Frequent Elements|[Go]({{< relref "/ChapterFour/0300~0399/0347.Top-K-Frequent-Elements.md" >}})|Medium| O(n)| O(n) ||62.4%|
|
||||
|0349|Intersection of Two Arrays|[Go]({{< relref "/ChapterFour/0300~0399/0349.Intersection-of-Two-Arrays.md" >}})|Easy| O(n)| O(n) ||64.7%|
|
||||
|0350|Intersection of Two Arrays II|[Go]({{< relref "/ChapterFour/0300~0399/0350.Intersection-of-Two-Arrays-II.md" >}})|Easy| O(n)| O(n) ||52.0%|
|
||||
|0387|First Unique Character in a String|[Go]({{< relref "/ChapterFour/0300~0399/0387.First-Unique-Character-in-a-String.md" >}})|Easy||||53.8%|
|
||||
@ -45,15 +45,15 @@ weight: 13
|
||||
|0575|Distribute Candies|[Go]({{< relref "/ChapterFour/0500~0599/0575.Distribute-Candies.md" >}})|Easy||||62.1%|
|
||||
|0594|Longest Harmonious Subsequence|[Go]({{< relref "/ChapterFour/0500~0599/0594.Longest-Harmonious-Subsequence.md" >}})|Easy||||51.2%|
|
||||
|0599|Minimum Index Sum of Two Lists|[Go]({{< relref "/ChapterFour/0500~0599/0599.Minimum-Index-Sum-of-Two-Lists.md" >}})|Easy||||51.6%|
|
||||
|0632|Smallest Range Covering Elements from K Lists|[Go]({{< relref "/ChapterFour/0600~0699/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})|Hard||||54.1%|
|
||||
|0632|Smallest Range Covering Elements from K Lists|[Go]({{< relref "/ChapterFour/0600~0699/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})|Hard||||54.2%|
|
||||
|0645|Set Mismatch|[Go]({{< relref "/ChapterFour/0600~0699/0645.Set-Mismatch.md" >}})|Easy||||42.5%|
|
||||
|0648|Replace Words|[Go]({{< relref "/ChapterFour/0600~0699/0648.Replace-Words.md" >}})|Medium| O(n)| O(n) ||58.4%|
|
||||
|0648|Replace Words|[Go]({{< relref "/ChapterFour/0600~0699/0648.Replace-Words.md" >}})|Medium| O(n)| O(n) ||58.5%|
|
||||
|0676|Implement Magic Dictionary|[Go]({{< relref "/ChapterFour/0600~0699/0676.Implement-Magic-Dictionary.md" >}})|Medium| O(n)| O(n) ||55.2%|
|
||||
|0705|Design HashSet|[Go]({{< relref "/ChapterFour/0700~0799/0705.Design-HashSet.md" >}})|Easy||||64.7%|
|
||||
|0706|Design HashMap|[Go]({{< relref "/ChapterFour/0700~0799/0706.Design-HashMap.md" >}})|Easy||||62.8%|
|
||||
|0710|Random Pick with Blacklist|[Go]({{< relref "/ChapterFour/0700~0799/0710.Random-Pick-with-Blacklist.md" >}})|Hard| O(n)| O(n) ||32.7%|
|
||||
|0718|Maximum Length of Repeated Subarray|[Go]({{< relref "/ChapterFour/0700~0799/0718.Maximum-Length-of-Repeated-Subarray.md" >}})|Medium||||50.3%|
|
||||
|0720|Longest Word in Dictionary|[Go]({{< relref "/ChapterFour/0700~0799/0720.Longest-Word-in-Dictionary.md" >}})|Easy| O(n)| O(n) ||49.1%|
|
||||
|0720|Longest Word in Dictionary|[Go]({{< relref "/ChapterFour/0700~0799/0720.Longest-Word-in-Dictionary.md" >}})|Easy| O(n)| O(n) ||49.2%|
|
||||
|0726|Number of Atoms|[Go]({{< relref "/ChapterFour/0700~0799/0726.Number-of-Atoms.md" >}})|Hard| O(n)| O(n) |❤️|51.1%|
|
||||
|0739|Daily Temperatures|[Go]({{< relref "/ChapterFour/0700~0799/0739.Daily-Temperatures.md" >}})|Medium| O(n)| O(n) ||64.5%|
|
||||
|0748|Shortest Completing Word|[Go]({{< relref "/ChapterFour/0700~0799/0748.Shortest-Completing-Word.md" >}})|Easy||||57.5%|
|
||||
@ -67,7 +67,7 @@ weight: 13
|
||||
|0961|N-Repeated Element in Size 2N Array|[Go]({{< relref "/ChapterFour/0900~0999/0961.N-Repeated-Element-in-Size-2N-Array.md" >}})|Easy||||74.4%|
|
||||
|0970|Powerful Integers|[Go]({{< relref "/ChapterFour/0900~0999/0970.Powerful-Integers.md" >}})|Medium||||40.0%|
|
||||
|0981|Time Based Key-Value Store|[Go]({{< relref "/ChapterFour/0900~0999/0981.Time-Based-Key-Value-Store.md" >}})|Medium||||54.1%|
|
||||
|0987|Vertical Order Traversal of a Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0987.Vertical-Order-Traversal-of-a-Binary-Tree.md" >}})|Hard||||38.7%|
|
||||
|0987|Vertical Order Traversal of a Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0987.Vertical-Order-Traversal-of-a-Binary-Tree.md" >}})|Hard||||38.8%|
|
||||
|0992|Subarrays with K Different Integers|[Go]({{< relref "/ChapterFour/0900~0999/0992.Subarrays-with-K-Different-Integers.md" >}})|Hard| O(n)| O(n) |❤️|50.6%|
|
||||
|1002|Find Common Characters|[Go]({{< relref "/ChapterFour/1000~1099/1002.Find-Common-Characters.md" >}})|Easy||||68.6%|
|
||||
|1078|Occurrences After Bigram|[Go]({{< relref "/ChapterFour/1000~1099/1078.Occurrences-After-Bigram.md" >}})|Easy||||64.9%|
|
||||
@ -78,6 +78,7 @@ weight: 13
|
||||
|1539|Kth Missing Positive Number|[Go]({{< relref "/ChapterFour/1500~1599/1539.Kth-Missing-Positive-Number.md" >}})|Easy||||55.1%|
|
||||
|1640|Check Array Formation Through Concatenation|[Go]({{< relref "/ChapterFour/1600~1699/1640.Check-Array-Formation-Through-Concatenation.md" >}})|Easy||||60.1%|
|
||||
|1679|Max Number of K-Sum Pairs|[Go]({{< relref "/ChapterFour/1600~1699/1679.Max-Number-of-K-Sum-Pairs.md" >}})|Medium||||54.2%|
|
||||
|1748|Sum of Unique Elements|[Go]({{< relref "/ChapterFour/1700~1799/1748.Sum-of-Unique-Elements.md" >}})|Easy||||77.3%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
||||
|
@ -41,7 +41,7 @@ weight: 4
|
||||
|0143|Reorder List|[Go]({{< relref "/ChapterFour/0100~0199/0143.Reorder-List.md" >}})|Medium| O(n)| O(1)|❤️|40.5%|
|
||||
|0147|Insertion Sort List|[Go]({{< relref "/ChapterFour/0100~0199/0147.Insertion-Sort-List.md" >}})|Medium| O(n)| O(1)|❤️|44.3%|
|
||||
|0148|Sort List|[Go]({{< relref "/ChapterFour/0100~0199/0148.Sort-List.md" >}})|Medium| O(n log n)| O(n)|❤️|46.1%|
|
||||
|0160|Intersection of Two Linked Lists|[Go]({{< relref "/ChapterFour/0100~0199/0160.Intersection-of-Two-Linked-Lists.md" >}})|Easy| O(n)| O(1)|❤️|43.0%|
|
||||
|0160|Intersection of Two Linked Lists|[Go]({{< relref "/ChapterFour/0100~0199/0160.Intersection-of-Two-Linked-Lists.md" >}})|Easy| O(n)| O(1)|❤️|43.1%|
|
||||
|0203|Remove Linked List Elements|[Go]({{< relref "/ChapterFour/0200~0299/0203.Remove-Linked-List-Elements.md" >}})|Easy| O(n)| O(1)||39.2%|
|
||||
|0206|Reverse Linked List|[Go]({{< relref "/ChapterFour/0200~0299/0206.Reverse-Linked-List.md" >}})|Easy| O(n)| O(1)||65.1%|
|
||||
|0234|Palindrome Linked List|[Go]({{< relref "/ChapterFour/0200~0299/0234.Palindrome-Linked-List.md" >}})|Easy| O(n)| O(1)||40.4%|
|
||||
@ -56,7 +56,7 @@ weight: 4
|
||||
|1171|Remove Zero Sum Consecutive Nodes from Linked List|[Go]({{< relref "/ChapterFour/1100~1199/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md" >}})|Medium||||41.4%|
|
||||
|1290|Convert Binary Number in a Linked List to Integer|[Go]({{< relref "/ChapterFour/1200~1299/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md" >}})|Easy||||81.8%|
|
||||
|1669|Merge In Between Linked Lists|[Go]({{< relref "/ChapterFour/1600~1699/1669.Merge-In-Between-Linked-Lists.md" >}})|Medium||||77.0%|
|
||||
|1670|Design Front Middle Back Queue|[Go]({{< relref "/ChapterFour/1600~1699/1670.Design-Front-Middle-Back-Queue.md" >}})|Medium||||54.5%|
|
||||
|1670|Design Front Middle Back Queue|[Go]({{< relref "/ChapterFour/1600~1699/1670.Design-Front-Middle-Back-Queue.md" >}})|Medium||||54.6%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ weight: 12
|
||||
|0367|Valid Perfect Square|[Go]({{< relref "/ChapterFour/0300~0399/0367.Valid-Perfect-Square.md" >}})|Easy||||42.0%|
|
||||
|0372|Super Pow|[Go]({{< relref "/ChapterFour/0300~0399/0372.Super-Pow.md" >}})|Medium||||36.7%|
|
||||
|0397|Integer Replacement|[Go]({{< relref "/ChapterFour/0300~0399/0397.Integer-Replacement.md" >}})|Medium||||33.5%|
|
||||
|0441|Arranging Coins|[Go]({{< relref "/ChapterFour/0400~0499/0441.Arranging-Coins.md" >}})|Easy||||42.3%|
|
||||
|0441|Arranging Coins|[Go]({{< relref "/ChapterFour/0400~0499/0441.Arranging-Coins.md" >}})|Easy||||42.4%|
|
||||
|0447|Number of Boomerangs|[Go]({{< relref "/ChapterFour/0400~0499/0447.Number-of-Boomerangs.md" >}})|Medium||||52.4%|
|
||||
|0453|Minimum Moves to Equal Array Elements|[Go]({{< relref "/ChapterFour/0400~0499/0453.Minimum-Moves-to-Equal-Array-Elements.md" >}})|Easy||||50.8%|
|
||||
|0483|Smallest Good Base|[Go]({{< relref "/ChapterFour/0400~0499/0483.Smallest-Good-Base.md" >}})|Hard||||36.2%|
|
||||
@ -49,13 +49,13 @@ weight: 12
|
||||
|0781|Rabbits in Forest|[Go]({{< relref "/ChapterFour/0700~0799/0781.Rabbits-in-Forest.md" >}})|Medium||||55.5%|
|
||||
|0812|Largest Triangle Area|[Go]({{< relref "/ChapterFour/0800~0899/0812.Largest-Triangle-Area.md" >}})|Easy||||58.9%|
|
||||
|0836|Rectangle Overlap|[Go]({{< relref "/ChapterFour/0800~0899/0836.Rectangle-Overlap.md" >}})|Easy||||44.7%|
|
||||
|0878|Nth Magical Number|[Go]({{< relref "/ChapterFour/0800~0899/0878.Nth-Magical-Number.md" >}})|Hard||||28.8%|
|
||||
|0878|Nth Magical Number|[Go]({{< relref "/ChapterFour/0800~0899/0878.Nth-Magical-Number.md" >}})|Hard||||28.9%|
|
||||
|0885|Spiral Matrix III|[Go]({{< relref "/ChapterFour/0800~0899/0885.Spiral-Matrix-III.md" >}})|Medium| O(n^2)| O(1)||70.7%|
|
||||
|0887|Super Egg Drop|[Go]({{< relref "/ChapterFour/0800~0899/0887.Super-Egg-Drop.md" >}})|Hard||||27.1%|
|
||||
|0891|Sum of Subsequence Widths|[Go]({{< relref "/ChapterFour/0800~0899/0891.Sum-of-Subsequence-Widths.md" >}})|Hard| O(n log n)| O(1)||33.0%|
|
||||
|0892|Surface Area of 3D Shapes|[Go]({{< relref "/ChapterFour/0800~0899/0892.Surface-Area-of-3D-Shapes.md" >}})|Easy||||59.7%|
|
||||
|0910|Smallest Range II|[Go]({{< relref "/ChapterFour/0900~0999/0910.Smallest-Range-II.md" >}})|Medium||||31.3%|
|
||||
|0914|X of a Kind in a Deck of Cards|[Go]({{< relref "/ChapterFour/0900~0999/0914.X-of-a-Kind-in-a-Deck-of-Cards.md" >}})|Easy||||34.3%|
|
||||
|0914|X of a Kind in a Deck of Cards|[Go]({{< relref "/ChapterFour/0900~0999/0914.X-of-a-Kind-in-a-Deck-of-Cards.md" >}})|Easy||||34.2%|
|
||||
|0927|Three Equal Parts|[Go]({{< relref "/ChapterFour/0900~0999/0927.Three-Equal-Parts.md" >}})|Hard||||34.6%|
|
||||
|0942|DI String Match|[Go]({{< relref "/ChapterFour/0900~0999/0942.DI-String-Match.md" >}})|Easy| O(n)| O(1)||73.5%|
|
||||
|0949|Largest Time for Given Digits|[Go]({{< relref "/ChapterFour/0900~0999/0949.Largest-Time-for-Given-Digits.md" >}})|Medium||||36.2%|
|
||||
@ -76,10 +76,11 @@ weight: 12
|
||||
|1281|Subtract the Product and Sum of Digits of an Integer|[Go]({{< relref "/ChapterFour/1200~1299/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer.md" >}})|Easy||||85.6%|
|
||||
|1317|Convert Integer to the Sum of Two No-Zero Integers|[Go]({{< relref "/ChapterFour/1300~1399/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers.md" >}})|Easy||||56.8%|
|
||||
|1512|Number of Good Pairs|[Go]({{< relref "/ChapterFour/1500~1599/1512.Number-of-Good-Pairs.md" >}})|Easy||||87.7%|
|
||||
|1641|Count Sorted Vowel Strings|[Go]({{< relref "/ChapterFour/1600~1699/1641.Count-Sorted-Vowel-Strings.md" >}})|Medium||||76.9%|
|
||||
|1641|Count Sorted Vowel Strings|[Go]({{< relref "/ChapterFour/1600~1699/1641.Count-Sorted-Vowel-Strings.md" >}})|Medium||||76.8%|
|
||||
|1648|Sell Diminishing-Valued Colored Balls|[Go]({{< relref "/ChapterFour/1600~1699/1648.Sell-Diminishing-Valued-Colored-Balls.md" >}})|Medium||||30.8%|
|
||||
|1680|Concatenation of Consecutive Binary Numbers|[Go]({{< relref "/ChapterFour/1600~1699/1680.Concatenation-of-Consecutive-Binary-Numbers.md" >}})|Medium||||52.4%|
|
||||
|1685|Sum of Absolute Differences in a Sorted Array|[Go]({{< relref "/ChapterFour/1600~1699/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array.md" >}})|Medium||||62.9%|
|
||||
|1685|Sum of Absolute Differences in a Sorted Array|[Go]({{< relref "/ChapterFour/1600~1699/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array.md" >}})|Medium||||62.8%|
|
||||
|1716|Calculate Money in Leetcode Bank|[Go]({{< relref "/ChapterFour/1700~1799/1716.Calculate-Money-in-Leetcode-Bank.md" >}})|Easy||||67.3%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
||||
|
@ -46,7 +46,7 @@ weight: 18
|
||||
|0715|Range Module|[Go]({{< relref "/ChapterFour/0700~0799/0715.Range-Module.md" >}})|Hard| O(log n)| O(n)|❤️|40.2%|
|
||||
|0732|My Calendar III|[Go]({{< relref "/ChapterFour/0700~0799/0732.My-Calendar-III.md" >}})|Hard| O(log n)| O(n)|❤️|61.7%|
|
||||
|0850|Rectangle Area II|[Go]({{< relref "/ChapterFour/0800~0899/0850.Rectangle-Area-II.md" >}})|Hard| O(n log n)| O(n)|❤️|48.3%|
|
||||
|1157|Online Majority Element In Subarray|[Go]({{< relref "/ChapterFour/1100~1199/1157.Online-Majority-Element-In-Subarray.md" >}})|Hard| O(log n)| O(n)|❤️|39.6%|
|
||||
|1157|Online Majority Element In Subarray|[Go]({{< relref "/ChapterFour/1100~1199/1157.Online-Majority-Element-In-Subarray.md" >}})|Hard| O(log n)| O(n)|❤️|39.7%|
|
||||
|1649|Create Sorted Array through Instructions|[Go]({{< relref "/ChapterFour/1600~1699/1649.Create-Sorted-Array-through-Instructions.md" >}})|Hard||||36.3%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
@ -23,13 +23,13 @@ weight: 14
|
||||
|0075|Sort Colors|[Go]({{< relref "/ChapterFour/0001~0099/0075.Sort-Colors.md" >}})|Medium| O(n)| O(1)|❤️|49.3%|
|
||||
|0147|Insertion Sort List|[Go]({{< relref "/ChapterFour/0100~0199/0147.Insertion-Sort-List.md" >}})|Medium| O(n)| O(1) |❤️|44.3%|
|
||||
|0148|Sort List|[Go]({{< relref "/ChapterFour/0100~0199/0148.Sort-List.md" >}})|Medium|O(n log n)| O(log n)|❤️|46.1%|
|
||||
|0164|Maximum Gap|[Go]({{< relref "/ChapterFour/0100~0199/0164.Maximum-Gap.md" >}})|Hard| O(n log n)| O(log n) |❤️|36.7%|
|
||||
|0164|Maximum Gap|[Go]({{< relref "/ChapterFour/0100~0199/0164.Maximum-Gap.md" >}})|Hard| O(n log n)| O(log n) |❤️|36.8%|
|
||||
|0179|Largest Number|[Go]({{< relref "/ChapterFour/0100~0199/0179.Largest-Number.md" >}})|Medium| O(n log n)| O(log n) |❤️|30.6%|
|
||||
|0220|Contains Duplicate III|[Go]({{< relref "/ChapterFour/0200~0299/0220.Contains-Duplicate-III.md" >}})|Medium| O(n log n)| O(1) |❤️|21.3%|
|
||||
|0242|Valid Anagram|[Go]({{< relref "/ChapterFour/0200~0299/0242.Valid-Anagram.md" >}})|Easy| O(n)| O(n) ||58.5%|
|
||||
|0274|H-Index|[Go]({{< relref "/ChapterFour/0200~0299/0274.H-Index.md" >}})|Medium| O(n)| O(n) ||36.3%|
|
||||
|0315|Count of Smaller Numbers After Self|[Go]({{< relref "/ChapterFour/0300~0399/0315.Count-of-Smaller-Numbers-After-Self.md" >}})|Hard||||42.5%|
|
||||
|0324|Wiggle Sort II|[Go]({{< relref "/ChapterFour/0300~0399/0324.Wiggle-Sort-II.md" >}})|Medium| O(n)| O(n)|❤️|30.6%|
|
||||
|0324|Wiggle Sort II|[Go]({{< relref "/ChapterFour/0300~0399/0324.Wiggle-Sort-II.md" >}})|Medium| O(n)| O(n)|❤️|30.7%|
|
||||
|0327|Count of Range Sum|[Go]({{< relref "/ChapterFour/0300~0399/0327.Count-of-Range-Sum.md" >}})|Hard||||36.0%|
|
||||
|0349|Intersection of Two Arrays|[Go]({{< relref "/ChapterFour/0300~0399/0349.Intersection-of-Two-Arrays.md" >}})|Easy| O(n)| O(n) ||64.7%|
|
||||
|0350|Intersection of Two Arrays II|[Go]({{< relref "/ChapterFour/0300~0399/0350.Intersection-of-Two-Arrays-II.md" >}})|Easy| O(n)| O(n) ||52.0%|
|
||||
@ -37,7 +37,7 @@ weight: 14
|
||||
|0524|Longest Word in Dictionary through Deleting|[Go]({{< relref "/ChapterFour/0500~0599/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})|Medium| O(n)| O(1) ||49.0%|
|
||||
|0710|Random Pick with Blacklist|[Go]({{< relref "/ChapterFour/0700~0799/0710.Random-Pick-with-Blacklist.md" >}})|Hard| O(n)| O(n) ||32.7%|
|
||||
|0767|Reorganize String|[Go]({{< relref "/ChapterFour/0700~0799/0767.Reorganize-String.md" >}})|Medium| O(n log n)| O(log n) |❤️|50.0%|
|
||||
|0853|Car Fleet|[Go]({{< relref "/ChapterFour/0800~0899/0853.Car-Fleet.md" >}})|Medium| O(n log n)| O(log n) ||43.7%|
|
||||
|0853|Car Fleet|[Go]({{< relref "/ChapterFour/0800~0899/0853.Car-Fleet.md" >}})|Medium| O(n log n)| O(log n) ||43.8%|
|
||||
|0922|Sort Array By Parity II|[Go]({{< relref "/ChapterFour/0900~0999/0922.Sort-Array-By-Parity-II.md" >}})|Easy| O(n)| O(1) ||70.5%|
|
||||
|0969|Pancake Sorting|[Go]({{< relref "/ChapterFour/0900~0999/0969.Pancake-Sorting.md" >}})|Medium| O(n log n)| O(log n) |❤️|68.6%|
|
||||
|0973|K Closest Points to Origin|[Go]({{< relref "/ChapterFour/0900~0999/0973.K-Closest-Points-to-Origin.md" >}})|Medium| O(n log n)| O(log n) ||64.6%|
|
||||
@ -52,7 +52,8 @@ weight: 14
|
||||
|1640|Check Array Formation Through Concatenation|[Go]({{< relref "/ChapterFour/1600~1699/1640.Check-Array-Formation-Through-Concatenation.md" >}})|Easy||||60.1%|
|
||||
|1647|Minimum Deletions to Make Character Frequencies Unique|[Go]({{< relref "/ChapterFour/1600~1699/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique.md" >}})|Medium||||54.5%|
|
||||
|1648|Sell Diminishing-Valued Colored Balls|[Go]({{< relref "/ChapterFour/1600~1699/1648.Sell-Diminishing-Valued-Colored-Balls.md" >}})|Medium||||30.8%|
|
||||
|1691|Maximum Height by Stacking Cuboids|[Go]({{< relref "/ChapterFour/1600~1699/1691.Maximum-Height-by-Stacking-Cuboids.md" >}})|Hard||||50.0%|
|
||||
|1691|Maximum Height by Stacking Cuboids|[Go]({{< relref "/ChapterFour/1600~1699/1691.Maximum-Height-by-Stacking-Cuboids.md" >}})|Hard||||49.9%|
|
||||
|1710|Maximum Units on a Truck|[Go]({{< relref "/ChapterFour/1700~1799/1710.Maximum-Units-on-a-Truck.md" >}})|Easy||||70.5%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
||||
|
@ -18,13 +18,13 @@ weight: 5
|
||||
| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
|
||||
|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
|
||||
|0020|Valid Parentheses|[Go]({{< relref "/ChapterFour/0001~0099/0020.Valid-Parentheses.md" >}})|Easy| O(log n)| O(1)||39.8%|
|
||||
|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0001~0099/0042.Trapping-Rain-Water.md" >}})|Hard| O(n)| O(1)|❤️|51.0%|
|
||||
|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0001~0099/0042.Trapping-Rain-Water.md" >}})|Hard| O(n)| O(1)|❤️|51.1%|
|
||||
|0071|Simplify Path|[Go]({{< relref "/ChapterFour/0001~0099/0071.Simplify-Path.md" >}})|Medium| O(n)| O(n)|❤️|34.6%|
|
||||
|0084|Largest Rectangle in Histogram|[Go]({{< relref "/ChapterFour/0001~0099/0084.Largest-Rectangle-in-Histogram.md" >}})|Hard| O(n)| O(n)|❤️|37.0%|
|
||||
|0094|Binary Tree Inorder Traversal|[Go]({{< relref "/ChapterFour/0001~0099/0094.Binary-Tree-Inorder-Traversal.md" >}})|Medium| O(n)| O(1)||65.7%|
|
||||
|0103|Binary Tree Zigzag Level Order Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})|Medium| O(n)| O(n)||50.0%|
|
||||
|0144|Binary Tree Preorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0144.Binary-Tree-Preorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.4%|
|
||||
|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0145.Binary-Tree-Postorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.4%|
|
||||
|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0145.Binary-Tree-Postorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.5%|
|
||||
|0150|Evaluate Reverse Polish Notation|[Go]({{< relref "/ChapterFour/0100~0199/0150.Evaluate-Reverse-Polish-Notation.md" >}})|Medium| O(n)| O(1)||37.8%|
|
||||
|0155|Min Stack|[Go]({{< relref "/ChapterFour/0100~0199/0155.Min-Stack.md" >}})|Easy| O(n)| O(n)||46.3%|
|
||||
|0173|Binary Search Tree Iterator|[Go]({{< relref "/ChapterFour/0100~0199/0173.Binary-Search-Tree-Iterator.md" >}})|Medium| O(n)| O(1)||60.0%|
|
||||
@ -36,12 +36,12 @@ weight: 5
|
||||
|0394|Decode String|[Go]({{< relref "/ChapterFour/0300~0399/0394.Decode-String.md" >}})|Medium| O(n)| O(n)||52.6%|
|
||||
|0402|Remove K Digits|[Go]({{< relref "/ChapterFour/0400~0499/0402.Remove-K-Digits.md" >}})|Medium| O(n)| O(1)||28.6%|
|
||||
|0456|132 Pattern|[Go]({{< relref "/ChapterFour/0400~0499/0456.132-Pattern.md" >}})|Medium| O(n)| O(n)||30.6%|
|
||||
|0496|Next Greater Element I|[Go]({{< relref "/ChapterFour/0400~0499/0496.Next-Greater-Element-I.md" >}})|Easy| O(n)| O(n)||65.4%|
|
||||
|0496|Next Greater Element I|[Go]({{< relref "/ChapterFour/0400~0499/0496.Next-Greater-Element-I.md" >}})|Easy| O(n)| O(n)||65.5%|
|
||||
|0503|Next Greater Element II|[Go]({{< relref "/ChapterFour/0500~0599/0503.Next-Greater-Element-II.md" >}})|Medium| O(n)| O(n)||58.4%|
|
||||
|0636|Exclusive Time of Functions|[Go]({{< relref "/ChapterFour/0600~0699/0636.Exclusive-Time-of-Functions.md" >}})|Medium| O(n)| O(n)||54.3%|
|
||||
|0682|Baseball Game|[Go]({{< relref "/ChapterFour/0600~0699/0682.Baseball-Game.md" >}})|Easy| O(n)| O(n)||66.7%|
|
||||
|0726|Number of Atoms|[Go]({{< relref "/ChapterFour/0700~0799/0726.Number-of-Atoms.md" >}})|Hard| O(n)| O(n) |❤️|51.1%|
|
||||
|0735|Asteroid Collision|[Go]({{< relref "/ChapterFour/0700~0799/0735.Asteroid-Collision.md" >}})|Medium| O(n)| O(n) ||43.3%|
|
||||
|0735|Asteroid Collision|[Go]({{< relref "/ChapterFour/0700~0799/0735.Asteroid-Collision.md" >}})|Medium| O(n)| O(n) ||43.2%|
|
||||
|0739|Daily Temperatures|[Go]({{< relref "/ChapterFour/0700~0799/0739.Daily-Temperatures.md" >}})|Medium| O(n)| O(n) ||64.5%|
|
||||
|0844|Backspace String Compare|[Go]({{< relref "/ChapterFour/0800~0899/0844.Backspace-String-Compare.md" >}})|Easy| O(n)| O(n) ||46.9%|
|
||||
|0856|Score of Parentheses|[Go]({{< relref "/ChapterFour/0800~0899/0856.Score-of-Parentheses.md" >}})|Medium| O(n)| O(n)||62.4%|
|
||||
@ -54,7 +54,7 @@ weight: 5
|
||||
|1003|Check If Word Is Valid After Substitutions|[Go]({{< relref "/ChapterFour/1000~1099/1003.Check-If-Word-Is-Valid-After-Substitutions.md" >}})|Medium| O(n)| O(1)||56.3%|
|
||||
|1019|Next Greater Node In Linked List|[Go]({{< relref "/ChapterFour/1000~1099/1019.Next-Greater-Node-In-Linked-List.md" >}})|Medium| O(n)| O(1)||58.2%|
|
||||
|1021|Remove Outermost Parentheses|[Go]({{< relref "/ChapterFour/1000~1099/1021.Remove-Outermost-Parentheses.md" >}})|Easy| O(n)| O(1)||79.0%|
|
||||
|1047|Remove All Adjacent Duplicates In String|[Go]({{< relref "/ChapterFour/1000~1099/1047.Remove-All-Adjacent-Duplicates-In-String.md" >}})|Easy| O(n)| O(1)||70.6%|
|
||||
|1047|Remove All Adjacent Duplicates In String|[Go]({{< relref "/ChapterFour/1000~1099/1047.Remove-All-Adjacent-Duplicates-In-String.md" >}})|Easy| O(n)| O(1)||70.7%|
|
||||
|1673|Find the Most Competitive Subsequence|[Go]({{< relref "/ChapterFour/1600~1699/1673.Find-the-Most-Competitive-Subsequence.md" >}})|Medium||||45.2%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
@ -21,7 +21,7 @@ weight: 2
|
||||
|0071|Simplify Path|[Go]({{< relref "/ChapterFour/0001~0099/0071.Simplify-Path.md" >}})|Medium| O(n)| O(n)||34.6%|
|
||||
|0076|Minimum Window Substring|[Go]({{< relref "/ChapterFour/0001~0099/0076.Minimum-Window-Substring.md" >}})|Hard| O(n)| O(n)|❤️|35.9%|
|
||||
|0091|Decode Ways|[Go]({{< relref "/ChapterFour/0001~0099/0091.Decode-Ways.md" >}})|Medium| O(n)| O(n)||26.5%|
|
||||
|0093|Restore IP Addresses|[Go]({{< relref "/ChapterFour/0001~0099/0093.Restore-IP-Addresses.md" >}})|Medium| O(n)| O(n)|❤️|37.4%|
|
||||
|0093|Restore IP Addresses|[Go]({{< relref "/ChapterFour/0001~0099/0093.Restore-IP-Addresses.md" >}})|Medium| O(n)| O(n)|❤️|37.5%|
|
||||
|0125|Valid Palindrome|[Go]({{< relref "/ChapterFour/0100~0199/0125.Valid-Palindrome.md" >}})|Easy| O(n)| O(1)||38.1%|
|
||||
|0126|Word Ladder II|[Go]({{< relref "/ChapterFour/0100~0199/0126.Word-Ladder-II.md" >}})|Hard| O(n)| O(n^2)|❤️|23.6%|
|
||||
|0151|Reverse Words in a String|[Go]({{< relref "/ChapterFour/0100~0199/0151.Reverse-Words-in-a-String.md" >}})|Medium||||23.6%|
|
||||
@ -32,7 +32,7 @@ weight: 2
|
||||
|0537|Complex Number Multiplication|[Go]({{< relref "/ChapterFour/0500~0599/0537.Complex-Number-Multiplication.md" >}})|Medium||||68.3%|
|
||||
|0541|Reverse String II|[Go]({{< relref "/ChapterFour/0500~0599/0541.Reverse-String-II.md" >}})|Easy||||49.1%|
|
||||
|0557|Reverse Words in a String III|[Go]({{< relref "/ChapterFour/0500~0599/0557.Reverse-Words-in-a-String-III.md" >}})|Easy||||71.8%|
|
||||
|0632|Smallest Range Covering Elements from K Lists|[Go]({{< relref "/ChapterFour/0600~0699/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})|Hard||||54.1%|
|
||||
|0632|Smallest Range Covering Elements from K Lists|[Go]({{< relref "/ChapterFour/0600~0699/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})|Hard||||54.2%|
|
||||
|0767|Reorganize String|[Go]({{< relref "/ChapterFour/0700~0799/0767.Reorganize-String.md" >}})|Medium| O(n log n)| O(log n) |❤️|50.0%|
|
||||
|0819|Most Common Word|[Go]({{< relref "/ChapterFour/0800~0899/0819.Most-Common-Word.md" >}})|Easy||||45.5%|
|
||||
|0842|Split Array into Fibonacci Sequence|[Go]({{< relref "/ChapterFour/0800~0899/0842.Split-Array-into-Fibonacci-Sequence.md" >}})|Medium| O(n^2)| O(1)|❤️|36.8%|
|
||||
@ -45,16 +45,17 @@ weight: 2
|
||||
|1221|Split a String in Balanced Strings|[Go]({{< relref "/ChapterFour/1200~1299/1221.Split-a-String-in-Balanced-Strings.md" >}})|Easy||||84.1%|
|
||||
|1234|Replace the Substring for Balanced String|[Go]({{< relref "/ChapterFour/1200~1299/1234.Replace-the-Substring-for-Balanced-String.md" >}})|Medium||||34.3%|
|
||||
|1455|Check If a Word Occurs As a Prefix of Any Word in a Sentence|[Go]({{< relref "/ChapterFour/1400~1499/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md" >}})|Easy||||64.4%|
|
||||
|1573|Number of Ways to Split a String|[Go]({{< relref "/ChapterFour/1500~1599/1573.Number-of-Ways-to-Split-a-String.md" >}})|Medium||||31.0%|
|
||||
|1614|Maximum Nesting Depth of the Parentheses|[Go]({{< relref "/ChapterFour/1600~1699/1614.Maximum-Nesting-Depth-of-the-Parentheses.md" >}})|Easy||||83.1%|
|
||||
|1573|Number of Ways to Split a String|[Go]({{< relref "/ChapterFour/1500~1599/1573.Number-of-Ways-to-Split-a-String.md" >}})|Medium||||31.1%|
|
||||
|1614|Maximum Nesting Depth of the Parentheses|[Go]({{< relref "/ChapterFour/1600~1699/1614.Maximum-Nesting-Depth-of-the-Parentheses.md" >}})|Easy||||83.0%|
|
||||
|1624|Largest Substring Between Two Equal Characters|[Go]({{< relref "/ChapterFour/1600~1699/1624.Largest-Substring-Between-Two-Equal-Characters.md" >}})|Easy||||58.9%|
|
||||
|1653|Minimum Deletions to Make String Balanced|[Go]({{< relref "/ChapterFour/1600~1699/1653.Minimum-Deletions-to-Make-String-Balanced.md" >}})|Medium||||50.5%|
|
||||
|1662|Check If Two String Arrays are Equivalent|[Go]({{< relref "/ChapterFour/1600~1699/1662.Check-If-Two-String-Arrays-are-Equivalent.md" >}})|Easy||||83.2%|
|
||||
|1668|Maximum Repeating Substring|[Go]({{< relref "/ChapterFour/1600~1699/1668.Maximum-Repeating-Substring.md" >}})|Easy||||38.5%|
|
||||
|1668|Maximum Repeating Substring|[Go]({{< relref "/ChapterFour/1600~1699/1668.Maximum-Repeating-Substring.md" >}})|Easy||||38.6%|
|
||||
|1678|Goal Parser Interpretation|[Go]({{< relref "/ChapterFour/1600~1699/1678.Goal-Parser-Interpretation.md" >}})|Easy||||85.7%|
|
||||
|1684|Count the Number of Consistent Strings|[Go]({{< relref "/ChapterFour/1600~1699/1684.Count-the-Number-of-Consistent-Strings.md" >}})|Easy||||83.2%|
|
||||
|1694|Reformat Phone Number|[Go]({{< relref "/ChapterFour/1600~1699/1694.Reformat-Phone-Number.md" >}})|Easy||||66.2%|
|
||||
|1694|Reformat Phone Number|[Go]({{< relref "/ChapterFour/1600~1699/1694.Reformat-Phone-Number.md" >}})|Easy||||66.3%|
|
||||
|1704|Determine if String Halves Are Alike|[Go]({{< relref "/ChapterFour/1700~1799/1704.Determine-if-String-Halves-Are-Alike.md" >}})|Easy||||77.6%|
|
||||
|1736|Latest Time by Replacing Hidden Digits|[Go]({{< relref "/ChapterFour/1700~1799/1736.Latest-Time-by-Replacing-Hidden-Digits.md" >}})|Easy||||41.1%|
|
||||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ weight: 6
|
||||
|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
|
||||
|0094|Binary Tree Inorder Traversal|[Go]({{< relref "/ChapterFour/0001~0099/0094.Binary-Tree-Inorder-Traversal.md" >}})|Medium| O(n)| O(1)||65.7%|
|
||||
|0095|Unique Binary Search Trees II|[Go]({{< relref "/ChapterFour/0001~0099/0095.Unique-Binary-Search-Trees-II.md" >}})|Medium||||42.4%|
|
||||
|0096|Unique Binary Search Trees|[Go]({{< relref "/ChapterFour/0001~0099/0096.Unique-Binary-Search-Trees.md" >}})|Medium| O(n^2)| O(n)||54.3%|
|
||||
|0096|Unique Binary Search Trees|[Go]({{< relref "/ChapterFour/0001~0099/0096.Unique-Binary-Search-Trees.md" >}})|Medium| O(n^2)| O(n)||54.4%|
|
||||
|0098|Validate Binary Search Tree|[Go]({{< relref "/ChapterFour/0001~0099/0098.Validate-Binary-Search-Tree.md" >}})|Medium| O(n)| O(1)||28.7%|
|
||||
|0099|Recover Binary Search Tree|[Go]({{< relref "/ChapterFour/0001~0099/0099.Recover-Binary-Search-Tree.md" >}})|Hard| O(n)| O(1)||42.4%|
|
||||
|0100|Same Tree|[Go]({{< relref "/ChapterFour/0100~0199/0100.Same-Tree.md" >}})|Easy| O(n)| O(1)||54.1%|
|
||||
@ -24,21 +24,21 @@ weight: 6
|
||||
|0107|Binary Tree Level Order Traversal II|[Go]({{< relref "/ChapterFour/0100~0199/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})|Easy| O(n)| O(1)||55.1%|
|
||||
|0108|Convert Sorted Array to Binary Search Tree|[Go]({{< relref "/ChapterFour/0100~0199/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})|Easy| O(n)| O(1)||60.3%|
|
||||
|0110|Balanced Binary Tree|[Go]({{< relref "/ChapterFour/0100~0199/0110.Balanced-Binary-Tree.md" >}})|Easy| O(n)| O(1)||44.7%|
|
||||
|0111|Minimum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0100~0199/0111.Minimum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||39.4%|
|
||||
|0112|Path Sum|[Go]({{< relref "/ChapterFour/0100~0199/0112.Path-Sum.md" >}})|Easy| O(n)| O(1)||42.3%|
|
||||
|0111|Minimum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0100~0199/0111.Minimum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||39.5%|
|
||||
|0112|Path Sum|[Go]({{< relref "/ChapterFour/0100~0199/0112.Path-Sum.md" >}})|Easy| O(n)| O(1)||42.4%|
|
||||
|0113|Path Sum II|[Go]({{< relref "/ChapterFour/0100~0199/0113.Path-Sum-II.md" >}})|Medium| O(n)| O(1)||49.0%|
|
||||
|0114|Flatten Binary Tree to Linked List|[Go]({{< relref "/ChapterFour/0100~0199/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})|Medium| O(n)| O(1)||51.8%|
|
||||
|0124|Binary Tree Maximum Path Sum|[Go]({{< relref "/ChapterFour/0100~0199/0124.Binary-Tree-Maximum-Path-Sum.md" >}})|Hard| O(n)| O(1)||35.4%|
|
||||
|0129|Sum Root to Leaf Numbers|[Go]({{< relref "/ChapterFour/0100~0199/0129.Sum-Root-to-Leaf-Numbers.md" >}})|Medium| O(n)| O(1)||50.8%|
|
||||
|0144|Binary Tree Preorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0144.Binary-Tree-Preorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.4%|
|
||||
|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0145.Binary-Tree-Postorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.4%|
|
||||
|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0145.Binary-Tree-Postorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.5%|
|
||||
|0173|Binary Search Tree Iterator|[Go]({{< relref "/ChapterFour/0100~0199/0173.Binary-Search-Tree-Iterator.md" >}})|Medium| O(n)| O(1)||60.0%|
|
||||
|0199|Binary Tree Right Side View|[Go]({{< relref "/ChapterFour/0100~0199/0199.Binary-Tree-Right-Side-View.md" >}})|Medium| O(n)| O(1)||56.3%|
|
||||
|0222|Count Complete Tree Nodes|[Go]({{< relref "/ChapterFour/0200~0299/0222.Count-Complete-Tree-Nodes.md" >}})|Medium| O(n)| O(1)||49.1%|
|
||||
|0222|Count Complete Tree Nodes|[Go]({{< relref "/ChapterFour/0200~0299/0222.Count-Complete-Tree-Nodes.md" >}})|Medium| O(n)| O(1)||49.2%|
|
||||
|0226|Invert Binary Tree|[Go]({{< relref "/ChapterFour/0200~0299/0226.Invert-Binary-Tree.md" >}})|Easy| O(n)| O(1)||66.9%|
|
||||
|0230|Kth Smallest Element in a BST|[Go]({{< relref "/ChapterFour/0200~0299/0230.Kth-Smallest-Element-in-a-BST.md" >}})|Medium| O(n)| O(1)||62.5%|
|
||||
|0235|Lowest Common Ancestor of a Binary Search Tree|[Go]({{< relref "/ChapterFour/0200~0299/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md" >}})|Easy| O(n)| O(1)||51.6%|
|
||||
|0236|Lowest Common Ancestor of a Binary Tree|[Go]({{< relref "/ChapterFour/0200~0299/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md" >}})|Medium| O(n)| O(1)||48.5%|
|
||||
|0235|Lowest Common Ancestor of a Binary Search Tree|[Go]({{< relref "/ChapterFour/0200~0299/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md" >}})|Easy| O(n)| O(1)||51.7%|
|
||||
|0236|Lowest Common Ancestor of a Binary Tree|[Go]({{< relref "/ChapterFour/0200~0299/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md" >}})|Medium| O(n)| O(1)||48.6%|
|
||||
|0257|Binary Tree Paths|[Go]({{< relref "/ChapterFour/0200~0299/0257.Binary-Tree-Paths.md" >}})|Easy| O(n)| O(1)||53.5%|
|
||||
|0337|House Robber III|[Go]({{< relref "/ChapterFour/0300~0399/0337.House-Robber-III.md" >}})|Medium||||51.8%|
|
||||
|0404|Sum of Left Leaves|[Go]({{< relref "/ChapterFour/0400~0499/0404.Sum-of-Left-Leaves.md" >}})|Easy| O(n)| O(1)||52.2%|
|
||||
@ -61,7 +61,7 @@ weight: 6
|
||||
|0897|Increasing Order Search Tree|[Go]({{< relref "/ChapterFour/0800~0899/0897.Increasing-Order-Search-Tree.md" >}})|Easy||||74.5%|
|
||||
|0968|Binary Tree Cameras|[Go]({{< relref "/ChapterFour/0900~0999/0968.Binary-Tree-Cameras.md" >}})|Hard||||38.7%|
|
||||
|0979|Distribute Coins in Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0979.Distribute-Coins-in-Binary-Tree.md" >}})|Medium||||69.7%|
|
||||
|0987|Vertical Order Traversal of a Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0987.Vertical-Order-Traversal-of-a-Binary-Tree.md" >}})|Hard||||38.7%|
|
||||
|0987|Vertical Order Traversal of a Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0987.Vertical-Order-Traversal-of-a-Binary-Tree.md" >}})|Hard||||38.8%|
|
||||
|0993|Cousins in Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0993.Cousins-in-Binary-Tree.md" >}})|Easy| O(n)| O(1)||52.3%|
|
||||
|1026|Maximum Difference Between Node and Ancestor|[Go]({{< relref "/ChapterFour/1000~1099/1026.Maximum-Difference-Between-Node-and-Ancestor.md" >}})|Medium||||69.4%|
|
||||
|1028|Recover a Tree From Preorder Traversal|[Go]({{< relref "/ChapterFour/1000~1099/1028.Recover-a-Tree-From-Preorder-Traversal.md" >}})|Hard||||70.9%|
|
||||
|
@ -34,7 +34,7 @@ weight: 3
|
||||
|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
|
||||
|0003|Longest Substring Without Repeating Characters|[Go]({{< relref "/ChapterFour/0001~0099/0003.Longest-Substring-Without-Repeating-Characters.md" >}})|Medium| O(n)| O(1)|❤️|31.4%|
|
||||
|0011|Container With Most Water|[Go]({{< relref "/ChapterFour/0001~0099/0011.Container-With-Most-Water.md" >}})|Medium| O(n)| O(1)||52.4%|
|
||||
|0015|3Sum|[Go]({{< relref "/ChapterFour/0001~0099/0015.3Sum.md" >}})|Medium| O(n^2)| O(n)|❤️|27.9%|
|
||||
|0015|3Sum|[Go]({{< relref "/ChapterFour/0001~0099/0015.3Sum.md" >}})|Medium| O(n^2)| O(n)|❤️|28.0%|
|
||||
|0016|3Sum Closest|[Go]({{< relref "/ChapterFour/0001~0099/0016.3Sum-Closest.md" >}})|Medium| O(n^2)| O(1)|❤️|46.3%|
|
||||
|0018|4Sum|[Go]({{< relref "/ChapterFour/0001~0099/0018.4Sum.md" >}})|Medium| O(n^3)| O(n^2)|❤️|34.8%|
|
||||
|0019|Remove Nth Node From End of List|[Go]({{< relref "/ChapterFour/0001~0099/0019.Remove-Nth-Node-From-End-of-List.md" >}})|Medium| O(n)| O(1)||35.7%|
|
||||
@ -42,7 +42,7 @@ weight: 3
|
||||
|0027|Remove Element|[Go]({{< relref "/ChapterFour/0001~0099/0027.Remove-Element.md" >}})|Easy| O(n)| O(1)||49.2%|
|
||||
|0028|Implement strStr()|[Go]({{< relref "/ChapterFour/0001~0099/0028.Implement-strStr.md" >}})|Easy| O(n)| O(1)||35.2%|
|
||||
|0030|Substring with Concatenation of All Words|[Go]({{< relref "/ChapterFour/0001~0099/0030.Substring-with-Concatenation-of-All-Words.md" >}})|Hard| O(n)| O(n)|❤️|26.2%|
|
||||
|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0001~0099/0042.Trapping-Rain-Water.md" >}})|Hard| O(n)| O(1)|❤️|51.0%|
|
||||
|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0001~0099/0042.Trapping-Rain-Water.md" >}})|Hard| O(n)| O(1)|❤️|51.1%|
|
||||
|0061|Rotate List|[Go]({{< relref "/ChapterFour/0001~0099/0061.Rotate-List.md" >}})|Medium| O(n)| O(1)||31.7%|
|
||||
|0075|Sort Colors|[Go]({{< relref "/ChapterFour/0001~0099/0075.Sort-Colors.md" >}})|Medium| O(n)| O(1)|❤️|49.3%|
|
||||
|0076|Minimum Window Substring|[Go]({{< relref "/ChapterFour/0001~0099/0076.Minimum-Window-Substring.md" >}})|Hard| O(n)| O(n)|❤️|35.9%|
|
||||
@ -66,7 +66,7 @@ weight: 3
|
||||
|0524|Longest Word in Dictionary through Deleting|[Go]({{< relref "/ChapterFour/0500~0599/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})|Medium| O(n)| O(1) ||49.0%|
|
||||
|0532|K-diff Pairs in an Array|[Go]({{< relref "/ChapterFour/0500~0599/0532.K-diff-Pairs-in-an-Array.md" >}})|Medium| O(n)| O(n)||35.1%|
|
||||
|0567|Permutation in String|[Go]({{< relref "/ChapterFour/0500~0599/0567.Permutation-in-String.md" >}})|Medium| O(n)| O(1)|❤️|44.6%|
|
||||
|0632|Smallest Range Covering Elements from K Lists|[Go]({{< relref "/ChapterFour/0600~0699/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})|Hard||||54.1%|
|
||||
|0632|Smallest Range Covering Elements from K Lists|[Go]({{< relref "/ChapterFour/0600~0699/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})|Hard||||54.2%|
|
||||
|0713|Subarray Product Less Than K|[Go]({{< relref "/ChapterFour/0700~0799/0713.Subarray-Product-Less-Than-K.md" >}})|Medium| O(n)| O(1)||40.5%|
|
||||
|0763|Partition Labels|[Go]({{< relref "/ChapterFour/0700~0799/0763.Partition-Labels.md" >}})|Medium| O(n)| O(1)|❤️|78.0%|
|
||||
|0826|Most Profit Assigning Work|[Go]({{< relref "/ChapterFour/0800~0899/0826.Most-Profit-Assigning-Work.md" >}})|Medium| O(n log n)| O(n)||39.1%|
|
||||
|
@ -22,15 +22,15 @@ weight: 16
|
||||
|0128|Longest Consecutive Sequence|[Go]({{< relref "/ChapterFour/0100~0199/0128.Longest-Consecutive-Sequence.md" >}})|Hard| O(n)| O(n)|❤️|46.2%|
|
||||
|0130|Surrounded Regions|[Go]({{< relref "/ChapterFour/0100~0199/0130.Surrounded-Regions.md" >}})|Medium| O(m\*n)| O(m\*n)||29.3%|
|
||||
|0200|Number of Islands|[Go]({{< relref "/ChapterFour/0200~0299/0200.Number-of-Islands.md" >}})|Medium| O(m\*n)| O(m\*n)||49.0%|
|
||||
|0399|Evaluate Division|[Go]({{< relref "/ChapterFour/0300~0399/0399.Evaluate-Division.md" >}})|Medium| O(n)| O(n)||54.2%|
|
||||
|0399|Evaluate Division|[Go]({{< relref "/ChapterFour/0300~0399/0399.Evaluate-Division.md" >}})|Medium| O(n)| O(n)||54.3%|
|
||||
|0547|Number of Provinces|[Go]({{< relref "/ChapterFour/0500~0599/0547.Number-of-Provinces.md" >}})|Medium| O(n^2)| O(n)||60.4%|
|
||||
|0684|Redundant Connection|[Go]({{< relref "/ChapterFour/0600~0699/0684.Redundant-Connection.md" >}})|Medium| O(n)| O(n)||58.9%|
|
||||
|0685|Redundant Connection II|[Go]({{< relref "/ChapterFour/0600~0699/0685.Redundant-Connection-II.md" >}})|Hard| O(n)| O(n)||33.0%|
|
||||
|0721|Accounts Merge|[Go]({{< relref "/ChapterFour/0700~0799/0721.Accounts-Merge.md" >}})|Medium| O(n)| O(n)|❤️|51.6%|
|
||||
|0721|Accounts Merge|[Go]({{< relref "/ChapterFour/0700~0799/0721.Accounts-Merge.md" >}})|Medium| O(n)| O(n)|❤️|51.7%|
|
||||
|0765|Couples Holding Hands|[Go]({{< relref "/ChapterFour/0700~0799/0765.Couples-Holding-Hands.md" >}})|Hard| O(n)| O(n)|❤️|55.5%|
|
||||
|0778|Swim in Rising Water|[Go]({{< relref "/ChapterFour/0700~0799/0778.Swim-in-Rising-Water.md" >}})|Hard| O(n^2)| O(n)|❤️|54.8%|
|
||||
|0803|Bricks Falling When Hit|[Go]({{< relref "/ChapterFour/0800~0899/0803.Bricks-Falling-When-Hit.md" >}})|Hard| O(n^2)| O(n)|❤️|31.4%|
|
||||
|0839|Similar String Groups|[Go]({{< relref "/ChapterFour/0800~0899/0839.Similar-String-Groups.md" >}})|Hard| O(n^2)| O(n)||40.5%|
|
||||
|0839|Similar String Groups|[Go]({{< relref "/ChapterFour/0800~0899/0839.Similar-String-Groups.md" >}})|Hard| O(n^2)| O(n)||40.6%|
|
||||
|0924|Minimize Malware Spread|[Go]({{< relref "/ChapterFour/0900~0999/0924.Minimize-Malware-Spread.md" >}})|Hard| O(m\*n)| O(n)||41.9%|
|
||||
|0928|Minimize Malware Spread II|[Go]({{< relref "/ChapterFour/0900~0999/0928.Minimize-Malware-Spread-II.md" >}})|Hard| O(m\*n)| O(n)|❤️|41.2%|
|
||||
|0947|Most Stones Removed with Same Row or Column|[Go]({{< relref "/ChapterFour/0900~0999/0947.Most-Stones-Removed-with-Same-Row-or-Column.md" >}})|Medium| O(n)| O(n)||55.4%|
|
||||
|
Reference in New Issue
Block a user