Given a space that contains only uppercase and lowercase letters  ' '  String , Returns the length of its last word .

If there is no last word , Please return 0 .

explain : A word is made up of letters , But a string that doesn't contain any spaces .

Example :

 Input : "Hello World"
Output : 5
/**
* @param {string} s
* @return {number}
*/
var lengthOfLastWord = function(s) {
var arr = [];
var s = s.trim();// in consideration of "a " This situation
arr = s.split(' ');
return arr[arr.length-1].length
};

leetCode58. More about the length of the last word

  1. leetcode-58. Length of last word

    leetcode-58. Length of last word The question Given a space that contains only uppercase and lowercase letters  ' '  String , Returns the length of its last word . If there is no last word , Please return 0 . explain : A word is made up of letters , but ...

  2. [Swift]LeetCode58. Length of last word | Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  3. lintcode:Length of Last Word Length of last word

    subject : Length of last word Given a string , Contains upper and lower case letters . Space ' ', Please return the length of the last word . If there is no last word , Please return  0 . Examples Given s = "Hello World& ...

  4. HW— The length of the last word in the string , Words are separated by spaces .

    describe Calculate the length of the last word in the string , Words are separated by spaces . Knowledge point character string , loop Run time limit 0M Memory limit 0 Input One line string , The length is less than 128. Output Integers N, Length of last word . The sample input hell ...

  5. OJ topic : The length of the last word in the string

    Title Description Calculate the length of the last word in the string , Words are separated by spaces . Input description : One line string , Non empty , The length is less than 5000. Output description : Integers N, Length of last word . Input example : hello world Output example : 5 ...

  6. Huawei oj The length of the last word of the string

    subject : The length of the last word in the string Heat index :9697 The time limit :1 second Space restriction :32768K Knowledge of the subject : character string Title Description Calculate the length of the last word in the string , Words are separated by spaces . Input description : One line string , Not ...

  7. Huawei machine test 001: The length of the last word in the string ( Huawei OJ001)

    Huawei machine test The length of the last word in the string Calculate the length of the last word in the string , Words are separated by spaces . Submit the URL : http://www.nowcoder.com/practice/8c949ea5f36f422594b ...

  8. The length of the last word is golang Realization

    Given a space that contains only uppercase and lowercase letters ' ' String , Returns the length of its last word . If there is no last word , Please return 0 . explain : A word is made up of letters , But a string that doesn't contain any spaces . Input : "He ...

  9. Leetcode——58. Length of last word

    Given a space that contains only uppercase and lowercase letters ' ' String , Returns the length of its last word . If there is no last word , Please return 0 . explain : A word is made up of letters , But a string that doesn't contain any spaces . Example : Input : &quo ...

Random recommendation

  1. chart.js Add a list of charts to the list :

    chart.js Add a list of charts to the list : var legend = myDoughnut.generateLegend(); $("#chart_legend").html(legen ...

  2. 【 essays 】Linux Server backup related

    The security of server data has always been the top priority of daily server management .Linux Although server virtualization is known for its highly reliable operating system , But system failures can still happen . Maybe because of hardware failure , Power interruption , Or other unforeseen problems . More often, this Some questions ...

  3. C++ Four books and five classics of programming [ from 2004 Programmer magazine ]-- The next part

    C++ Four books and five classics of programming ( The next part ) author : glory In the first part of my article “ Inventory ” 了 TCPL and D&E And the introductory course . Efficient and robust programming . There are more than ten books on template and generic programming C++ Good book . Winter spring , Let's move on C++ A wonderful book tour . ...

  4. JS Math Count

    Math.ceil()ceil()  Method to round up a number . ceil English translation   The ceiling The parameter must be a numeric value . The return value is greater than or equal to  x, And the nearest integer to it . Math.floor()floor()  The method can be used for one ...

  5. Mathematics in machine learning (3)- The model combination (Model Combining) And Boosting And Gradient Boosting

    Copyright notice : This paper is written by LeftNotEasy Published on http://leftnoteasy.cnblogs.com, This article can be reprinted in full or used in part , But please note the source , If there are questions , Please contact the wheeleast@gm ...

  6. Repository Mode introduction summary

    1.Linq To Sql in Repository Pattern application scenario http://www.cnblogs.com/zhijianliutang/archive/2012/02/24/2367305.html ...

  7. Autoconf/Automake Tool introduction

    stay linux When programming , Sometimes engineering projects are big , There are more documents , At this point, you need to use auto create Makefile File function . That is to use Autoconf/Automake Automatic tool generation Makefile, It brings convenience to compiler , ...

  8. MySQL Misoperation leads to mysql The database can't be viewed

    Use   show databases; +--------------------+| Database           |+--------------------+| information_ ...

  9. iOS Animation cases (1)

    Entrusted by others , Make a similar qq An animation in the account information , I think it's interesting , It doesn't feel that hard , I started , As a result, I found that all my mathematical knowledge was returned to the PE teacher , I've studied it for most of the day . Let's look at the animation first : Knowledge used ...

  10. mysql Index principle

    1.B+Tree The data result of the index is B+Tree, It is better than BTree When inquiring , With less IO The number of times is dominant . 2. Clustered index and nonclustered index Clustered index : The logical order of the indexes is the same as the physical order of the data on the disk .( There is at most one in the table ) such as ...