Skip to content

Commit a536abf

Browse files
authored
Merge pull request #1949 from s0ooo0k/main
[s0ooo0k] Week 14 Solutions
2 parents bb28c0e + ed9eaee commit a536abf

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

counting-bits/s0ooo0k.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int[] countBits(int n) {
3+
int[] arr = new int[n + 1];
4+
5+
for (int i = 1; i <= n; i++) {
6+
arr[i] = arr[i >> 1] + (i & 1);
7+
}
8+
9+
return arr;
10+
}
11+
}
12+

missing-number/s0ooo0k.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int missingNumber(int[] nums) {
3+
int n = nums.length;
4+
boolean[] dp = new boolean[n+1];
5+
6+
for(int i=0; i<n; i++) {
7+
dp[nums[i]]=true;
8+
}
9+
10+
for(int i=0; i<=n; i++) {
11+
if(dp[i]==false) return i;
12+
}
13+
return 0;
14+
}
15+
}
16+

0 commit comments

Comments
 (0)