更新 0209. 长度最小的子数组 排版格式修复

This commit is contained in:
jinbudaily
2023-07-17 15:32:24 +08:00
parent ec101bebb2
commit 76c84efca0

View File

@ -23,14 +23,14 @@
* 1 <= nums.length <= 10^5
* 1 <= nums[i] <= 10^5
# 算法公开课
## 算法公开课
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[拿下滑动窗口! | LeetCode 209 长度最小的子数组](https://www.bilibili.com/video/BV1tZ4y1q7XE),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
# 思路
## 思路
## 暴力解法
### 暴力解法
这道题目暴力解法当然是 两个for循环然后不断的寻找符合条件的子序列时间复杂度很明显是O(n^2)。
@ -64,7 +64,7 @@ public:
后面力扣更新了数据,暴力解法已经超时了。
## 滑动窗口
### 滑动窗口
接下来就开始介绍数组操作中另一个重要的方法:**滑动窗口**。
@ -151,8 +151,8 @@ public:
## 其他语言版本
### Java
Java
```java
class Solution {
@ -173,7 +173,7 @@ class Solution {
}
```
Python
### Python
```python
版本一滑动窗口法
@ -216,7 +216,8 @@ class Solution:
return min_len if min_len != float('inf') else 0
```
Go
### Go
```go
func minSubArrayLen(target int, nums []int) int {
i := 0
@ -242,8 +243,7 @@ func minSubArrayLen(target int, nums []int) int {
}
```
JavaScript:
### JavaScript:
```js
var minSubArrayLen = function(target, nums) {
@ -266,7 +266,7 @@ var minSubArrayLen = function(target, nums) {
};
```
Typescript
### Typescript
```typescript
function minSubArrayLen(target: number, nums: number[]): number {
@ -288,7 +288,7 @@ function minSubArrayLen(target: number, nums: number[]): number {
};
```
Swift:
### Swift:
```swift
func minSubArrayLen(_ target: Int, _ nums: [Int]) -> Int {
@ -309,7 +309,7 @@ func minSubArrayLen(_ target: Int, _ nums: [Int]) -> Int {
}
```
Rust:
### Rust:
```rust
impl Solution {
@ -336,7 +336,8 @@ impl Solution {
}
```
PHP:
### PHP:
```php
// 双指针 - 滑动窗口
class Solution {
@ -365,7 +366,7 @@ class Solution {
}
```
Ruby:
### Ruby:
```ruby
def min_sub_array_len(target, nums)
@ -383,8 +384,9 @@ def min_sub_array_len(target, nums)
end
```
C:
### C:
暴力解法:
```c
int minSubArrayLen(int target, int* nums, int numsSize){
//初始化最小长度为INT_MAX
@ -433,7 +435,8 @@ int minSubArrayLen(int target, int* nums, int numsSize){
}
```
Kotlin:
### Kotlin:
```kotlin
class Solution {
fun minSubArrayLen(target: Int, nums: IntArray): Int {
@ -485,7 +488,7 @@ class Solution {
}
}
```
Scala:
### Scala:
滑动窗口:
```scala
@ -533,7 +536,8 @@ object Solution {
}
}
```
C#:
### C#:
```csharp
public class Solution {
public int MinSubArrayLen(int s, int[] nums) {
@ -559,3 +563,4 @@ public class Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>