Skip to content

Commit

Permalink
Create BIN2DEC_LL.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyanshiguptaaa authored Jan 31, 2021
1 parent 25644c9 commit e4e1210
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Linked_List/BIN2DEC_LL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
int getDecimalValue(ListNode* head)
{
int result = head->val;
while(head->next)
{
result=result*2 + head->next->val;
head=head->next;
}
return result;
}
};

0 comments on commit e4e1210

Please sign in to comment.