[抄题]:

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. Alpha阶段敏捷冲刺---Day2

    一.Daily Scrum Meeting照片 PS:不要问我们为什么少了个人,某位不愿说出姓名的大佬强行申请要拍照 二.今天冲刺情况反馈 今天我们依旧在五社区五号楼719进行我们的每日立会.经过昨天 ...

  2. ASP.NET Word转为PDF

    1.首先安装 Microsoft Office 2007加载项:Microsoft Save as PDF-简体中文版:下载地址: http://download.microsoft.com/down ...

  3. 《DSP using MATLAB》Problem 2.16

    先由脉冲响应序列h(n)得到差分方程系数,过程如下: 代码: %% ------------------------------------------------------------------ ...

  4. 【C++11】新特性 之 auto的使用

      C++11中引入的auto主要有两种用途:自己主动类型判断和返回值占位.auto在C++98中的标识暂时变量的语义,因为使用极少且多余.在C++11中已被删除.前后两个标准的auto,全然是两个概 ...

  5. 【转】foxmail邮箱我已进清理了为什么还是说我的邮箱已满

    原文网址:http://zhidao.baidu.com/link?url=YmX_tBenMVsCopjljd80e2Jwvh7H8GnVSrDLeKKBNQkh_Ty50IsX5eAIy4P_64 ...

  6. Nginx获取自定义头部header的值

    http://blog.csdn.net/xbynet/article/details/51899286?_t=t http://shift-alt-ctrl.iteye.com/blog/23314 ...

  7. 关于Eclipse

    Navigator窗口 之前看到同事使用Eclipse的Navigator窗口,十分不解这个窗口有啥用:今天通过了解才知道Package Explorer是从工程的角度来显示文件,比如settings ...

  8. winform 勾选可以改变框控件

    public partial class UCCheck : UserControl { [Browsable(true), Category("修改属性"), Descripti ...

  9. 02 - Unit02:登录功能

    需求实现步骤 发送Ajax请求 服务器处理 Ajax回调处理 登录功能 发送Ajax请求 绑定事件:"登录"按钮的单击事件 获取参数:用户名userName和密码password ...

  10. php 的两个扩展 memcache 和 memcachd

    今天绕了很大弯子, 因为自己写的php的memcache类. 于是出现了下面问题 在本地测试好好的, 线上就出了问题 原因是线上使用的是memcache, 我本地使用的是memcached 区别参考网 ...