Gopal S Akshintala
04/25/2020, 1:49 PMfun SLLNode?.sumListWith(node: SLLNode?, carry: Int = 0): SLLNode? =
when {
this == null && node == null -> if (carry == 0) null else SLLNode(carry)
this == null -> node.also { it!!.value += carry } // Smart cast doesn't work here.
node == null -> this.also { value += carry } // Works here.
else -> {
...
}
}
vinayagasundar
04/26/2020, 2:42 AMalso
method. Change like this node?.also
Animesh Sahu
04/26/2020, 6:46 AMvinayagasundar
04/26/2020, 6:51 AM&&
operator works. if the first condition fails ie. this == null
. It won't evaluated the seconds condition node==null
. because we already know the final result will be false
anyway.vinayagasundar
04/26/2020, 6:52 AMshort-circuit
evaluationAnimesh Sahu
04/26/2020, 6:54 AMGopal S Akshintala
04/26/2020, 9:30 AM