Skip to content

Commit 8486ab8

Browse files
committed
2023-02-09 update: added "83. Remove Duplicates from Sorted List"
1 parent 41e12d6 commit 8486ab8

File tree

3 files changed

+77
-15
lines changed

3 files changed

+77
-15
lines changed

README.md

+16-15
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
1212

1313
### Easy
1414

15-
| Name | Link to LeetCode | Link to solution |
16-
|----------------------------|---------------------------------------------------------------|------------------------------------------------|
17-
| 1. Two Sum | [Link](https://leetcode.com/problems/two-sum/) | [Link](./lib/easy/two_sum.dart) |
18-
| 9. Palindrome Number | [Link](https://leetcode.com/problems/palindrome-number/) | [Link](./lib/easy/palindrome_number.dart) |
19-
| 13. Roman to Integer | [Link](https://leetcode.com/problems/roman-to-integer/) | [Link](./lib/easy/roman_to_integer.dart) |
20-
| 14. Longest Common Prefix | [Link](https://leetcode.com/problems/longest-common-prefix/) | [Link](./lib/easy/longest_common_prefix.dart) |
21-
| 20. Valid Parentheses | [Link](https://leetcode.com/problems/valid-parentheses/) | [Link](./lib/easy/valid_parentheses.dart) |
22-
| 21. Merge Two Sorted Lists | [Link](https://leetcode.com/problems/merge-two-sorted-lists/) | [Link](./lib/easy/merge_two_sorted_lists.dart) |
23-
| 27. Remove Element | [Link](https://leetcode.com/problems/remove-element/) | [Link](./lib/easy/remove_element.dart) |
24-
| 35. Search Insert Position | [Link](https://leetcode.com/problems/search-insert-position/) | [Link](./lib/easy/search_insert_position.dart) |
25-
| 58. Length of Last Word | [Link](https://leetcode.com/problems/length-of-last-word/) | [Link](./lib/easy/length_of_last_word.dart) |
26-
| 66. Plus One | [Link](https://leetcode.com/problems/plus-one/) | [Link](./lib/easy/plus_one.dart) |
27-
| 67. Add Binary | [Link](https://leetcode.com/problems/add-binary/) | [Link](./lib/easy/add_binary.dart) |
28-
| 69. Sqrt(x) | [Link](https://leetcode.com/problems/sqrtx/) | [Link](./lib/easy/sqrt_x.dart) |
29-
| 70. Climbing Stairs | [Link](https://leetcode.com/problems/climbing-stairs/) | [Link](./lib/easy/climbing_stairs.dart) |
15+
| Name | Link to LeetCode | Link to solution |
16+
|----------------------------------------|---------------------------------------------------------------------------|------------------------------------------------------------|
17+
| 1. Two Sum | [Link](https://leetcode.com/problems/two-sum/) | [Link](./lib/easy/two_sum.dart) |
18+
| 9. Palindrome Number | [Link](https://leetcode.com/problems/palindrome-number/) | [Link](./lib/easy/palindrome_number.dart) |
19+
| 13. Roman to Integer | [Link](https://leetcode.com/problems/roman-to-integer/) | [Link](./lib/easy/roman_to_integer.dart) |
20+
| 14. Longest Common Prefix | [Link](https://leetcode.com/problems/longest-common-prefix/) | [Link](./lib/easy/longest_common_prefix.dart) |
21+
| 20. Valid Parentheses | [Link](https://leetcode.com/problems/valid-parentheses/) | [Link](./lib/easy/valid_parentheses.dart) |
22+
| 21. Merge Two Sorted Lists | [Link](https://leetcode.com/problems/merge-two-sorted-lists/) | [Link](./lib/easy/merge_two_sorted_lists.dart) |
23+
| 27. Remove Element | [Link](https://leetcode.com/problems/remove-element/) | [Link](./lib/easy/remove_element.dart) |
24+
| 35. Search Insert Position | [Link](https://leetcode.com/problems/search-insert-position/) | [Link](./lib/easy/search_insert_position.dart) |
25+
| 58. Length of Last Word | [Link](https://leetcode.com/problems/length-of-last-word/) | [Link](./lib/easy/length_of_last_word.dart) |
26+
| 66. Plus One | [Link](https://leetcode.com/problems/plus-one/) | [Link](./lib/easy/plus_one.dart) |
27+
| 67. Add Binary | [Link](https://leetcode.com/problems/add-binary/) | [Link](./lib/easy/add_binary.dart) |
28+
| 69. Sqrt(x) | [Link](https://leetcode.com/problems/sqrtx/) | [Link](./lib/easy/sqrt_x.dart) |
29+
| 70. Climbing Stairs | [Link](https://leetcode.com/problems/climbing-stairs/) | [Link](./lib/easy/climbing_stairs.dart) |
30+
| 83. Remove Duplicates from Sorted List | [Link](https://leetcode.com/problems/remove-duplicates-from-sorted-list/) | [Link](./lib/easy/remove_duplicates_from_sorted_list.dart) |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import '../common/list_node.dart';
2+
3+
// https://leetcode.com/problems/remove-duplicates-from-sorted-list/
4+
class Solution {
5+
ListNode? deleteDuplicates(ListNode? head) {
6+
var p = head;
7+
while (p != null && p.next != null) {
8+
if (p.val == p.next!.val) {
9+
p.next = p.next!.next;
10+
} else {
11+
p = p.next;
12+
}
13+
}
14+
return head;
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'package:leetcode_dart/easy/remove_duplicates_from_sorted_list.dart';
2+
import 'package:test/test.dart';
3+
4+
import '../common/linked_list_helper.dart';
5+
6+
void main() {
7+
group(
8+
'Example tests',
9+
() {
10+
final rdfsl = Solution();
11+
test(
12+
'[1, 2]',
13+
() => expect(
14+
true,
15+
LinkedListHelper.areEqual(
16+
LinkedListHelper.fromList(
17+
[1, 2],
18+
),
19+
rdfsl.deleteDuplicates(
20+
LinkedListHelper.fromList(
21+
[1, 1, 2],
22+
),
23+
),
24+
),
25+
),
26+
);
27+
test(
28+
'[1, 2, 3]',
29+
() => expect(
30+
true,
31+
LinkedListHelper.areEqual(
32+
LinkedListHelper.fromList(
33+
[1, 2, 3],
34+
),
35+
rdfsl.deleteDuplicates(
36+
LinkedListHelper.fromList(
37+
[1, 1, 2, 3, 3],
38+
),
39+
),
40+
),
41+
),
42+
);
43+
},
44+
);
45+
}

0 commit comments

Comments
 (0)