Skip to content

Commit 6a817a0

Browse files
adding MissingNumber.dart
1 parent 4f3af52 commit 6a817a0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

MissingNumber.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Leetcode problem link: https://leetcode.com/problems/missing-number/
2+
3+
class Solution {
4+
5+
// initializing an iterator at first to avoid initializing it each time inside the loop as the loop iterates
6+
var i = 0;
7+
8+
// this function will be called with a list to return the missing number
9+
int missingNumber(List nums) {
10+
for (; i <= nums.length; i++) {
11+
// checking if the list doesn't contain i
12+
if (!nums.contains(i)) {
13+
return i;
14+
}
15+
}
16+
17+
return 0;
18+
19+
}
20+
}

0 commit comments

Comments
 (0)