代码重构 【Github Actions】

This commit is contained in:
github-actions[bot]
2021-07-29 02:33:38 +00:00
parent 5a5325b0c8
commit a8b66cd5ae
38 changed files with 110 additions and 159 deletions
@@ -80,3 +80,4 @@ func dailyTemperatures(temperatures []int) []int {
} }
return arr return arr
} }
```
@@ -116,4 +116,5 @@ func (m *MinStack) GetMin() int {
return m.minStk[len(m.minStk) - 1] return m.minStk[len(m.minStk) - 1]
} }
``` ```
### ###
@@ -261,7 +261,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -304,4 +303,3 @@ func max(a, b int) int {
return b return b
} }
``` ```
@@ -203,7 +203,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -218,4 +217,3 @@ func twoSum(nums []int, target int) []int {
return []int{} return []int{}
} }
``` ```
@@ -243,4 +243,3 @@ func containsNearbyDuplicate(nums []int, k int) bool {
return false return false
} }
``` ```
@@ -183,7 +183,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -203,4 +202,3 @@ func removeElement(nums []int, val int) int {
return i return i
} }
``` ```
@@ -274,7 +274,6 @@ public:
}; };
``` ```
Go Code: Go Code:
```go ```go
@@ -297,4 +296,3 @@ func firstMissingPositive(nums []int) int {
return length + 1 return length + 1
} }
``` ```
@@ -22,7 +22,7 @@
下面我们通过一个视频模拟代码执行步骤大家一下就能搞懂了 下面我们通过一个视频模拟代码执行步骤大家一下就能搞懂了
![leetcode485最长连续1的个数](https://cdn.jsdelivr.net/gh/tan45du/test1@master/20210122/leetcode485最长连续1的个数.7avzcthkit80.gif) ![leetcode485最长连续1的个数](https://cdn.jsdelivr.net/gh/tan45du/test1@master/20210122/leetcode485最长连续1的个数.7avzcthkit80.gif)
下面我们直接看代码吧 下面我们直接看代码吧
@@ -231,4 +231,3 @@ func max(a, b int) int {
return b return b
} }
``` ```
@@ -181,7 +181,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -218,4 +217,3 @@ func spiralOrder(matrix [][]int) []int {
return res return res
} }
``` ```
@@ -236,4 +236,3 @@ func subarraySum(nums []int, k int) int {
return cnt return cnt
} }
``` ```
@@ -361,7 +361,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -405,4 +404,3 @@ func generateMatrix(n int) [][]int {
return res return res
} }
``` ```
@@ -138,4 +138,3 @@ func plusOne(digits []int) []int {
return digits return digits
} }
``` ```
@@ -173,8 +173,6 @@ func sortColors(nums []int) {
} }
``` ```
另外我们看这段代码有什么问题呢那就是我们即使完全符合时仍会交换元素这样会大大降低我们的效率 另外我们看这段代码有什么问题呢那就是我们即使完全符合时仍会交换元素这样会大大降低我们的效率
例如[0,0,0,1,1,1,2,2,2] 例如[0,0,0,1,1,1,2,2,2]
@@ -336,4 +334,3 @@ func sortColors(nums []int) {
} }
} }
``` ```
@@ -120,7 +120,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -150,4 +149,3 @@ func min(a, b int) int {
return b return b
} }
``` ```
@@ -163,7 +163,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -210,4 +209,3 @@ func threeSum(nums []int) [][]int {
return res return res
} }
``` ```
@@ -96,7 +96,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -150,6 +149,3 @@ func fourSum(nums []int, target int) [][]int {
return res return res
} }
``` ```
@@ -228,7 +228,6 @@ class Solution:
return nums[len(nums) - 1] return nums[len(nums) - 1]
``` ```
Go Code: Go Code:
```go ```go
@@ -248,8 +247,6 @@ func singleNumber(nums []int) int {
} }
``` ```
### HashSet ### HashSet
#### 解析 #### 解析
@@ -326,55 +326,55 @@ JS Code:
```javascript ```javascript
var isPalindrome = function (head) { var isPalindrome = function (head) {
if (head === null || head.next === null) { if (head === null || head.next === null) {
return true;
}
//找到中间节点也就是翻转的头节点这个在昨天的题目中讲到
//但是今天和昨天有一些不一样的地方就是如果有两个中间节点返回第一个昨天的题目是第二个
let midnode = searchmidnode(head);
//原地翻转链表需要两个辅助指针这个也是面试题目大家可以做一下
//这里我们用的是midnode.next需要注意因为我们找到的是中点但是我们翻转的是后半部分
let backhalf = reverse(midnode.next);
//遍历两部分链表判断值是否相等
let p1 = head;
let p2 = backhalf;
while (p2 != null) {
if (p1.val != p2.val) {
//若要还原记得这里也要reverse
midnode.next = reverse(backhalf);
return false;
}
p1 = p1.next;
p2 = p2.next;
}
//还原链表并返回结果这一步是需要注意的我们不可以破坏初始结构我们只是判断是否为回文
//当然如果没有这一步也是可以AC但是面试的时候题目要求可能会有这一条
midnode.next = reverse(backhalf);
return true; return true;
}
//找到中间节点也就是翻转的头节点这个在昨天的题目中讲到
//但是今天和昨天有一些不一样的地方就是如果有两个中间节点返回第一个昨天的题目是第二个
let midnode = searchmidnode(head);
//原地翻转链表需要两个辅助指针这个也是面试题目大家可以做一下
//这里我们用的是midnode.next需要注意因为我们找到的是中点但是我们翻转的是后半部分
let backhalf = reverse(midnode.next);
//遍历两部分链表判断值是否相等
let p1 = head;
let p2 = backhalf;
while (p2 != null) {
if (p1.val != p2.val) {
//若要还原记得这里也要reverse
midnode.next = reverse(backhalf);
return false;
}
p1 = p1.next;
p2 = p2.next;
}
//还原链表并返回结果这一步是需要注意的我们不可以破坏初始结构我们只是判断是否为回文
//当然如果没有这一步也是可以AC但是面试的时候题目要求可能会有这一条
midnode.next = reverse(backhalf);
return true;
}; };
//找到中点 //找到中点
var searchmidnode = function (head) { var searchmidnode = function (head) {
let fast = head; let fast = head;
let slow = head; let slow = head;
while (fast.next != null && fast.next.next != null) { while (fast.next != null && fast.next.next != null) {
fast = fast.next.next; fast = fast.next.next;
slow = slow.next; slow = slow.next;
} }
return slow; return slow;
}; };
//翻转链表 //翻转链表
var reverse = function (slow) { var reverse = function (slow) {
let low = null; let low = null;
let temp = null; let temp = null;
while (slow != null) { while (slow != null) {
temp = slow.next; temp = slow.next;
slow.next = low; slow.next = low;
low = slow; low = slow;
slow = temp; slow = temp;
} }
return low; return low;
}; };
``` ```
@@ -530,4 +530,3 @@ func reverse(node *ListNode) *ListNode {
return pre return pre
} }
``` ```
@@ -125,7 +125,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -142,4 +141,3 @@ func hasCycle(head *ListNode) bool {
return false return false
} }
``` ```
@@ -298,7 +298,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -322,4 +321,3 @@ func detectCycle(head *ListNode) *ListNode {
return nil return nil
} }
``` ```
@@ -258,7 +258,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -289,4 +288,3 @@ func insertionSortList(head *ListNode) *ListNode {
return root.Next return root.Next
} }
``` ```
@@ -238,19 +238,19 @@ JS Code:
```javascript ```javascript
var reverseList = function (head) { var reverseList = function (head) {
//结束条件 //结束条件
if (!head || !head.next) { if (!head || !head.next) {
return head; return head;
} }
//保存最后一个节点 //保存最后一个节点
let pro = reverseList(head.next); let pro = reverseList(head.next);
//将节点进行反转我们可以这样理解 4.next.next = 4 //将节点进行反转我们可以这样理解 4.next.next = 4
//4.next = 5 //4.next = 5
// 5.next = 4 则实现了反转 // 5.next = 4 则实现了反转
head.next.next = head; head.next.next = head;
//防止循环 //防止循环
head.next = null; head.next = null;
return pro; return pro;
}; };
``` ```
@@ -98,15 +98,15 @@ var oddEvenList = function (head) {
even = head.next, even = head.next,
evenHead = even; evenHead = even;
while (odd.next && even.next) { while (odd.next && even.next) {
//将偶数位合在一起奇数位合在一起 //将偶数位合在一起奇数位合在一起
odd.next = even.next; odd.next = even.next;
odd = odd.next; odd = odd.next;
even.next = odd.next; even.next = odd.next;
even = even.next; even = even.next;
} }
//链接 //链接
odd.next = evenHead; odd.next = evenHead;
return head; return head;
}; };
``` ```
@@ -195,7 +195,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -222,4 +221,3 @@ func deleteDuplicates(head *ListNode) *ListNode {
return root.Next return root.Next
} }
``` ```
@@ -188,7 +188,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -214,4 +213,3 @@ func partition(head *ListNode, x int) *ListNode {
return headSmall.Next return headSmall.Next
} }
``` ```
@@ -264,7 +264,6 @@ class Solution {
} }
``` ```
GoCode: GoCode:
```go ```go
@@ -307,4 +306,3 @@ func reverse(head *ListNode) *ListNode {
return pre return pre
} }
``` ```
@@ -147,7 +147,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -173,4 +172,3 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
return root.Next return root.Next
} }
``` ```
@@ -164,7 +164,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -182,4 +181,3 @@ func getKthFromEnd(head *ListNode, k int) *ListNode {
return after return after
} }
``` ```
@@ -136,7 +136,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -150,4 +149,3 @@ func middleNode(head *ListNode) *ListNode {
return slow return slow
} }
``` ```
@@ -268,7 +268,6 @@ class Solution {
} }
``` ```
Go Code: Go Code:
```go ```go
@@ -305,4 +304,3 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
return root.Next return root.Next
} }
``` ```