mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
Change path
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"github.com/halfrost/LeetCode-Go/template"
|
||||
"github.com/halfrost/leetcode-go/template"
|
||||
)
|
||||
|
||||
// 解法一 map,时间复杂度 O(n)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
// TreeNode define
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
type question129 struct {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"github.com/halfrost/LeetCode-Go/template"
|
||||
"github.com/halfrost/leetcode-go/template"
|
||||
)
|
||||
|
||||
var dir = [][]int{
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
type question138 struct {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
// ListNode define
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
type question141 struct {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
// ListNode define
|
||||
|
@ -1,7 +1,7 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
// ListNode define
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
type question143 struct {
|
||||
|
@ -31,4 +31,4 @@ Given 1->2->3->4->5, reorder it to 1->5->2->4->3.
|
||||
|
||||
更好的做法是结合之前几道题的操作:链表逆序,找中间结点。
|
||||
|
||||
先找到链表的中间结点,然后利用逆序区间的操作,如 [第 92 题](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0092.Reverse-Linked-List-II) 里的 reverseBetween() 操作,只不过这里的反转区间是从中点一直到末尾。最后利用 2 个指针,一个指向头结点,一个指向中间结点,开始拼接最终的结果。这种做法的时间复杂度是 O(n),空间复杂度是 O(1)。
|
||||
先找到链表的中间结点,然后利用逆序区间的操作,如 [第 92 题](https://github.com/halfrost/leetcode-go/tree/master/leetcode/0092.Reverse-Linked-List-II) 里的 reverseBetween() 操作,只不过这里的反转区间是从中点一直到末尾。最后利用 2 个指针,一个指向头结点,一个指向中间结点,开始拼接最终的结果。这种做法的时间复杂度是 O(n),空间复杂度是 O(1)。
|
@ -1,7 +1,7 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
// TreeNode define
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/halfrost/LeetCode-Go/structures"
|
||||
"github.com/halfrost/leetcode-go/structures"
|
||||
)
|
||||
|
||||
type question144 struct {
|
||||
|
Reference in New Issue
Block a user