Skip to content

Update dependencies #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions test/zigzag_iterator/ZigzagIteratorTest.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.github.masx200.leetcode_test.zigzag_iterator


import org.junit.jupiter.api.Test
import kotlin.test.assertContentEquals

class ZigzagIteratorTest {


@Test
fun nextTest() {

val v1 = listOf<Int>(1, 2)
val v2 = listOf<Int>(3, 4, 5, 6)
val OUTPUT = listOf<Int>(1, 3, 2, 4, 5, 6)


val zzit = ZigzagIterator(v1, v2)

val res: MutableList<Int> = mutableListOf<Int>()
Expand All @@ -31,7 +27,6 @@ class ZigzagIteratorTest {
val v2 = listOf<Int>()
val OUTPUT = listOf<Int>(1)


val zzit = ZigzagIterator(v1, v2)

val res: MutableList<Int> = mutableListOf<Int>()
Expand All @@ -48,7 +43,6 @@ class ZigzagIteratorTest {
val v2 = listOf<Int>(1)
val OUTPUT = listOf<Int>(1)


val zzit = ZigzagIterator(v1, v2)

val res: MutableList<Int> = mutableListOf<Int>()
Expand All @@ -58,4 +52,4 @@ class ZigzagIteratorTest {
}
assertContentEquals(res, OUTPUT)
}
}
}
9 changes: 1 addition & 8 deletions zigzag-iterator/ZigzagIterator.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.github.masx200.leetcode_test.zigzag_iterator




class ZigzagIterator(v1: List<Int>, v2: List<Int>) {


private val generator = ZigzagGenerator(v1, v2)


private val iterator = generator.iterator()
fun next(): Int {
return iterator.next()
Expand All @@ -28,10 +23,8 @@ private fun ZigzagGenerator(v1: List<Int>, v2: List<Int>): Sequence<Int> = seque
}
for (i in v1.size until v2.size) {
yield(v2[i])

}
} else {
yieldAll(ZigzagGenerator(v2, v1))
}

}
}