Padmapada_21BCS9841(J7)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

WINNING CAMP JAVA WORKSHEET-7

NAME- Padmapada Nayak DATE- 03/07/2024


UID-21BCS9841 SEC- 627-A

1.
class Solution {
public int missingNumber(int[] nums) {
int n = nums.length;
int[] v = new int[n+1];
Arrays.fill(v, -1);
for(int i = 0; i < nums.length; i++) {
v[nums[i]] = nums[i];
}
for(int i = 0; i < v.length; i++) {
if(v[i] == -1) return i;
}
return 0;
}
}
2.
class Solution {
public int addDigits(int num) {

while(num/10 != 0) {
int sum = 0;

while(num>0) {
int rem = num % 10;
sum+=rem;
num /= 10;
}

if(sum/10==0) {
return sum;
}
else {
num = sum;
}
}

return num;
}
}

You might also like