From a09fc0bda9c975c32ad405cf4b3236586b25a692 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sun, 28 Apr 2024 10:24:35 +0300 Subject: [PATCH 1/2] Improved task 89 --- src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt b/src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt index ea71e9aa8..b61111ddf 100644 --- a/src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt +++ b/src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt @@ -5,18 +5,18 @@ package g0001_0100.s0089_gray_code @Suppress("NAME_SHADOWING") class Solution { - fun grayCode(n: Int): List { + fun grayCode(n: Int): List { var n = n - var n1 = arrayOf(0) + var n1 = arrayOf(0) var shift = 1 while (n > 0) { - val temp = arrayOfNulls(n1.size * 2) + val temp = Array(n1.size * 2) {0} var pos = 0 for (integer in n1) { temp[pos++] = integer } for (i in n1.indices.reversed()) { - temp[pos++] = n1[i]!! or shift + temp[pos++] = n1[i] or shift } n1 = temp shift = shift shl 1 From da594c55cde5b5b403a3adbc15c385cf44731e63 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sun, 28 Apr 2024 10:57:01 +0300 Subject: [PATCH 2/2] Update Solution.kt --- src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt b/src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt index b61111ddf..b038f7810 100644 --- a/src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt +++ b/src/main/kotlin/g0001_0100/s0089_gray_code/Solution.kt @@ -10,7 +10,7 @@ class Solution { var n1 = arrayOf(0) var shift = 1 while (n > 0) { - val temp = Array(n1.size * 2) {0} + val temp = Array(n1.size * 2) { 0 } var pos = 0 for (integer in n1) { temp[pos++] = integer