EngTW / English-for-Programmers

《程式英文》:用英文提昇程式可讀性
977 stars 45 forks source link

1290. Convert Binary Number in a Linked List to Integer #87

Closed twy30 closed 3 years ago

twy30 commented 3 years ago

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

public class Solution
{
    public int GetDecimalValue(ListNode head)
    {
        // 「頭節點」
        var headNode = head;

        // 「輸出值」
        var output = headNode.val;

        // 「節點」
        var node = headNode.next;

        while (node != null)
        {
            output *= 2;
            output += node.val;
            node = node.next;
        }

        return output;
    }
}

請參考「刷 LeetCode 練習命名」 https://github.com/EngTW/English-for-Programmers/issues/69 😊