Python functional style one liner


  • 0
    1
    class Solution(object):
        def reverseWords(self, s):
            """
            :type s: str
            :rtype: str
            """
            return " ".join(map(lambda x : x[::-1], s[::-1].split()))

  • 0
    L

    package excise;

    public class T022 {
    public static void main(String args[]) {
    String test = "the sky is blue";
    System.out.println(reverseWords(test));
    }

    public static String reverseWords(String s) {
    	String x[]=s.split(" ");
    	StringBuffer str = new StringBuffer();
    	for(int i=x.length-1;i>=0;i--){
    		str.append(x[i]).append(" ");
    	}		
    	return str.toString();
    
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.