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

Commit 740d2c6

Browse files
Update README and add test case for firstMissingPositive solution
1 parent 6fabffa commit 740d2c6

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

‎README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@
5656
- Prefix sum &&& Suffix sum
5757
- Prefix product &&& Suffix product
5858
- Hash Table
59-
- Mark Indices
60-
- By negative value
61-
- By the index equals its value
62-
- By zeros if not the list contains zeros
59+
- Mark Indices --> By negative value
6360
-
6461

6562

‎leetcode/41.first_missing_positive.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,35 @@ class Solution {
2828
}
2929
return -1;
3030
}
31+
32+
/// Udemy Solution
33+
// int firstMissingPositive(List<int> nums) {
34+
// int n = nums.length;
35+
36+
// // preprocess the array
37+
// for (int i = 0; i < n; i++) {
38+
// if (nums[i] <= 0) {
39+
// nums[i] = n + 1;
40+
// }
41+
// }
42+
43+
// // marking indices
44+
// for (int i = 0; i < n; i++) {
45+
// int index = nums[i].abs() - 1;
46+
// if (index < n && nums[index] > 0) {
47+
// nums[index] *= -1;
48+
// }
49+
// }
50+
51+
// // scan the array
52+
// for (int i = 0; i < n; i++) {
53+
// if (nums[i] > 0) {
54+
// return i + 1;
55+
// }
56+
// }
57+
58+
// return n + 1;
59+
// }
3160
}
3261

3362
void runTests() {
@@ -39,6 +68,10 @@ void runTests() {
3968
expect(s.firstMissingPositive([1, 2, 0]), equals(3));
4069
});
4170

71+
test('Example: [1, 2, 6, 3, 5, 4] → 3', () {
72+
expect(s.firstMissingPositive([1, 2, 6, 3, 5, 4]), equals(7));
73+
});
74+
4275
test('Example 2: [3,4,-1,1] → 2', () {
4376
expect(s.firstMissingPositive([3, 4, -1, 1]), equals(2));
4477
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /