diff --git a/problems/0027.移除元素.md b/problems/0027.移除元素.md index 3d43a199..ce9eccf0 100644 --- a/problems/0027.移除元素.md +++ b/problems/0027.移除元素.md @@ -5,7 +5,7 @@
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
-## 27. 移除元素 +# 27. 移除元素 [力扣题目链接](https://leetcode.cn/problems/remove-element/) @@ -159,8 +159,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java class Solution { public int removeElement(int[] nums, int val) { @@ -197,7 +197,7 @@ class Solution { } ``` -Python: +### Python: ``` python 3 @@ -233,8 +233,8 @@ class Solution: ``` +### Go: -Go: ```go func removeElement(nums []int, val int) int { length:=len(nums) @@ -275,7 +275,8 @@ func removeElement(nums []int, val int) int { } ``` -JavaScript: +### JavaScript: + ```javascript //时间复杂度:O(n) //空间复杂度:O(1) @@ -290,7 +291,7 @@ var removeElement = (nums, val) => { }; ``` -TypeScript: +### TypeScript: ```typescript function removeElement(nums: number[], val: number): number { @@ -305,7 +306,7 @@ function removeElement(nums: number[], val: number): number { }; ``` -Ruby: +### Ruby: ```ruby def remove_element(nums, val) @@ -319,7 +320,8 @@ def remove_element(nums, val) i end ``` -Rust: +### Rust: + ```rust impl Solution { pub fn remove_element(nums: &mut Vec
+
diff --git a/problems/0209.长度最小的子数组.md b/problems/0209.长度最小的子数组.md
index 82d551ea..4b1d0e96 100644
--- a/problems/0209.长度最小的子数组.md
+++ b/problems/0209.长度最小的子数组.md
@@ -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 {
+
diff --git a/problems/0977.有序数组的平方.md b/problems/0977.有序数组的平方.md
index de06c419..4bee585b 100644
--- a/problems/0977.有序数组的平方.md
+++ b/problems/0977.有序数组的平方.md
@@ -21,14 +21,14 @@
* 输入:nums = [-7,-3,2,3,11]
* 输出:[4,9,9,49,121]
-# 算法公开课
+## 算法公开课
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[双指针法经典题目!LeetCode:977.有序数组的平方](https://www.bilibili.com/video/BV1QB4y1D7ep),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
-# 思路
+## 思路
-## 暴力排序
+### 暴力排序
最直观的想法,莫过于:每个数平方之后,排个序,美滋滋,代码如下:
@@ -47,7 +47,7 @@ public:
这个时间复杂度是 O(n + nlogn), 可以说是O(nlogn)的时间复杂度,但为了和下面双指针法算法时间复杂度有鲜明对比,我记为 O(n + nlog n)。
-## 双指针法
+### 双指针法
数组其实是有序的, 只不过负数平方之后可能成为最大数了。
@@ -99,7 +99,8 @@ public:
## 其他语言版本
-Java:
+### Java:
+
```Java
class Solution {
public int[] sortedSquares(int[] nums) {
@@ -141,7 +142,8 @@ class Solution {
}
```
-Python:
+### Python:
+
```Python
(版本一)双指针法
class Solution:
@@ -176,7 +178,8 @@ class Solution:
return sorted(x*x for x in nums)
```
-Go:
+### Go:
+
```Go
func sortedSquares(nums []int) []int {
n := len(nums)
@@ -196,7 +199,8 @@ func sortedSquares(nums []int) []int {
return ans
}
```
-Rust
+### Rust:
+
```rust
impl Solution {
pub fn sorted_squares(nums: Vec
+
diff --git a/problems/数组总结篇.md b/problems/数组总结篇.md
index ef962187..7550ce02 100644
--- a/problems/数组总结篇.md
+++ b/problems/数组总结篇.md
@@ -4,9 +4,9 @@
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+# 数组总结篇 - -# 数组理论基础 +## 数组理论基础 数组是非常基础的数据结构,在面试中,考察数组的题目一般在思维上都不难,主要是考察对代码的掌控能力 @@ -51,7 +51,7 @@ 所以**Java的二维数组在内存中不是 `3*4` 的连续地址空间,而是四条连续的地址空间组成!** -# 数组的经典题目 +## 数组的经典题目 在面试中,数组是必考的基础数据结构。 @@ -59,7 +59,7 @@ 我们之前一共讲解了四道经典数组题目,每一道题目都代表一个类型,一种思想。 -## 二分法 +### 二分法 [数组:每次遇到二分法,都是一看就会,一写就废](https://programmercarl.com/0704.二分查找.html) @@ -75,7 +75,7 @@ **二分法是算法面试中的常考题,建议通过这道题目,锻炼自己手撕二分的能力**。 -## 双指针法 +### 双指针法 * [数组:就移除个元素很难么?](https://programmercarl.com/0027.移除元素.html) @@ -91,7 +91,7 @@ 双指针法(快慢指针法)在数组和链表的操作中是非常常见的,很多考察数组和链表操作的面试题,都使用双指针法。 -## 滑动窗口 +### 滑动窗口 * [数组:滑动窗口拯救了你](https://programmercarl.com/0209.长度最小的子数组.html) @@ -107,7 +107,7 @@ 如果没有接触过这一类的方法,很难想到类似的解题思路,滑动窗口方法还是很巧妙的。 -## 模拟行为 +### 模拟行为 * [数组:这个循环可以转懵很多人!](https://programmercarl.com/0059.螺旋矩阵II.html) @@ -118,7 +118,7 @@ 相信大家有遇到过这种情况: 感觉题目的边界调节超多,一波接着一波的判断,找边界,拆了东墙补西墙,好不容易运行通过了,代码写的十分冗余,毫无章法,其实**真正解决题目的代码都是简洁的,或者有原则性的**,大家可以在这道题目中体会到这一点。 -# 总结 +## 总结  diff --git a/problems/数组理论基础.md b/problems/数组理论基础.md index 67b7b20d..d104c883 100644 --- a/problems/数组理论基础.md +++ b/problems/数组理论基础.md @@ -6,7 +6,7 @@ -## 数组理论基础 +# 数组理论基础 数组是非常基础的数据结构,在面试中,考察数组的题目一般在思维上都不难,主要是考察对代码的掌控能力