Skip to content

Commit fbb0a53

Browse files
authored
Improved task 89
1 parent 7e29011 commit fbb0a53

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ package g0001_0100.s0089_gray_code
55

66
@Suppress("NAME_SHADOWING")
77
class Solution {
8-
fun grayCode(n: Int): List<Int?> {
8+
fun grayCode(n: Int): List<Int> {
99
var n = n
10-
var n1 = arrayOf<Int?>(0)
10+
var n1 = arrayOf(0)
1111
var shift = 1
1212
while (n > 0) {
13-
val temp = arrayOfNulls<Int>(n1.size * 2)
13+
val temp = Array(n1.size * 2) { 0 }
1414
var pos = 0
1515
for (integer in n1) {
1616
temp[pos++] = integer
1717
}
1818
for (i in n1.indices.reversed()) {
19-
temp[pos++] = n1[i]!! or shift
19+
temp[pos++] = n1[i] or shift
2020
}
2121
n1 = temp
2222
shift = shift shl 1

0 commit comments

Comments
 (0)