+ 5
How to find the missing element (number) in an Array?
11 Antworten
+ 4
i searched the answer on different references an i got, YOU CAN FIND THE MISSING ELEMENT OF AN ARRAY BY IND THE SUM OF ALL ELEMENTS THEN FIND THE DIFFERENT OF THE SUM YOU GOT WITH AN EXPECTED OUTPUT,
+ 3
no .. just any number which may be the among of. elements of ana array @liam keegan
+ 3
but the number is unknown... how can you assume that it is 0 or any other number???
+ 3
no assumption should be taken into consideration
+ 3
your welcome Justin
+ 1
your right Bukuru. I wrote a 4 loop to check it and it works. now I know how to tell what is missing. thanks
numbers=[1,2,4,5,6,7,8,9]
goal=45
total=0
for i in numbers:
total=total+i
print(goal-total)
Python, but proof of concept anyway. (that's what I use python for)
0
Do you mean a value of zero?
0
a for loop?
0
if you're looking for example for 0, loop through the array using enhanced for loop.
This code will return the index of the element that is 0 on the array.
for(int currentNumber : myIntArray){
if(currentNumber == 0){
return currentNumber;
}
}
0
so I assume you would know which numbers are suppose to be present in the array?
0
If it's an int array, it only contains numbers. What do you call "missing number"?
If you mean null, just change the code I give you and check if it's null instead of zero.