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
class Solution { | |
val leaves = mutableListOf<Pair<TreeNode, Int>>() | |
var depth = 1 | |
fun deepestLeavesSum(root: TreeNode?): Int { | |
if (root == null) return 0 | |
calcdepth(root) | |
val maxdepth = leaves.map { it.second }.maxBy { it } | |
return leaves.filter { it.second == maxdepth }.sumBy { it.first.`val` } | |
} |
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
// !!! | |
// If you need to handle clicking on the entire element only, you can omit adding View to listener lambda - listener(myModel) | |
// so in "bind" method you can write only - view.setOnclickListener { listener.invoke(myViewModel) } | |
class MyAdapter (private val listener: (MyModel, View) -> Unit): RecyclerView.Adapter<MyAdapter.MyViewHolder>{ | |
val myItemList = listOf<MyModel>() | |
//... | |
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { | |
holder.bind(myItemList[position], listener) //bind listener to position | |
} |