mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-23 18:10:20 +08:00
25 lines
379 B
Go
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
|
|
}
|