Reverse a string word by word | Java Placement Course | Lecture 27

preview_player
Показать описание
This course is private from Apni Kaksha channel and many students follow this series to learn java but now these videos is not on YouTube :(
But I already download these videos... and now I upload these videos to just help students like me who learn java from this course and "IF APNI KAKSHA PUBLIC THIS COURSE THAN I DELETE THESE VIDEOS" :)

aman dhattarwal, java course, anuj bhaiya, anuj bhaiya java course, dsa java, c++ aman dhattarwal, anuj sharma java course, java apni kaksha, apna college, aman dhattarwal c++, microsoft didi, java, code with harry

#java #dsa #apnikaksha #anujbhaiya #javaplacementcourse #javadsa #dsaplacementcourse #datastructures #DSA #javaprogramming #apnikaksha
Рекомендации по теме
Комментарии
Автор

you can also use StringBuilder in java insted of concatenating strings for optimized version

CuriousSarah
Автор

ye aman dhatur aur wo uski x ye sab paise ke piche pagal hai... but Anuj Bhaiya.. everything free on yt.. best man

vishaljaiswar
Автор

thanks bhaiya for launching new channel java
bhaiya jo question aapne dsa ke cpp me karaye hai unhe please java me bhi provide kara do....
java ke content bahut kam hain

ashutoshtripathi
Автор

How we write reverse string if we get first word by reverse for example the sky is blue
The out put is
The first print the reverse the sky and is and last blue
eht yks SI eulb

inayatullahkhan
Автор

Thanks for the amazing explanation bhaiya

beinghappy
Автор

bro please upload all those videos which are on that playlist i was following that playlist but suddenly they removed

nakulyadav
Автор

Can't we just trim the input string and then start ?

tanishktripathi
Автор

Ye hi sabhi questions line by line by explain good

deepakkumar
Автор

What's the difference between concat and append?

JohnWick-khow
Автор

Solution using stack data structure:-
class Solution {
public:
string reverseWords(string s) {
int n=s.size();
stack<char> st;
string res="";
bool prevSpace=false;
int sp=-1;
int ep=-1;
for(int i=0;i<n;i++)
{
if(s[i]!=' ')
{
if(sp==-1)
sp=i;
ep=i;
}
}
for(int i=ep;i>=sp;i--)
{
if(s[i]==' ')
{
while(!st.empty())
{
res+=st.top();
st.pop();
}
if(!prevSpace)
res+=' ';
prevSpace=true;
}
else
{
prevSpace=false;
st.push(s[i]);
}
}
while(!st.empty())
{
res+=st.top();
st.pop();
}
return res;
}
};

supratimbhattacharjee
Автор

Class Solution{
public string reverseWords(String s){
String words[ ] = s.trim().split(" +");


return String.join(" ", words);

reddevilbeast
Автор

public String reverseWords(String s) {
Scanner scanner = new Scanner(s);
String ans = "";

while( scanner.hasNext()) {
ans = scanner.next() + " " + ans;
}

scanner.close();

return ans.substring(0, ans.length() - 1);
}

rryann
Автор

aman dhatur bujness man hai .. usko samjh gaya shraddha bhi gayi toh apna yt chalu karke paise chap legi.. aur apni kaccha ki kaccha fatt jayegi.. toh us se shadi kar liya

vishaljaiswar