代码重构 【Github Actions】

pull/42/head
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 @@
![leetcode4851](https://cdn.jsdelivr.net/gh/tan45du/test1@master/20210122/leetcode485最长连续1的个数.7avzcthkit80.gif)
![leetcode4851](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
}
```