diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 6e04be1..b7a39e1 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -2,5 +2,18 @@ package ru.otus.homework fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") + val numbers = Array(n) { "" } + for (i in 0..() + val indexMap = mutableMapOf>() + + for (i in numbers.indices) { + val complement = target - numbers[i] + + indexMap[complement]?.forEach { j -> + result.add(j) + result.add(i) + } + + indexMap.getOrPut(numbers[i]) { mutableListOf() }.add(i) + } + + // Проверка на наличие пар + require(result.isNotEmpty()) { + "Не найдено пар с суммой $target в массиве ${numbers.contentToString()}" + } + + return result.toIntArray() } \ No newline at end of file