public class FindNumber {
static String findNumber(List<Integer> arr, int k) {
String res = "YES";
//Unable to identify problem with this part of the code
for (int i = 0; i < arr.size(); i++) {
if (k == arr.get(i))
res = "YES";
else
res = "NO";
}
return res;
}
}
Above code returns NO as the answer even if the integer is present in the list.
==to compare Integer objects only works if the values are between-128and127, all other values will need to be compared using the.equals()method instead