function findLongestWord(str) { // 分割字符串 var stringArr = str.split(" "); // 边界值及递归跳出条件 if (stringArr.length === 1) { return stringArr[0].length; } // 比较数组中第一个元素(字符串)与第二个元素(字符串)的长度 if (stringArr[0].length >= stringArr[1].length) {...
functionfindLongestWord(str){var arr = str.split(' '); arr.sort(function(a,b){returnb.length-a.length; });returnarr[0].length; } findLongestWord("The quick brown fox jumped over the lazy dog"); 解法2: 使用for循环遍历数组,更新最大长度字符串 function findLongestWord(str) { var str...
Find the Longest Word in a String 找出最长单词 在句子中找出最长的单词,并返回它的长度。 函数的返回值应该是一个数字。 当你完成不了挑战的时候,记得开大招'Read-Search-Ask'。这是一些对你有帮助的资源:String.split() String.length 示例:findLongestWord("The quick brown fox jumped over the lazy ...
String.length 第一种想法就是,先定一个小变量,来他一个0;然后把每个单词的长度与它比较,把长度大的赋值给该变量,最后返回该变量; function findLongestWord(str) { var array=str.split(' '); //分割句子为单词,保存在数组array里 var result=0; //先定一个小目标 for(var i=1;i<array.length;i++...
return longestWorld.length; } console.log(findLongestWord("The quick brown fox jumped over the lazy dog"));``` 抄袭于https://medium.freecodecamp.com/three-ways-to-find-the-longest-word-in-a-string-in-javascript-a2fb04c9757c#.u8a9v4qc4...
Python Code: deflongest_word(filename):withopen(filename,'r')asinfile:words=infile.read().split()max_len=len(max(words,key=len))return[wordforwordinwordsiflen(word)==max_len]print(longest_word('test.txt')) Copy Sample Output:
the temporary substring is longer than the result word if (temp_str1.length() > result_word.length()) { result_word = temp_str1; // Update the result word } temp_str1.clear(); // Clear the temporary substring } } return result_word; // Return the longest word found in the ...
If you want to find words made from some or all of the letters, but have these words use only these letters in any amounts, then use thefind words made fromsearch. Scrabble® Tips Find the longest word that can be made with the given letters. ...
2831. 找出最长等值子数组 Find the Longest Equal Subarray 力扣 LeetCode 题解 09:26 2225. 找出输掉零场或一场比赛的玩家 Find Players With Zero or One Losses 力扣 LeetCode 题解 04:24 2769. 找出最大的可达成数字 Find the Maximum Achievable Number 力扣 LeetCode 题解 02:03 1542. 找出最长...
1673. 找出最具竞争力的子序列 Find the Most Competitive Subsequence 力扣 LeetCode 题解 05:57 2831. 找出最长等值子数组 Find the Longest Equal Subarray 力扣 LeetCode 题解 09:26 2225. 找出输掉零场或一场比赛的玩家 Find Players With Zero or One Losses 力扣 LeetCode 题解 04:24 2769. 找出...