⭐️ 题目描述
leetcode链接:二进制链表转整数
ps:
1 0 1
(0 << 1) + 1 = 0 + 1 = 1
(1 << 1) + 0 = 2 + 0 = 2
(2 << 1) + 1 = 4 + 1 = 5
代码:
int getDecimalValue(struct ListNode* head)
{
int ans = 0;
while(head != NULL)
{
ans = (ans << 1) + head->val;
printf("%d " , ans);
head = head->next;
}
return ans;
}