[抄题]:

Given many wordswords[i] has weight i.

Design a class WordFilter that supports one function, WordFilter.f(String prefix, String suffix). It will return the word with given prefix and suffix with maximum weight. If no word exists, return -1.

Examples:

Input:
WordFilter(["apple"])
WordFilter.f("a", "e") // returns 0
WordFilter.f("b", "") // returns -1

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[英文数据结构或算法,为什么不用别的数据结构或算法]:

为了获得最大的index,从最后一位开始倒数。特别注意是n - 1 到>=0

[一句话思路]:

不需要用别的数据结构 用自己这个数组来实现就行

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

不需要用别的数据结构 用自己这个数组来实现就行

[复杂度]:Time complexity: O(数组长度n*最长单词数l) Space complexity: O(1)

[算法思想:迭代/递归/分治/贪心]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

class WordFilter {
String[] input;
public WordFilter(String[] words) {
input = words;
}
public int f(String prefix, String suffix) {
for(int i = input.length-1; i >= 0; i--){
if(input[i].startsWith(prefix) && input[i].endsWith(suffix)) return i;
}
return -1;
}
}

[LC给出的题目变变变]:

[代码风格] :

[是否头一次写此类driver funcion的代码] :

745. Prefix and Suffix Search 查找最大index的单词的更多相关文章

  1. 【leetcode】745. Prefix and Suffix Search

    题目如下: Given many words, words[i] has weight i. Design a class WordFilter that supports one function, ...

  2. [LeetCode] Prefix and Suffix Search 前后缀搜索

    Given many words, words[i] has weight i. Design a class WordFilter that supports one function, WordF ...

  3. [Swift]LeetCode745. 前缀和后缀搜索 | Prefix and Suffix Search

    Given many words, words[i] has weight i. Design a class WordFilter that supports one function, WordF ...

  4. Prefix and Suffix Search

    Given many words, words[i] has weight i. Design a class WordFilter that supports one function, WordF ...

  5. <trim>: prefix+prefixOverrides+suffix+suffixOverrides

    <trim prefix="where" prefixOverrides="where" suffixOverrides="and"& ...

  6. JS中search查找某些内容,正则表达式|查找分隔的任何项

    JS中可以用indexOf来查找某个字符串里的某些内容的索引,也就是在字符串的位置.如果存在该字符串,会返回该字符串的索引,如果不存在会返回-1,可以通过某些内容的索引是否为-1判断是否存在该字符串. ...

  7. SpringMVC-组件分析之视图解析器(prefix,suffix)

    SpringMVC的默认组件都是在DispatcherServlet.properties配置文件中配置的: spring-webmvc->org/springframewrok/web/ser ...

  8. Prefix and Suffix

    题目描述 Snuke is interested in strings that satisfy the following conditions: The length of the string ...

  9. mysql 中基础英语单词 (一)关于数据库创建与查找 (包括简写单词)

    create 创建             limit 限制        count  计算     rollup  几上归纳 drop   降下,撤销                       ...

随机推荐

  1. 解决HTML加载时,外部js文件引用较多,影响页面打开速度问题

    解决HTML加载时,外部js文件引用较多,影响页面打开速度问题   通常HTML文件在浏览器中加载时,浏览器都会按照<script>元素在页面中出现的先后顺序,对它们依次加载,一旦加载的j ...

  2. 最新解决 Ubuntu16.04 和 win10 双系统时间同步问题 (设置为 UTC 时间)

    最近在电脑上安装了 Ubuntu16.04 和  Win10 双系统, 开机后发现电脑的开机系统出现了问题,不知道怎么搞的总是会出现8个小时的误差,在网上查了好多文章发现网上的大部分方法都是比较过时的 ...

  3. java第十次面试题

    一.给定一个字符串,把字符串内的字母转换成该字母的下一个字母,a换成b,z换成a,Z换成A,如aBf转换成bCg,字符串内的其他字符不改变,给定函数,编写函数. public static void ...

  4. 使用xUnit为.net core程序进行单元测试(2)

    第一部分: http://www.cnblogs.com/cgzl/p/8283610.html 下面有一点点内容是重叠的.... String Assert 测试string是否相等: [Fact] ...

  5. 说说 PADS Layout 中的第 20 层和 第 25层

    说说 PADS Layout 中的第 20 层和 第 25层 PADA Layout 有一个不成文的说明,第 20 层和第 25 层各有各的用途. 第 20 层是 Placement Outline ...

  6. windows下php7安装redis扩展

    windows下php7安装redis扩展windows下开发用的wamp集成的环境,想装个php-redis扩展.php_redis.dll下载地址:https://pecl.php.net/pac ...

  7. 根据tomcat的日志判断web的发布路径以及服务路径

    [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.unde ...

  8. IE8 focus 失效解决方案

    这几天遇到两个在IE8下focus失效的非常奇怪的问题,当然这个是指JS函数: document.getElementById("id").focus(); 或者 $(" ...

  9. Erlang process structure -- refc binary

    Erlang 的process 是虚拟机层面的进程,每个Erlang process 都包括一个 pcb(process control block), 一个stack 以及私有heap . 这部分的 ...

  10. emacs之配置speedbar

    安装sr-speedbar,这样的话,speedbar就内嵌到emacs里面了 emacsConfig/speedbar-setting.el (require 'sr-speedbar) (setq ...