Leetcode Note: Go - Convert Binary Number in a Linked List to Integer

Convert Binary Number in a Linked List to Integer - LeetCode
https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/

  • Go 言語で取り組んだメモ

回答

binary operations solution - Convert Binary Number in a Linked List to Integer - LeetCode
https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/solutions/479574/binary-operations-solution/

/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func getDecimalValue(head *ListNode) int {
	var out int	
	for head != nil {
		out <<= 1
		out |= head.Val
		head = head.Next
	}
	return out
}