Find the Longest Word in a String
2017-03-03 12:30
435 查看
Return the length of the longest word in the provided sentence.
Your response should be a number
思路:1.使用split(" ")将字符串转换为字符串;
2.将数组的第一个数赋给b;
3.遍历数组,如果数组中的数的长度大于b,将此数赋给b
for(var i=0;i<array.length;i++){
if(b.length<array[i].length){
b=array[i];
}
4.返回b的长度 b.length;
function findLongestWord(str) {
var array=str.split(" ");
var b=array[0];
for(var i=0;i<array.length;i++){
if(b.length<array[i].length){
b=array[i];
}
}
return b.length;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
相关文章推荐
- FCC算法:四、Find the Longest Word in a String -- 找出最长单词
- JavaScript实现-找出最长单词-Find the Longest Word in a String
- FCC 学习日志:Find the Longest Word in a String
- Bonfire: Find the Longest Word in a String 找出一句话中最大的单词
- freecodecamp学习--Find the Longest Word in a String
- freecodecamp学习--Find the Longest Word in a String
- 《牛客网leetcode144题》Given a string S, find the longest palindromic substring in S
- find the longest numeric string in the given input strings
- Given a string S, find the longest palindromic substring in S.
- Find the longest substring with k unique distinct characters in a given string (Google)
- Write a function to find the longest common common string amongst an array of strings.
- You are to find all the two-word compound words in a dictionary. A two-word compound word is a word
- You're given a string of lower-case Latin letters. Your task is to find the length of its longest su
- choose the longest word in the line .把字符串中最长的单词输出
- Find the first un-repeated character in a string(待整理)
- Write a function to find the longest common prefix string amongst an array of strings.
- Find The First Non Repeated Character In A String : Technical Interview Question
- Given a string, find the length of the longest substring without repeating characters
- 代码面试题:Find the first element in a given string A that also appears in another given string B
- Find the first unique char in string