File tree 9 files changed +120
-0
lines changed
02.01.Remove Duplicate Node
02.02.Kth Node From End of List
9 files changed +120
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,14 @@ class Solution {
60
60
}
61
61
```
62
62
63
+ ### ** Go**
64
+
65
+ ``` go
66
+ func isFlipedString (s1 string , s2 string ) bool {
67
+ return len (s1) == len (s2) && strings.Contains (s1+s1, s2)
68
+ }
69
+ ```
70
+
63
71
### ** ...**
64
72
65
73
```
Original file line number Diff line number Diff line change @@ -56,6 +56,14 @@ class Solution {
56
56
}
57
57
```
58
58
59
+ ### ** Go**
60
+
61
+ ``` go
62
+ func isFlipedString (s1 string , s2 string ) bool {
63
+ return len (s1) == len (s2) && strings.Contains (s1+s1, s2)
64
+ }
65
+ ```
66
+
59
67
### ** ...**
60
68
61
69
```
Original file line number Diff line number Diff line change
1
+ func isFlipedString (s1 string , s2 string ) bool {
2
+ return len (s1 ) == len (s2 ) && strings .Contains (s1 + s1 , s2 )
3
+ }
Original file line number Diff line number Diff line change @@ -164,6 +164,27 @@ public:
164
164
};
165
165
```
166
166
167
+ ### **Go**
168
+
169
+ ```go
170
+ func removeDuplicateNodes(head *ListNode) *ListNode {
171
+ if head == nil {
172
+ return nil
173
+ }
174
+ vis := map[int]bool{head.Val: true}
175
+ p := head
176
+ for p.Next != nil {
177
+ if vis[p.Next.Val] {
178
+ p.Next = p.Next.Next
179
+ } else {
180
+ vis[p.Next.Val] = true
181
+ p = p.Next
182
+ }
183
+ }
184
+ return head
185
+ }
186
+ ```
187
+
167
188
### ** ...**
168
189
169
190
```
Original file line number Diff line number Diff line change @@ -164,6 +164,27 @@ public:
164
164
};
165
165
```
166
166
167
+ ### **Go**
168
+
169
+ ```go
170
+ func removeDuplicateNodes(head *ListNode) *ListNode {
171
+ if head == nil {
172
+ return nil
173
+ }
174
+ vis := map[int]bool{head.Val: true}
175
+ p := head
176
+ for p.Next != nil {
177
+ if vis[p.Next.Val] {
178
+ p.Next = p.Next.Next
179
+ } else {
180
+ vis[p.Next.Val] = true
181
+ p = p.Next
182
+ }
183
+ }
184
+ return head
185
+ }
186
+ ```
187
+
167
188
### ** ...**
168
189
169
190
```
Original file line number Diff line number Diff line change
1
+ func removeDuplicateNodes (head * ListNode ) * ListNode {
2
+ if head == nil {
3
+ return nil
4
+ }
5
+ vis := map [int ]bool {head .Val : true }
6
+ p := head
7
+ for p .Next != nil {
8
+ if vis [p .Next .Val ] {
9
+ p .Next = p .Next .Next
10
+ } else {
11
+ vis [p .Next .Val ] = true
12
+ p = p .Next
13
+ }
14
+ }
15
+ return head
16
+ }
Original file line number Diff line number Diff line change @@ -133,6 +133,22 @@ public:
133
133
};
134
134
```
135
135
136
+ ### **Go**
137
+
138
+ ```go
139
+ func kthToLast(head *ListNode, k int) int {
140
+ slow, fast := head, head
141
+ for i := 0; i < k; i++ {
142
+ fast = fast.Next
143
+ }
144
+ for fast != nil {
145
+ slow = slow.Next
146
+ fast = fast.Next
147
+ }
148
+ return slow.Val
149
+ }
150
+ ```
151
+
136
152
### ** ...**
137
153
138
154
```
Original file line number Diff line number Diff line change @@ -125,6 +125,22 @@ public:
125
125
};
126
126
```
127
127
128
+ ### **Go**
129
+
130
+ ```go
131
+ func kthToLast(head *ListNode, k int) int {
132
+ slow, fast := head, head
133
+ for i := 0; i < k; i++ {
134
+ fast = fast.Next
135
+ }
136
+ for fast != nil {
137
+ slow = slow.Next
138
+ fast = fast.Next
139
+ }
140
+ return slow.Val
141
+ }
142
+ ```
143
+
128
144
### ** ...**
129
145
130
146
```
Original file line number Diff line number Diff line change
1
+ func kthToLast (head * ListNode , k int ) int {
2
+ slow , fast := head , head
3
+ for i := 0 ; i < k ; i ++ {
4
+ fast = fast .Next
5
+ }
6
+ for fast != nil {
7
+ slow = slow .Next
8
+ fast = fast .Next
9
+ }
10
+ return slow .Val
11
+ }
You can’t perform that action at this time.
0 commit comments