Skip to content

Commit 1bc4f37

Browse files
committed
[CountingElements] Codility-MissingInteger
1 parent 270a13b commit 1bc4f37

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

โ€ŽREADME.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
| 02 | | [Codility-Lesson2 OddOccurrencesInArray](./src/Array/OddOccurrencesInArray) | |
5353
| 03 | | [Codility-Lesson4 FrogRiverOne](./src/Array/FrogRiverOne) | |
5454
| 04 | | [Codility-Lesson4 PermCheck](./src/Array/PermCheck) | |
55+
| 05 | | [Codility-Lesson4 MissingInteger](./src/Array/MissingInteger) | |
5556

5657
### Stack
5758

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package Array.MissingInteger;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
Solution sol = new Solution();
6+
System.out.println(sol.solution(new int[]{1, 2, 3}));
7+
}
8+
}
9+
10+
class Solution {
11+
12+
static boolean[] check = new boolean[1000001];
13+
14+
public int solution(int[] A) {
15+
for (int value : A) {
16+
if (value > 0) check[value] = true;
17+
}
18+
int ans = 1;
19+
while (check[ans]) ans ++;
20+
return ans;
21+
}
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [Codility - Lesson 4 Counting Elements] MissingInteger
2+
3+
> Detected time complexity : **O(N) or O(N * log(N))**
4+
5+
![image](https://user-images.githubusercontent.com/22045163/104467349-9205bf80-55f9-11eb-9944-5a0ce4077b19.png)

0 commit comments

Comments
ย (0)