Skip to content

Commit b97e1dd

Browse files
Added solutions
1 parent 295f4d8 commit b97e1dd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

convert_ll_to_binary_number.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode(int x) : val(x), next(NULL) {}
7+
* };
8+
*/
9+
class Solution {
10+
public:
11+
int getDecimalValue(ListNode* head) {
12+
13+
int res=0;
14+
while(head!=NULL) {
15+
res*=2;
16+
if(head->val==1) res++;
17+
head=head->next;
18+
}
19+
return res;
20+
21+
}
22+
};

0 commit comments

Comments
 (0)