https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/ Easy

Решение

/**
 * Example:
 * var li = ListNode(5)
 * var v = li.`val`
 * Definition for singly-linked list.
 * class ListNode(var `val`: Int) {
 *     var next: ListNode? = null
 * }
 */
fun getDecimalValue(head: ListNode?): Int {
    var num = 0
    var current = head
    while (current != null) {
        num = num * 2 + current.`val` // Сдвигаем число влево и добавляем текущий бит
        current = current.next
    }
    return num
}