-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
43 lines (40 loc) · 938 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
namespace ZigzagIterator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
public class ZigzagIterator
{
private List<int> nums;
private int p;
public ZigzagIterator(IList<int> v1, IList<int> v2)
{
nums = new List<int>();
p = 0;
int p1 = 0, p2 = 0;
while (p1 < v1.Count && p2 < v2.Count)
{
nums.Add(v1[p1++]);
nums.Add(v2[p2++]);
}
while (p1 < v1.Count)
nums.Add(v1[p1++]);
while (p2 < v2.Count)
nums.Add(v2[p2++]);
}
public bool HasNext()
{
return p < nums.Count;
}
public int Next()
{
return nums[p++];
}
}
}