This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.app.shape | |
import kotlin.math.cos | |
import kotlin.math.min | |
import kotlin.math.sin | |
import kotlin.math.sqrt | |
import kotlin.math.tan | |
internal class SmoothCorner( | |
private val cornerRadius: Float, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void withIf() { | |
Map<int, void> items = { | |
1: (), | |
2: (), | |
3: (), | |
4: (), | |
5: (), | |
}; | |
items.forEach( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val Int.isPrime: Boolean | |
get() { | |
if (this <= 1) return false | |
for (i in 2..<this) { | |
if (this % i == 0) return false | |
} | |
return true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
class TextEditor(initialValue: String = "") { | |
private val operationHistory = Stack<String>().apply { push(initialValue) } | |
val value: String | |
get() = operationHistory.peek() | |
fun append(text: String) { | |
operationHistory.push(operationHistory.peek() + text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
const val RESULT_YES = "YES" | |
const val RESULT_NO = "NO" | |
fun isBalanced(s: String): String { | |
val stack = Stack<Char>() | |
s.forEach { char -> | |
when (char) { | |
'[' -> stack.push(']') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
const val QUEUE_ENQUEUE = 1 | |
const val QUEUE_DEQUEUE = 2 | |
const val QUEUE_PRINT_HEAD = 3 | |
fun queueUsingTwoStacks( | |
numberOfQueues: Int, | |
scanner: Scanner = Scanner(System.`in`), | |
) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun IntArray.alternateSort(): IntArray { | |
require(this.isNotEmpty()) { "There must be at least one element" } | |
this.sort() | |
val result = mutableListOf<Int>() | |
var j = this.lastIndex | |
var i = 0 | |
while (i < j) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
repeat(readln().trim().toInt()) { | |
val result = mutableListOf<Int>() | |
repeat(readln().trimEnd().toInt()) { | |
result.add(readln().toInt()) | |
} | |
repeat(readln().trimEnd().toInt()) { | |
result.add(readln().toInt()) | |
} | |
result.sorted().forEach { print("$it ") } |
NewerOlder