Two string Java solution(226ms)


  • 4
    O
    public class Solution {
        public int lengthOfLastWord(String s) {
            String[] str = s.trim().split(" +"); 
            return str[str.length - 1].length();
        }
    }

Log in to reply
 

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