代码重构 【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

View File

@ -80,3 +80,4 @@ func dailyTemperatures(temperatures []int) []int {
}
return arr
}
```

View File

@ -116,4 +116,5 @@ func (m *MinStack) GetMin() int {
return m.minStk[len(m.minStk) - 1]
}
```
###

View File

@ -261,7 +261,6 @@ class Solution {
}
```
Go Code:
```go
@ -304,4 +303,3 @@ func max(a, b int) int {
return b
}
```

View File

@ -203,7 +203,6 @@ class Solution {
}
```
Go Code:
```go
@ -218,4 +217,3 @@ func twoSum(nums []int, target int) []int {
return []int{}
}
```

View File

@ -243,4 +243,3 @@ func containsNearbyDuplicate(nums []int, k int) bool {
return false
}
```

View File

@ -183,7 +183,6 @@ class Solution {
}
```
Go Code:
```go
@ -203,4 +202,3 @@ func removeElement(nums []int, val int) int {
return i
}
```

View File

@ -274,7 +274,6 @@ public:
};
```
Go Code:
```go
@ -297,4 +296,3 @@ func firstMissingPositive(nums []int) int {
return length + 1
}
```

View File

@ -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
}
```

View File

@ -181,7 +181,6 @@ class Solution {
}
```
Go Code:
```go
@ -218,4 +217,3 @@ func spiralOrder(matrix [][]int) []int {
return res
}
```

View File

@ -236,4 +236,3 @@ func subarraySum(nums []int, k int) int {
return cnt
}
```

View File

@ -361,7 +361,6 @@ class Solution {
}
```
Go Code:
```go
@ -405,4 +404,3 @@ func generateMatrix(n int) [][]int {
return res
}
```

View File

@ -138,4 +138,3 @@ func plusOne(digits []int) []int {
return digits
}
```

View File

@ -173,8 +173,6 @@ func sortColors(nums []int) {
}
```
另外我们看这段代码有什么问题呢那就是我们即使完全符合时仍会交换元素这样会大大降低我们的效率
例如[0,0,0,1,1,1,2,2,2]
@ -336,4 +334,3 @@ func sortColors(nums []int) {
}
}
```

View File

@ -120,7 +120,6 @@ class Solution {
}
```
Go Code:
```go
@ -150,4 +149,3 @@ func min(a, b int) int {
return b
}
```

View File

@ -163,7 +163,6 @@ class Solution {
}
```
Go Code:
```go
@ -210,4 +209,3 @@ func threeSum(nums []int) [][]int {
return res
}
```

View File

@ -96,7 +96,6 @@ class Solution {
}
```
Go Code:
```go
@ -150,6 +149,3 @@ func fourSum(nums []int, target int) [][]int {
return res
}
```

View File

@ -228,7 +228,6 @@ class Solution:
return nums[len(nums) - 1]
```
Go Code:
```go
@ -248,8 +247,6 @@ func singleNumber(nums []int) int {
}
```
### HashSet
#### 解析

View File

@ -326,55 +326,55 @@ JS Code:
```javascript
var isPalindrome = function (head) {
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);
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;
};
//找到中点
var searchmidnode = function (head) {
let fast = head;
let slow = head;
while (fast.next != null && fast.next.next != null) {
fast = fast.next.next;
slow = slow.next;
}
return slow;
let fast = head;
let slow = head;
while (fast.next != null && fast.next.next != null) {
fast = fast.next.next;
slow = slow.next;
}
return slow;
};
//翻转链表
var reverse = function (slow) {
let low = null;
let temp = null;
while (slow != null) {
temp = slow.next;
slow.next = low;
low = slow;
slow = temp;
}
return low;
let temp = null;
while (slow != null) {
temp = slow.next;
slow.next = low;
low = slow;
slow = temp;
}
return low;
};
```
@ -530,4 +530,3 @@ func reverse(node *ListNode) *ListNode {
return pre
}
```

View File

@ -125,7 +125,6 @@ class Solution {
}
```
Go Code:
```go
@ -142,4 +141,3 @@ func hasCycle(head *ListNode) bool {
return false
}
```

View File

@ -298,7 +298,6 @@ class Solution {
}
```
Go Code:
```go
@ -322,4 +321,3 @@ func detectCycle(head *ListNode) *ListNode {
return nil
}
```

View File

@ -258,7 +258,6 @@ class Solution {
}
```
Go Code:
```go
@ -289,4 +288,3 @@ func insertionSortList(head *ListNode) *ListNode {
return root.Next
}
```

View File

@ -238,19 +238,19 @@ JS Code:
```javascript
var reverseList = function (head) {
//结束条件
if (!head || !head.next) {
return head;
}
//保存最后一个节点
let pro = reverseList(head.next);
//将节点进行反转我们可以这样理解 4.next.next = 4
//4.next = 5
// 5.next = 4 则实现了反转
head.next.next = head;
//防止循环
head.next = null;
return pro;
//结束条件
if (!head || !head.next) {
return head;
}
//保存最后一个节点
let pro = reverseList(head.next);
//将节点进行反转我们可以这样理解 4.next.next = 4
//4.next = 5
// 5.next = 4 则实现了反转
head.next.next = head;
//防止循环
head.next = null;
return pro;
};
```

View File

@ -98,15 +98,15 @@ var oddEvenList = function (head) {
even = head.next,
evenHead = even;
while (odd.next && even.next) {
//将偶数位合在一起奇数位合在一起
odd.next = even.next;
odd = odd.next;
even.next = odd.next;
even = even.next;
}
//链接
odd.next = evenHead;
return head;
//将偶数位合在一起奇数位合在一起
odd.next = even.next;
odd = odd.next;
even.next = odd.next;
even = even.next;
}
//链接
odd.next = evenHead;
return head;
};
```

View File

@ -195,7 +195,6 @@ class Solution {
}
```
Go Code:
```go
@ -222,4 +221,3 @@ func deleteDuplicates(head *ListNode) *ListNode {
return root.Next
}
```

View File

@ -188,7 +188,6 @@ class Solution {
}
```
Go Code:
```go
@ -214,4 +213,3 @@ func partition(head *ListNode, x int) *ListNode {
return headSmall.Next
}
```

View File

@ -264,7 +264,6 @@ class Solution {
}
```
GoCode:
```go
@ -307,4 +306,3 @@ func reverse(head *ListNode) *ListNode {
return pre
}
```

View File

@ -147,7 +147,6 @@ class Solution {
}
```
Go Code:
```go
@ -173,4 +172,3 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
return root.Next
}
```

View File

@ -164,7 +164,6 @@ class Solution {
}
```
Go Code:
```go
@ -182,4 +181,3 @@ func getKthFromEnd(head *ListNode, k int) *ListNode {
return after
}
```

View File

@ -136,7 +136,6 @@ class Solution {
}
```
Go Code:
```go
@ -150,4 +149,3 @@ func middleNode(head *ListNode) *ListNode {
return slow
}
```

View File

@ -268,7 +268,6 @@ class Solution {
}
```
Go Code:
```go
@ -305,4 +304,3 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
return root.Next
}
```