Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,24 @@ fun isCousins(root: TreeNode?, x: Int, y: Int): Boolean {

return false
}

/**
* 2331. Evaluate Boolean Binary Tree
*/

fun evaluateTree(root: TreeNode?): Boolean {
if (root?.left == null && root?.right == null) {
return when (root?.`val`) {
1 -> true
else -> false
}
}

val left = evaluateTree(root?.left)
val right = evaluateTree(root?.right)

return when (root.`val`) {
2 -> left || right
else -> left && right
}
}
15 changes: 15 additions & 0 deletions contest/src/main/java/com/github/contest/math/MathLeetcode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,18 @@ fun lcm(first: Int, second: Int): Int {
val product = (first.toLong() / gcd(first, second)) * second
return abs(product).toInt()
}

/**
* 3516. Find Closest Person
*/

fun findClosest(x: Int, y: Int, z: Int): Int {
val diff1 = abs(x - z)
val diff2 = abs(y - z)

return when {
diff1 < diff2 -> 1
diff1 > diff2 -> 2
else -> 0
}
}