[코테 풀이] Length of Last Word

시내·2024년 6월 5일

Q_58) Length of Last Word

출처 : https://leetcode.com/problems/length-of-last-word/

Given a string s consisting of words and spaces, return the length of the last word in the string.

A word is a maximal substring consisting of non-space characters only.

class Solution {
    public int lengthOfLastWord(String s) {
         String[] arr = s.split(" ");
        return arr[arr.length - 1].length();
    }
}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글