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 e40e2dd

Browse files
solved: First Missing Positive
1 parent d2dd8a5 commit e40e2dd

File tree

2 files changed

+100048
-0
lines changed

2 files changed

+100048
-0
lines changed

‎README.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,23 @@ bool _isValid(List<List<String>> board, int row, int col, int k) {
384384
385385
return true;
386386
}
387+
```
388+
389+
### First Missing Positive
390+
391+
```dart
392+
int firstMissingPositive(List<int> nums) {
393+
nums = nums.where((e) => e > 0).toSet().toList();
394+
nums.sort();
395+
396+
if (nums.isEmpty || nums.first != 1) return 1;
397+
398+
for (int index = 1; index < nums.length; index++) {
399+
if (nums[index] - nums[index - 1] != 1) {
400+
return nums[index - 1] + 1;
401+
}
402+
}
403+
404+
return nums.last + 1;
405+
}
387406
```

0 commit comments

Comments
(0)

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