Code:
class Solution:
def reverseWords(self, s: str) -> str:
s=s+" ";
b="";
l=[];
for i in s:
if(i!=' '):
b=b+i;
elif(b!=''):
l.append(b);
b="";
l.reverse();
return " ".join(l);
Detail explanation of algorithm: Brahmastra of Word extraction from a string https://www.youtube.com/watch?v=3VWI1... Check the problem statement here: https://leetcode.com/problems/reverse... Python for beginners: https://www.youtube.com/watch?v=egq7Z
class Solution:
def reverseWords(self, s: str) -> str:
s=s+" ";
b="";
l=[];
for i in s:
if(i!=' '):
b=b+i;
elif(b!=''):
l.append(b);
b="";
l.reverse();
return " ".join(l);
Detail explanation of algorithm: Brahmastra of Word extraction from a string https://www.youtube.com/watch?v=3VWI1... Check the problem statement here: https://leetcode.com/problems/reverse... Python for beginners: https://www.youtube.com/watch?v=egq7Z
0 Comments:
Post a Comment