-
1290. Convert Binary Number in a Linked List to Integer릿코드(LEETCODE) 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; } };
반응형'릿코드(LEETCODE)' 카테고리의 다른 글
392. Is Subsequence (0) 2020.02.13 342. Power of Four (0) 2020.02.13 389. Find the Difference (0) 2020.02.13 136. Single Number (0) 2020.02.13 268. Missing Number (0) 2020.02.13