Skip to content

Commit 7b03e7f

Browse files
solves convert binary number in linked list ti integer
1 parent 2bed37d commit 7b03e7f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@
332332
| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [![Java](assets/java.png)](src/FindWinnerOnATicTacToeGame.java) | |
333333
| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [![Java](assets/java.png)](src/SubtractTheProductAndSumOfDigitsOfAnInteger.java) | |
334334
| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | [![Java](assets/java.png)](src/ElementAppearingMoreThan25PercentInSortedArray.java) | |
335-
| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | | |
335+
| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | [![Java](assets/java.png)](src/ConvertBinaryNumberInLinkedListToInteger.java) | |
336336
| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | | |
337337
| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | | |
338338
| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | | |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class ConvertBinaryNumberInLinkedListToInteger {
2+
public int getDecimalValue(ListNode head) {
3+
int value = 0;
4+
while (head != null) {
5+
value <<= 1;
6+
value += head.val;
7+
head = head.next;
8+
}
9+
return value;
10+
}
11+
12+
13+
private static class ListNode {
14+
int val;
15+
ListNode next;
16+
ListNode() {};
17+
ListNode(int val) { this.val = val; }
18+
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
19+
}
20+
}

0 commit comments

Comments
 (0)