Skip to content

Commit 4f0c7b2

Browse files
author
Ozge Cimendere
committed
Add Convert Binary Number in a Linked List to Integer
1 parent e9dcc88 commit 4f0c7b2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//Problem:https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/
2+
namespace LeetCode {
3+
public partial class Solution {
4+
public int GetDecimalValue(ListNode head) {
5+
var num = head.val;
6+
while(head.next != null) {
7+
num = (num * 2) + head.next.val;
8+
head = head.next;
9+
}
10+
11+
return num;
12+
}
13+
}
14+
15+
public class ListNode {
16+
public int val;
17+
public ListNode next;
18+
public ListNode(int val=0, ListNode next=null) {
19+
this.val = val;
20+
this.next = next;
21+
}
22+
}
23+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ LeetCode C# solutions
88
|**682**| **[Baseball Game](https://leetcode.com/problems/baseball-game/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/682-BaseballGame.cs)** | **Easy** |
99
|**933**| **[Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/933-NumberofRecentCalls.cs)** | **Easy** |
1010
|**1108**| **[Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1108-DefangingAnIPAddress.cs)** | **Easy** |
11+
|**1290**| **[Convert Binary Number in a Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1290-ConvertBinaryNumberLinkedListInteger.cs)** | **Easy** |
1112
|**1431**| **[Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1431-KidsWithGreatestNumberofCandies.cs)** | **Easy** |
1213
|**1556**| **[Thousand Separator](https://leetcode.com/problems/thousand-separator/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1556-ThousandSeparator.cs)** | **Easy** |
1314
|**1662**| **[Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1662-CheckIfTwoStringArraysareEquivalent.cs)** | **Easy** |

0 commit comments

Comments
 (0)