Sunday, 26 April 2020

Split string by arbitrary number of white spaces | Python | Castor Classes

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

0 Comments:

Post a Comment

Codecademy Code Foundations

Popular Posts

Categories

Android (23) AngularJS (1) Assembly Language (2) Books (10) C (75) C# (12) C++ (81) Course (1) Data Strucures (4) Downloads (1) Engineering (13) flutter (1) FPL (17) Hadoop (1) HTML&CSS (40) IS (25) Java (89) Leet Code (4) Pandas (2) PHP (20) Projects (19) Python (434) R (69) Selenium Webdriver (2) Software (14) SQL (27)