Problem Statement:
2769. Find the Maximum Achievable Number
Given two integers, num and t. A number x is achievable if it can become equal to num after applying the following operation at most t times:Increase or decrease x by 1, and simultaneously increase or decrease num by 1.
Return the maximum possible value of x.
Initial Code:
class Solution {
public List<Integer> findWordsContaining(String[] words, char x) {
List<Integer> findWordsContaining = new ArrayList();
for (int i = 0; i < words.length; i++) {
if (words[i].contains(x)) {
findWordsContaining.add(i);
}
}
return findWordsContaining;
}
}
Issue in the code -
new ArrayList() | - Should declare the type parameter: new ArrayList<>() (or new ArrayList<Integer>() ) |
words[i].contains(x) | - String.contains() expects a CharSequence , but passed char . Need to convert the char to a String : |
No comments:
Post a Comment