Skip to content

Commit 8ebebb0

Browse files
authored
Update README_EN.md
1 parent 429b733 commit 8ebebb0

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

solution/0200-0299/0281.Zigzag Iterator/README_EN.md

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,54 @@ public class ZigzagIterator {
163163
*/
164164
```
165165

166+
#### Go
167+
168+
```go
169+
type ZigzagIterator struct {
170+
cur int
171+
size int
172+
indexes []int
173+
vectors [][]int
174+
}
175+
176+
func Constructor(v1, v2 []int) *ZigzagIterator {
177+
return &ZigzagIterator{
178+
cur: 0,
179+
size: 2,
180+
indexes: []int{0, 0},
181+
vectors: [][]int{v1, v2},
182+
}
183+
}
184+
185+
func (this *ZigzagIterator) next() int {
186+
vector := this.vectors[this.cur]
187+
index := this.indexes[this.cur]
188+
res := vector[index]
189+
this.indexes[this.cur]++
190+
this.cur = (this.cur + 1) % this.size
191+
return res
192+
}
193+
194+
func (this *ZigzagIterator) hasNext() bool {
195+
start := this.cur
196+
for this.indexes[this.cur] == len(this.vectors[this.cur]) {
197+
this.cur = (this.cur + 1) % this.size
198+
if start == this.cur {
199+
return false
200+
}
201+
}
202+
return true
203+
}
204+
205+
/**
206+
* Your ZigzagIterator object will be instantiated and called as such:
207+
* obj := Constructor(param_1, param_2);
208+
* for obj.hasNext() {
209+
* ans = append(ans, obj.next())
210+
* }
211+
*/
212+
```
213+
166214
#### Rust
167215

168216
```rust
@@ -221,46 +269,6 @@ impl ZigzagIterator {
221269
}
222270
```
223271

224-
#### Go
225-
226-
```go
227-
type ZigzagIterator struct {
228-
cur int
229-
size int
230-
indexes []int
231-
vectors [][]int
232-
}
233-
234-
func Constructor(v1 []int, v2 []int) *ZigzagIterator {
235-
return &ZigzagIterator{
236-
cur: 0,
237-
size: 2,
238-
indexes: []int{0, 0},
239-
vectors: [][]int{v1, v2},
240-
}
241-
}
242-
243-
func (this *ZigzagIterator) Next() int {
244-
vector := this.vectors[this.cur]
245-
index := this.indexes[this.cur]
246-
res := vector[index]
247-
this.indexes[this.cur]++
248-
this.cur = (this.cur + 1) % this.size
249-
return res
250-
}
251-
252-
func (this *ZigzagIterator) HasNext() bool {
253-
start := this.cur
254-
for this.indexes[this.cur] == len(this.vectors[this.cur]) {
255-
this.cur = (this.cur + 1) % this.size
256-
if start == this.cur {
257-
return false
258-
}
259-
}
260-
return true
261-
}
262-
```
263-
264272
<!-- tabs:end -->
265273

266274
<!-- solution:end -->

0 commit comments

Comments
 (0)