Skip to content

Commit bb2c5dc

Browse files
add 1474
1 parent fe4ce33 commit bb2c5dc

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+
package com.fishercoder.solutions;
2+
3+
import com.fishercoder.common.classes.ListNode;
4+
5+
public class _1474 {
6+
public static class Solution1 {
7+
public ListNode deleteNodes(ListNode head, int m, int n) {
8+
ListNode pre = new ListNode(-1);
9+
ListNode tmp = pre;
10+
while (head != null) {
11+
int mCount = m;
12+
while (head != null && mCount-- > 0) {
13+
tmp.next = new ListNode(head.val);
14+
head = head.next;
15+
tmp = tmp.next;
16+
}
17+
int nCount = n;
18+
while (head != null && nCount-- > 0) {
19+
head = head.next;
20+
}
21+
}
22+
return pre.next;
23+
}
24+
}
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.classes.ListNode;
4+
import com.fishercoder.common.utils.LinkedListUtils;
5+
import com.fishercoder.solutions._1474;
6+
import com.fishercoder.solutions._206;
7+
import org.junit.BeforeClass;
8+
import org.junit.Test;
9+
10+
import static junit.framework.TestCase.assertEquals;
11+
12+
public class _1474Test {
13+
private static _1474.Solution1 solution1;
14+
private static ListNode head;
15+
16+
@BeforeClass
17+
public static void setup() {
18+
solution1 = new _1474.Solution1();
19+
}
20+
21+
@Test
22+
public void test1() {
23+
head = LinkedListUtils.contructLinkedList(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13});
24+
assertEquals(LinkedListUtils.contructLinkedList(new int[]{1, 2, 6, 7, 11, 12}), solution1.deleteNodes(head, 2, 3));
25+
}
26+
27+
@Test
28+
public void test2() {
29+
head = LinkedListUtils.contructLinkedList(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
30+
assertEquals(LinkedListUtils.contructLinkedList(new int[]{1, 5, 9}), solution1.deleteNodes(head, 1, 3));
31+
}
32+
33+
}

0 commit comments

Comments
 (0)