릿코드(LEETCODE)
1290. Convert Binary Number in a Linked List to Integer
cepiloth
2020. 2. 13. 12:43
반응형
https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/
Source
shift operation
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
int getDecimalValue(ListNode* head) {
int num = head->val;
while(head = head->next)
num = (num << 1) + head->val;
return num;
}
};
반응형