leetcode-189周赛-1451-重新排列句子中的单词

题目描述:

 

 

 

 提交:

class Solution:
    def arrangeWords(self, text: str) -> str:
        text = text.lower().split(" ")
        text.sort(key = lambda x:len(x))
        text[0] = text[0][0].upper()+text[0][1:]
        return " ".join(text)

java:

class Solution {
    public String arrangeWords(String text) {
           String[] s = text.toLowerCase().split(" ");


        Arrays.sort(s, (o1, o2) -> {

                return o1.length()-o2.length();
        });
        

        char first=s[0].charAt(0);
        first=(char)(first-32);
        String temp= first +s[0].substring(1);
        s[0]=temp;
        String res="";
        res= String.join(" ", s);

        return res;
       
    
    }
}

 

posted @ 2020-05-19 19:41  oldby  阅读(136)  评论(0编辑  收藏  举报