返回提供的句子中最长的单词的长度. 返回值应该是一个数字. 第一步,使用String.prototype.split()方法将字符串转换成数组 function findLongestWord(str) { var arr = str.split(' '); console.log(arr) } findLongestWord("The quick brown fox jumped over the lazy dog"); 从结果中可以看出,返回的数组length为9 第二步,循环数组…
25:最长最短单词 总时间限制: 1000ms 内存限制: 65536kB 描述 输入1行句子(不多于200个单词,每个单词长度不超过100),只包含字母.空格和逗号.单词由至少一个连续的字母构成,空格和逗号都是单词间的间隔. 试输出第1个最长的单词和第1个最短单词. 输入 一行句子. 输出 两行输出:第1行,第一个最长的单词.第2行,第一个最短的单词. 样例输入 I am studying Programming language C in Peking University 样例输出 P…
题目:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 题解:首先需要清楚什么是“回文“(不知道这个翻译对不对?)字符串!回文字符串关于某一个字符对称,在左右两边与中心相同距离的字符相等. 那么还需要…
5.7 Given a list of words, write a program to find the longest word made of other words in the list. 这道题给了我们一个字符串数组,让我们找到最长的那个单词是由字符串数组中的其他单词组成的,LeetCode上跟类似的题目有Word Break和Word Break II.那么我们首先来想如果是拆分两个单词怎么做,那我们要首先把所有的单词存到哈希表里,然后遍历每个单词,每个位置上都拆分成左右两个字符…
Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other words in words. If there is more than one possible answer, return the longest word with the smallest l…