100165 Find Beautiful Indices in the Given Array I || leetcode || contest379 || solved || java

preview_player
Показать описание
solution for the second problem will be posted soon, please subscribe for the updates.........

here's the java code for the Leetcode weekly contest 380 100165 Find Beautiful Indices in the Given Array I || leetcode || contest379 || solved || java

subscribe for more....

// please like and subscribe our channel and comment if you like our solutionss!!!!!!!!!!!

#solutions #code #codes
Рекомендации по теме
Комментарии
Автор

class Solution {
public List<Integer> beautifulIndices(String s, String a, String b, int k) {
// please subscribe our channel and like and comment if you like our
List<Integer> list = new ArrayList<>();
List<Integer> A = new ArrayList<>();
List<Integer> B = new ArrayList<>();
for(int i = 0; i < s.length(); i++){
for(int j = 0; j < a.length(); j++){
if(i + j > s.length() - 1 || a.charAt(j) != s.charAt(i + j)){
break;
}
if(j == a.length() - 1){
A.add(i);
}
}
}
for(int i = 0; i < s.length(); i++){
for(int j = 0; j < b.length(); j++){
if(i + j > s.length() - 1 || b.charAt(j) != s.charAt(i + j)){
break;
}
if(j == b.length() - 1){
B.add(i);
}
}
}

for(int i = 0; i < A.size(); i++){
int x = A.get(i);
if(x <= s.length() - a.length() + 1){
for(int j = 0; j < B.size(); j++){
if(B.get(j) <= s.length() - b.length() + 1 && Math.abs(B.get(j) - A.get(i)) <= k){
list.add(x);
break;
}
}
}
}

return list;
}
}

sidbro
visit shbcf.ru