代码重构 【Github Actions】

This commit is contained in:
github-actions[bot]
2021-07-23 15:44:19 +00:00
parent c79cac3d9c
commit f671c90754
94 changed files with 1609 additions and 2111 deletions

View File

@@ -1,10 +1,10 @@
> 如果阅读时发现错误或者动画不可以显示的问题可以添加我微信好友 **[tan45du_one](https://raw.githubusercontent.com/tan45du/tan45du.github.io/master/个人微信.15egrcgqd94w.jpg)** ,备注 github + 题目 + 问题 向我反馈
> 如果阅读时发现错误或者动画不可以显示的问题可以添加我微信好友 **[tan45du_one](https://raw.githubusercontent.com/tan45du/tan45du.github.io/master/个人微信.15egrcgqd94w.jpg)** ,备注 github + 题目 + 问题 向我反馈
>
> 感谢支持该仓库会一直维护希望对各位有一丢丢帮助
>
> 另外希望手机阅读的同学可以来我的 <u>[**公众号袁厨的算法小屋**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u> 两个平台同步,想要和题友一起刷题,互相监督的同学,可以在我的小屋点击<u>[**刷题小队**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u>进入。
> 另外希望手机阅读的同学可以来我的 <u>[**公众号袁厨的算法小屋**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u> 两个平台同步,想要和题友一起刷题,互相监督的同学,可以在我的小屋点击<u>[**刷题小队**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u>进入。
### [75 颜色分类](https://leetcode-cn.com/problems/sort-colors/)
### [75 颜色分类](https://leetcode-cn.com/problems/sort-colors/)
题目描述
@@ -34,7 +34,7 @@
**做题思路**
这个题目我们使用 Arrays.sort() 解决哈哈但是那样太无聊啦题目含义就是让我们将所有的 0 放在前面2放在后面1 放在中间是不是和我们上面说的荷兰国旗问题一样我们仅仅将 1 做为 pivot
这个题目我们使用 Arrays.sort() 解决哈哈但是那样太无聊啦题目含义就是让我们将所有的 0 放在前面2 放在后面1 放在中间是不是和我们上面说的荷兰国旗问题一样我们仅仅将 1 做为 pivot
下面我们直接看代码吧和三向切分基本一致
@@ -48,7 +48,7 @@ class Solution {
//这里和三向切分不完全一致
int i = left;
int right = len-1;
while (i <= right) {
if (nums[i] == 2) {
swap(nums,i,right--);
@@ -57,7 +57,7 @@ class Solution {
} else {
i++;
}
}
}
}
public void swap (int[] nums, int i, int j) {
int temp = nums[i];
@@ -72,7 +72,7 @@ Python3 Code:
```python
from typing import List
class Solution:
def sortColors(self, nums: List[int]):
def sortColors(self, nums: List[int]):
leng = len(nums)
left = 0
# 这里和三向切分不完全一致
@@ -89,7 +89,7 @@ class Solution:
else:
i += 1
return nums
def swap(self, nums: List[int], i: int, j: int):
temp = nums[i]
nums[i] = nums[j]
@@ -112,7 +112,7 @@ public:
} else {
i++;
}
}
}
}
};
```
@@ -153,7 +153,7 @@ class Solution {
例如[0,0,0,1,1,1,2,2,2]
此时我们完全符合情况不需要交换元素但是按照我们上面的代码0,2 的每个元素会和自己进行交换所以这里我们可以根据 i left 的值是否相等来决定是否需要交换大家可以自己写一下
此时我们完全符合情况不需要交换元素但是按照我们上面的代码0,2 的每个元素会和自己进行交换所以这里我们可以根据 i left 的值是否相等来决定是否需要交换大家可以自己写一下
下面我们看一下另外一种写法
@@ -177,7 +177,7 @@ class Solution {
int len = nums.length;
int right = len - 1;
for (int i = 0; i <= right; ++i) {
if (nums[i] == 0) {
if (nums[i] == 0) {
swap(nums,i,left);
left++;
}
@@ -190,7 +190,7 @@ class Solution {
}
}
}
}
public void swap (int[] nums,int i, int j) {
int temp = nums[i];
@@ -220,7 +220,7 @@ class Solution:
# 如果不等于 1 则需要继续判断所以不移动 i 指针i--
if nums[i] != 1:
i -= 1
i += 1
i += 1
return nums
def swap(self, nums: List[int], i: int, j: int):
@@ -238,7 +238,7 @@ public:
int left = 0, len = nums.size();
int right = len - 1;
for (int i = 0; i <= right; ++i) {
if (nums[i] == 0) {
if (nums[i] == 0) {
swap(nums[i],nums[left++]);
}
if (nums[i] == 2) {
@@ -265,7 +265,7 @@ class Solution {
//nums.swapAt(i, left) 直接调用系统方法
self.swap(&nums, i, left) // 保持风格统一走自定义交换
left += 1
}
}
if nums[i] == 2 {
//nums.swapAt(i, right) 直接调用系统方法
self.swap(&nums, i, right) // 保持风格统一走自定义交换
@@ -285,4 +285,4 @@ class Solution {
nums[j] = temp
}
}
```
```