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

Commitbb2c5dc

Browse files
add 1474
1 parentfe4ce33 commitbb2c5dc

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ _If you like this project, please leave me a star._ ★
9494
|1480|[Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1480.java),[C++](../master/cpp/_1480.cpp)||Easy|Array|
9595
|1476|[Subrectangle Queries](https://leetcode.com/problems/subrectangle-queries/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1476.java)||Medium|Array|
9696
|1475|[Final Prices With a Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1475.java)||Easy|Array|
97+
|1474|[Delete N Nodes After M Nodes of a Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1474.java)||Easy|LinkedList|
9798
|1471|[The k Strongest Values in an Array](https://leetcode.com/problems/the-k-strongest-values-in-an-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1471.java)||Medium|Array, Sort|
9899
|1470|[Shuffle the Array](https://leetcode.com/problems/shuffle-the-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1470.java),[C++](../master/cpp/_1470.cpp)||Easy|Array|
99100
|1469|[Find All The Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1469.java)||Easy|Tree, DFS|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importcom.fishercoder.common.classes.ListNode;
4+
5+
publicclass_1474 {
6+
publicstaticclassSolution1 {
7+
publicListNodedeleteNodes(ListNodehead,intm,intn) {
8+
ListNodepre =newListNode(-1);
9+
ListNodetmp =pre;
10+
while (head !=null) {
11+
intmCount =m;
12+
while (head !=null &&mCount-- >0) {
13+
tmp.next =newListNode(head.val);
14+
head =head.next;
15+
tmp =tmp.next;
16+
}
17+
intnCount =n;
18+
while (head !=null &&nCount-- >0) {
19+
head =head.next;
20+
}
21+
}
22+
returnpre.next;
23+
}
24+
}
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.common.classes.ListNode;
4+
importcom.fishercoder.common.utils.LinkedListUtils;
5+
importcom.fishercoder.solutions._1474;
6+
importcom.fishercoder.solutions._206;
7+
importorg.junit.BeforeClass;
8+
importorg.junit.Test;
9+
10+
importstaticjunit.framework.TestCase.assertEquals;
11+
12+
publicclass_1474Test {
13+
privatestatic_1474.Solution1solution1;
14+
privatestaticListNodehead;
15+
16+
@BeforeClass
17+
publicstaticvoidsetup() {
18+
solution1 =new_1474.Solution1();
19+
}
20+
21+
@Test
22+
publicvoidtest1() {
23+
head =LinkedListUtils.contructLinkedList(newint[]{1,2,3,4,5,6,7,8,9,10,11,12,13});
24+
assertEquals(LinkedListUtils.contructLinkedList(newint[]{1,2,6,7,11,12}),solution1.deleteNodes(head,2,3));
25+
}
26+
27+
@Test
28+
publicvoidtest2() {
29+
head =LinkedListUtils.contructLinkedList(newint[]{1,2,3,4,5,6,7,8,9,10,11});
30+
assertEquals(LinkedListUtils.contructLinkedList(newint[]{1,5,9}),solution1.deleteNodes(head,1,3));
31+
}
32+
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp