leetcode-58。最後の単語の長さ

件名:https : //leetcode-cn.com/problems/length-of-last-word/

回答:

 public int lengthOfLastWord(String s){

    s = s.trim();

         int index = s.lastIndexOf( "");

         if(index <0){

             s.length();を返します。

         }そうしないと{

             s.length()-index-1を返します。

         }

    }

おすすめ

転載: blog.csdn.net/wuqiqi1992/article/details/108325556