We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7e29011 commit fbb0a53Copy full SHA for fbb0a53
src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt
@@ -5,18 +5,18 @@ package g0001_0100.s0089_gray_code
5
6
@Suppress("NAME_SHADOWING")
7
class Solution {
8
- fun grayCode(n: Int): List<Int?> {
+ fun grayCode(n: Int): List<Int> {
9
var n = n
10
- var n1 = arrayOf<Int?>(0)
+ var n1 = arrayOf(0)
11
var shift = 1
12
while (n > 0) {
13
- val temp = arrayOfNulls<Int>(n1.size * 2)
+ val temp = Array(n1.size * 2) { 0 }
14
var pos = 0
15
for (integer in n1) {
16
temp[pos++] = integer
17
}
18
for (i in n1.indices.reversed()) {
19
- temp[pos++] = n1[i]!! or shift
+ temp[pos++] = n1[i] or shift
20
21
n1 = temp
22
shift = shift shl 1
0 commit comments