This file contains 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 kotlinx.datetime.LocalDate | |
import kotlinx.datetime.toLocalDate | |
// Working with Retrofit + Moshi + KotlinX DateTime and want to use LocalDate | |
// as an object to deserialize/serialize with? Wabam! | |
// If this helped you maybe https://www.buymeacoffee.com/ekeitho <3 | |
object LocaleDateAdapter { | |
@ToJson | |
fun localDateToJson(localDate: LocalDate): String { |
This file contains 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 cracking.ch4 | |
import org.junit.Test | |
import java.util.* | |
class BuildOrder { | |
@Test | |
fun test() { | |
buildOrder(charArrayOf('a', 'b', 'c', 'd', 'e', 'f'), | |
arrayListOf('a' to 'd', 'f' to 'b', 'b' to 'd', 'f' to 'a', 'd' to 'c') |
This file contains 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 cracking.ch4 | |
import org.junit.Test | |
import java.util.* | |
class PrefixMapSum { | |
var trie = Trie(0) | |
@Test |
This file contains 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
@Test | |
fun test() { | |
val n = BinaryNode(4) | |
.apply { | |
addLeft(2).apply { | |
addLeft(1) | |
} | |
addRight(6).apply { | |
addRight(7) | |
} |
This file contains 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 cracking.ch4 | |
import org.junit.Test | |
class MinHeap { | |
val heap = arrayListOf<Int>() | |
@Test | |
fun test() { |
This file contains 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 <T> isComplete(root: BinaryNode<T>?) : Boolean { | |
// if left is null, but right isnt, it isn't complete | |
if (root?.left == null && root?.right != null) return false | |
// if left and right is null, we have found a child | |
if (root?.left == null && root?.right == null) return true | |
return isComplete(root.left) && isComplete(root.right) | |
} | |
fun <T> isFull(root: BinaryNode<T>?) : Boolean { | |
if (root?.left == null && root?.right == null) return true |
This file contains 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 partition(head: Node?, int: Int): Node? { | |
var left = head | |
var curr = head | |
while (curr != null) { | |
if (curr.data < int) { | |
val temp = left!!.data | |
left.data = curr.data |
This file contains 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 isMatch(word: String, pattern: String): Boolean { | |
if (pattern.length == 2 && pattern[0] == '.' && pattern[1] == '*') { | |
// recursively if we ever get to this, we know to return true regardless | |
return true | |
} | |
if (word.isEmpty() && pattern.isEmpty()) { | |
return true | |
} |
This file contains 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 comboOfSizeK(word: String, r: Int): List<String> { | |
val list = arrayListOf<String>() | |
fun comobs(word: String, created: String, start: Int, end: Int, sizeOfCombo: Int) { | |
if (created.length == sizeOfCombo) { | |
list.add(created) | |
return | |
} | |
if (start > end) { |
This file contains 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
data class Roman(val letter: Char, val amount: Int) | |
var map = mapOf('M' to Roman('M', 1000), | |
'D' to Roman('D', 500), | |
'C' to Roman('C', 100), | |
'L' to Roman('L', 50), | |
'X' to Roman('X', 10), | |
'V' to Roman('V', 5), | |
'I' to Roman('I', 1) | |
) |
NewerOlder