1290. 二进制链表转整数

package mainimport ("fmt""math")type ListNode struct {Val intNext *ListNode}func getDecimalValue(head *ListNode) int {var list []intfor head!=nil{list = append(list,head.Val)head = head.Next}var res intl := len(list)for i:=0;i<l;i++{if list[i]==1{r := int(math.Pow(2,float64(l-i-1)))res +=r}}return res}func main() {head :=&ListNode{Val:1}one :=&ListNode{Val:0}head.Next= onetwo :=&ListNode{Val:1}one.Next = twofmt.Println(getDecimalValue(head))}

