题解 | #牛牛的名字游戏#
牛牛的名字游戏
https://www.nowcoder.com/practice/92320333267c482b8de09a9b56ef6d9d
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return int整型
*/
public int lengthOfLastWord (String s) {
String[] s1 = s.split(" ");
return s1[s1.length-1].length();
}
}
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return int整型
*/
export function lengthOfLastWord(s: string): number {
const words = s.trim().split(" ");
return words.length==0? 0:words[words.length-1].length;
}

小天才公司福利 1152人发布