Files
LeetCode-Go/leetcode/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer/1290. Convert Binary Number in a Linked List to Integer.go
2020-08-07 17:06:53 +08:00

25 lines
379 B
Go

package leetcode
import (
"github.com/halfrost/LeetCode-Go/structures"
)
// ListNode define
type ListNode = structures.ListNode
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func getDecimalValue(head *ListNode) int {
sum := 0
for head != nil {
sum = sum*2 + head.Val
head = head.Next
}
return sum
}