1 line Java solution with Lambda


  • 0
    M
    class Solution {
        public int lengthOfLastWord(String s) {
            return Arrays.stream(s.split(" ")).reduce((a,b) -> b).orElse("").length();
        }
    }
    

Log in to reply
 

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