FCC 学习日志:Find the Longest Word in a String
2018-03-15 11:15
441 查看
题目:
找出最长单词在句子中找出最长的单词,并返回它的长度。函数的返回值应该是一个数字。
源码:function findLongestWord(str) {
// 请把你的代码写在这里
return str.length;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
解决:function findLongestWord(str) {
// 请把你的代码写在这里
var array=str.split(" ");
var a=0;
for(var i=0;i<array.length;i++)
{
if(array[i].length>a){
a=array[i].length;
}
}
return a;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
找出最长单词在句子中找出最长的单词,并返回它的长度。函数的返回值应该是一个数字。
源码:function findLongestWord(str) {
// 请把你的代码写在这里
return str.length;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
解决:function findLongestWord(str) {
// 请把你的代码写在这里
var array=str.split(" ");
var a=0;
for(var i=0;i<array.length;i++)
{
if(array[i].length>a){
a=array[i].length;
}
}
return a;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
相关文章推荐
- freecodecamp学习--Find the Longest Word in a String
- freecodecamp学习--Find the Longest Word in a String
- FCC算法:四、Find the Longest Word in a String -- 找出最长单词
- Find the Longest Word in a String
- Bonfire: Find the Longest Word in a String 找出一句话中最大的单词
- JavaScript实现-找出最长单词-Find the Longest Word in a String
- find the longest numeric string in the given input strings
- 《牛客网leetcode144题》Given a string S, find the longest palindromic substring in S
- 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 prefix string amongst an array of strings.
- Find The First Non Repeated Character In A String : Technical Interview Question
- Find the first unique char in string
- Given a string, find the length of the longest substring without repeating characters
- Leetcode学习(41)—— Find All Anagrams in a String
- 4、Write a function to find the longest common prefix string amongst an array of strings
- You're given a string of lower-case Latin letters. Your task is to find the length of its longest su
- Find the substring of length 3 which is present in the reverse order from the string
- 代码面试题:Find the first element in a given string A that also appears in another given string B
- LeetCode : Given a string, find the length of the longest serial substring without repeating characters.