Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83326b5

Browse files
authored
fix: add solution and testcase (fishercoder1534#156)
1 parent21ec308 commit83326b5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

‎src/main/java/com/fishercoder/solutions/_1290.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,15 @@ public int getDecimalValue(ListNode head) {
1313
returnInteger.parseInt(sb.toString(),2);
1414
}
1515
}
16+
publicstaticclassSolution2 {
17+
publicintgetDecimalValue(ListNodehead) {
18+
intsum =0;
19+
while (head !=null) {
20+
sum *=2;
21+
sum +=head.val;
22+
head =head.next;
23+
}
24+
returnsum;
25+
}
26+
}
1627
}

‎src/test/java/com/fishercoder/_1290Test.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@
1212

1313
publicclass_1290Test {
1414
privatestatic_1290.Solution1solution1;
15+
privatestatic_1290.Solution2solution2;
1516
privatestaticListNodehead;
1617

1718
@BeforeClass
1819
publicstaticvoidsetup() {
1920
solution1 =new_1290.Solution1();
21+
solution2 =new_1290.Solution2();
2022
}
2123

2224
@Test
2325
publicvoidtest1() {
2426
head =LinkedListUtils.createSinglyLinkedList(Arrays.asList(1,0,1));
2527
assertEquals(5,solution1.getDecimalValue(head));
2628
}
27-
29+
@Test
30+
publicvoidtest2() {
31+
head =ListNode.createSinglyLinkedList(Arrays.asList(1,1,1));
32+
assertEquals(7,solution2.getDecimalValue(head));
33+
}
2834
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp