buddy strings | buddy strings leetcode | leetcode 859 | string

preview_player
Показать описание


#String #Buddy #Linear #Buddy_Strings #Interview #Practice #October #Leetcode #Easy #859 #Algorithm #DataStructure #Java #Preparation #NG #nickode #CookCodeTravel #CCT
Рекомендации по теме
Комментарии
Автор

I solved this but it's only beating 31% so I'm here again

monkeytrollhunter
Автор

bool solve(int i, int j, string &s, string goal){ //i=0 j=s.length()-1
if(i==j) return false;



char temp;
temp=s[i]; //change it
s[i]=s[j];
s[j]=temp;

if(s==goal){ fount=true; return true; }

temp=s[i];
s[i]=s[j]; //undo it
s[j]=temp;

solve(i+1, j, s, goal); //don't move j it might swap and return true with new i
solve(i, j-1, s, goal); // ""



return false;



}
can anybody please tell me that why my solution is returning false resuts in some cases.

fffooccc
Автор

Sir, for example if we consider A="abcd" and B="badc", then our list size will be 4, so then how ill return list.size()==2 will work? Can you briefly explain sir?

mithildevisetty