Length of Last Word 最後個字元長度
Given a string s consists of upper/lower-case alphabets and empty space characters '
'
, return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.
For example,
Given s = "Hello World"
return
5
.
int lengthOfLastWord(char *s) {
int len,k,i;
len=strlen(s);
k=0;
i=len-1;
while(s[i]==' ') i--;
for(;i>=0;i--)
{
if(s[i]!=' ')
{
k++;
}
else
{
break;
}
}
return k;
}
相關推薦
Length of Last Word 最後個字元長度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word d
leetcode 58 Length of Last Word(最後一個單詞長度)
題目要求: 給一個包含大寫或者小寫以及空格的字串,返回這個串最後一個單詞的長度。如果最後一個的單詞不存在,那麼返回0。 注意:一個單詞意味著,連續字母之間沒有空格。 示例: Example 1 Input : "Hello World" Output : 5
[Leetcode] Length of last word 最後一個單詞的長度
== length spa ast class define 跳過 要求 怎麽辦 Given a string s consists of upper/lower-case alphabets and empty space characters‘ ‘, return th
length-of-last-word 最後一個單詞的長度
pac char space rac class strong 順序 character string Given a string s consists of upper/lower-case alphabets and empty space characters‘ ‘
leetcode-58 length-of-last-word(最後一個單詞的長度)
這道題讓我和難受,我的程式碼醜陋不說,還沒有通過。先看一下題目描述: 從題目描述看確實很簡單,先看一下我的程式碼: 1 public static int lengthOfLastWord(String s) { 2 if (s.length() == 0) { 3
Leetcode演算法——58、最後單詞的長度(length of last word)
給定一個字串,包含大小寫字母和空格。返回字串中最後一個單詞的長度。 如果最後一個單詞不存在,返回0。 備註: 一個單詞定義為不包含空格的字元序列。 示例: Input: "Hello World" Output: 5 思路 從後向前,尋找到第一個出現的非空格。
LeetCode 58. 最後一個單詞的長度 Length of Last Word(C語言)
題目描述: 給定一個僅包含大小寫字母和空格 ’ ’ 的字串,返回其最後一個單詞的長度。 如果不存在最後一個單詞,請返回 0 。 說明:一個單詞是指由字母組成,但不包含任何空格的字串。 示例: 輸入: “Hello World” 輸出: 5 題目解答: 方
Length of Last Word(返回最後一個字母的長度)
題目描述: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', ret
LeetCode 最後一個單詞的長度(Length of Last Word)
題目 給定一個僅包含大小寫字母和空格 ’ ’ 的字串,返回其最後一個單詞的長度。 如果不存在最後一個單詞,請返回 0 。 說明:一個單詞是指由字母組成,但不包含任何空格的字串。 描述 示例:
LeetCode:Length of Last Word(最後一個單詞的長度)
題目 Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the s
LeetCode 58 Length of Last Word(最後單詞的長度)
翻譯 給定一個包含大小寫字母和空格字元的字串, 返回該字串中最後一個單詞的長度。 如果最後一個單詞不存在,返回0。 批註: 一個單詞被定義為包含非空字元的字元序列。 例如, 給定 S = "H
leetcode 58. Length of Last Word(C語言,計算最後一個單詞的長度)19
貼原題: Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, r
LeetCode 58. Length of Last Word(最後一個單詞的長度)
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t
Leetcode 58 Length of Last Word 句子中最後一個詞的長度
題目描述:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
[LeetCode] Length of Last Word 求末尾單詞的長度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word d
LeetCode Length of Last Word
archive n-1 art fine ive lan ets hello style 1. 題目Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘
LeetCode --- 58. Length of Last Word
res ase span mon n) 時間復雜度 ace dsm courier Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘, r
58. Length of Last Word
|| int char last span ret pre rim length 求最後一個單詞的長度 Java 1: 1 class Solution { 2 public int lengthOfLastWord(String s) { 3
LeetCode 58. Length of Last Word
per 這樣的 int last -c efi empty ets != Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘, return the l
LeetCode-58. Length of Last Word
hello pos 組成 amp 第一個 == span spa code 一、問題描述 給定一個字符串s,s是由多個單詞組成,單詞之間以‘ ’分開,找出最後一個單詞的長度。如果沒有最後單詞則返回0。 二、問題描述 先找到最後一個單詞的末尾,因為s可能以空格結尾,所